Mercurial > games > semicongine
comparison tests/test_mesh.nim @ 268:d16fd73959c1
update shader to work correctly
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 28 May 2023 18:11:17 +0700 |
parents | ad078e26a1c7 |
children | b5fb27b0f7a4 |
comparison
equal
deleted
inserted
replaced
267:a107d9ef1a1f | 268:d16fd73959c1 |
---|---|
5 var ent2 = newEntity("hehe", ent1) | 5 var ent2 = newEntity("hehe", ent1) |
6 var myScene = newScene("hi", ent2) | 6 var myScene = newScene("hi", ent2) |
7 myScene.root.transform = translate3d(0.2'f32, 0'f32, 0'f32) | 7 myScene.root.transform = translate3d(0.2'f32, 0'f32, 0'f32) |
8 myScene.root.children[0].transform = translate3d(0'f32, 0.2'f32, 0'f32) | 8 myScene.root.children[0].transform = translate3d(0'f32, 0.2'f32, 0'f32) |
9 var scenes = [ | 9 var scenes = [ |
10 loadScene("default_cube.glb", "1"), | 10 # loadScene("default_cube.glb", "1"), |
11 # loadScene("default_cube1.glb", "3"), | 11 # loadScene("default_cube1.glb", "3"), |
12 # loadScene("default_cube2.glb", "4"), | 12 # loadScene("default_cube2.glb", "4"), |
13 # loadScene("flat.glb", "5"), | 13 # loadScene("flat.glb", "5"), |
14 # loadScene("tutorialk-donat.glb", "6"), | 14 loadScene("tutorialk-donat.glb", "6"), |
15 # myScene, | 15 # myScene, |
16 # loadScene("personv3.glb", "2"), | 16 # loadScene("personv3.glb", "2"), |
17 ] | 17 ] |
18 | 18 |
19 var engine = initEngine("Test meshes") | 19 var engine = initEngine("Test meshes") |
22 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 22 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
23 attr[uint8]("material", memoryPerformanceHint=PreferFastRead), | 23 attr[uint8]("material", memoryPerformanceHint=PreferFastRead), |
24 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), | 24 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), |
25 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), | 25 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), |
26 ] | 26 ] |
27 vertexOutput = @[attr[Vec4f]("vertexColor"), #[ attr[Vec2f]("colorTexCoord")]#] | 27 vertexOutput = @[ |
28 attr[Vec4f]("vertexColor"), | |
29 attr[Vec2f]("colorTexCoord"), | |
30 attr[uint8]("materialId", noInterpolation=true) | |
31 ] | |
28 fragOutput = @[attr[Vec4f]("color")] | 32 fragOutput = @[attr[Vec4f]("color")] |
29 uniforms = @[ | 33 uniforms = @[ |
30 attr[Mat4]("projection"), | 34 attr[Mat4]("projection"), |
31 attr[Mat4]("view"), | 35 attr[Mat4]("view"), |
32 attr[Vec4f]("material_color", arrayCount=16), | 36 attr[Vec4f]("baseColorFactor", arrayCount=4), |
33 ] | 37 ] |
34 samplers = @[ | 38 samplers = @[ |
35 # attr[Sampler2DType]("material_color_texture", arrayCount=1), | 39 attr[Sampler2DType]("baseColorTexture", arrayCount=4), |
36 ] | 40 ] |
37 vertexCode = compileGlslShader( | 41 vertexCode = compileGlslShader( |
38 stage=VK_SHADER_STAGE_VERTEX_BIT, | 42 stage=VK_SHADER_STAGE_VERTEX_BIT, |
39 inputs=vertexInput, | 43 inputs=vertexInput, |
40 outputs=vertexOutput, | 44 outputs=vertexOutput, |
41 uniforms=uniforms, | 45 uniforms=uniforms, |
42 samplers=samplers, | 46 samplers=samplers, |
43 main=""" | 47 main=""" |
44 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); | 48 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); |
45 vertexColor = Uniforms.material_color[material]; | 49 vertexColor = Uniforms.baseColorFactor[material]; |
46 // colorTexCoord = texcoord_0; | 50 colorTexCoord = texcoord_0; |
51 materialId = material; | |
47 """ | 52 """ |
48 ) | 53 ) |
49 fragmentCode = compileGlslShader( | 54 fragmentCode = compileGlslShader( |
50 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | 55 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
51 inputs=vertexOutput, | 56 inputs=vertexOutput, |
52 outputs=fragOutput, | 57 outputs=fragOutput, |
53 uniforms=uniforms, | 58 uniforms=uniforms, |
54 samplers=samplers, | 59 samplers=samplers, |
55 # main="""color = texture(material_color_texture[0], colorTexCoord) * vertexColor;""" | 60 main=""" |
56 main="""color = vertexColor;""" | 61 vec4 col[4] = vec4[4](vec4(1, 0, 0, 1), vec4(0, 1, 0, 1), vec4(0, 0, 1, 1), vec4(1, 1, 1, 1)); |
62 color = texture(baseColorTexture[materialId], colorTexCoord) * vertexColor; | |
63 """ | |
57 ) | 64 ) |
58 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) | 65 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) |
59 for scene in scenes.mitems: | 66 for scene in scenes.mitems: |
60 engine.addScene(scene, vertexInput, samplers, transformAttribute="transform") | 67 engine.addScene(scene, vertexInput, samplers, transformAttribute="transform") |
61 scene.addShaderGlobal("projection", Unit4) | 68 scene.addShaderGlobal("projection", Unit4) |