changeset 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 9efc258df208
children 83954ffb238b
files tests/test_mesh.nim
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test_mesh.nim	Sat Aug 12 23:54:28 2023 +0700
+++ b/tests/test_mesh.nim	Sat Aug 12 23:55:05 2023 +0700
@@ -1,3 +1,5 @@
+import std/sequtils
+import std/tables
 import semicongine
 
 proc main() =
@@ -20,14 +22,14 @@
   const
     vertexInput = @[
       attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
-      attr[uint8]("material", memoryPerformanceHint=PreferFastRead),
+      attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead),
       attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead),
       attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true),
     ]
     intermediate = @[
       attr[Vec4f]("vertexColor"),
       attr[Vec2f]("colorTexCoord"),
-      attr[uint8]("materialId", noInterpolation=true)
+      attr[uint16]("materialIndexOut", noInterpolation=true)
     ]
     fragOutput = @[attr[Vec4f]("color")]
     uniforms = @[
@@ -44,20 +46,22 @@
       samplers=samplers,
       vertexCode="""
 gl_Position =  vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection);
-vertexColor = Uniforms.baseColorFactor[material];
+vertexColor = Uniforms.baseColorFactor[materialIndex];
 colorTexCoord = texcoord_0;
-materialId = material;
+materialIndexOut = materialIndex;
 """,
       fragmentCode="""
-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));
-color = texture(baseColorTexture[materialId], colorTexCoord) * vertexColor;
+// 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));
+color = texture(baseColorTexture[materialIndexOut], colorTexCoord) * vertexColor;
 """
     )
   engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1)))
   for scene in scenes.mitems:
-    engine.addScene(scene, vertexInput, samplers, transformAttribute="transform", materialIndexAttribute="")
+    engine.addScene(scene, vertexInput, samplers)
     scene.addShaderGlobal("projection", Unit4)
     scene.addShaderGlobal("view", Unit4)
+    let baseColors = scene.materials.map(proc(i: Material): Vec4f = getValue[Vec4f](i[].constants["baseColorFactor"]))
+    scene.addShaderGlobalArray("baseColorFactor", baseColors)
   var
     size = 1'f32
     elevation = 0'f32