Mercurial > games > semicongine
comparison tests/test_mesh.nim @ 318:e656c0aad093
fix: test not running with temporary new material system
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 12 Aug 2023 23:55:05 +0700 |
parents | b145a05c2459 |
children | 27aaf43e18b4 |
comparison
equal
deleted
inserted
replaced
317:9efc258df208 | 318:e656c0aad093 |
---|---|
1 import std/sequtils | |
2 import std/tables | |
1 import semicongine | 3 import semicongine |
2 | 4 |
3 proc main() = | 5 proc main() = |
4 var ent1 = newEntity("hoho", {"mesh": Component(rect())}) | 6 var ent1 = newEntity("hoho", {"mesh": Component(rect())}) |
5 var ent2 = newEntity("hehe", [], ent1) | 7 var ent2 = newEntity("hehe", [], ent1) |
18 | 20 |
19 var engine = initEngine("Test meshes") | 21 var engine = initEngine("Test meshes") |
20 const | 22 const |
21 vertexInput = @[ | 23 vertexInput = @[ |
22 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 24 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
23 attr[uint8]("material", memoryPerformanceHint=PreferFastRead), | 25 attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead), |
24 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), | 26 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), |
25 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), | 27 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), |
26 ] | 28 ] |
27 intermediate = @[ | 29 intermediate = @[ |
28 attr[Vec4f]("vertexColor"), | 30 attr[Vec4f]("vertexColor"), |
29 attr[Vec2f]("colorTexCoord"), | 31 attr[Vec2f]("colorTexCoord"), |
30 attr[uint8]("materialId", noInterpolation=true) | 32 attr[uint16]("materialIndexOut", noInterpolation=true) |
31 ] | 33 ] |
32 fragOutput = @[attr[Vec4f]("color")] | 34 fragOutput = @[attr[Vec4f]("color")] |
33 uniforms = @[ | 35 uniforms = @[ |
34 attr[Mat4]("projection"), | 36 attr[Mat4]("projection"), |
35 attr[Mat4]("view"), | 37 attr[Mat4]("view"), |
42 outputs=fragOutput, | 44 outputs=fragOutput, |
43 uniforms=uniforms, | 45 uniforms=uniforms, |
44 samplers=samplers, | 46 samplers=samplers, |
45 vertexCode=""" | 47 vertexCode=""" |
46 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); | 48 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); |
47 vertexColor = Uniforms.baseColorFactor[material]; | 49 vertexColor = Uniforms.baseColorFactor[materialIndex]; |
48 colorTexCoord = texcoord_0; | 50 colorTexCoord = texcoord_0; |
49 materialId = material; | 51 materialIndexOut = materialIndex; |
50 """, | 52 """, |
51 fragmentCode=""" | 53 fragmentCode=""" |
52 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)); | 54 // 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)); |
53 color = texture(baseColorTexture[materialId], colorTexCoord) * vertexColor; | 55 color = texture(baseColorTexture[materialIndexOut], colorTexCoord) * vertexColor; |
54 """ | 56 """ |
55 ) | 57 ) |
56 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) | 58 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) |
57 for scene in scenes.mitems: | 59 for scene in scenes.mitems: |
58 engine.addScene(scene, vertexInput, samplers, transformAttribute="transform", materialIndexAttribute="") | 60 engine.addScene(scene, vertexInput, samplers) |
59 scene.addShaderGlobal("projection", Unit4) | 61 scene.addShaderGlobal("projection", Unit4) |
60 scene.addShaderGlobal("view", Unit4) | 62 scene.addShaderGlobal("view", Unit4) |
63 let baseColors = scene.materials.map(proc(i: Material): Vec4f = getValue[Vec4f](i[].constants["baseColorFactor"])) | |
64 scene.addShaderGlobalArray("baseColorFactor", baseColors) | |
61 var | 65 var |
62 size = 1'f32 | 66 size = 1'f32 |
63 elevation = 0'f32 | 67 elevation = 0'f32 |
64 azimut = 0'f32 | 68 azimut = 0'f32 |
65 currentScene = 0 | 69 currentScene = 0 |