diff tests/test_vulkan_wrapper.nim @ 785:1880ab140165

add: first complete working version of multiple materials and shaders per scene, yipie :)
author Sam <sam@basx.dev>
date Sat, 19 Aug 2023 23:30:25 +0700
parents fa39e67dded7
children 0c3f4f6f1aa2
line wrap: on
line diff
--- a/tests/test_vulkan_wrapper.nim	Sat Aug 19 22:24:06 2023 +0700
+++ b/tests/test_vulkan_wrapper.nim	Sat Aug 19 23:30:25 2023 +0700
@@ -41,7 +41,7 @@
     name: "mat3",
     materialType: "my_special_material",
     constants: {
-      "colors": toGPUValue(newVec4f(0.5, 0.5, 0))
+      "color": toGPUValue(newVec4f(0.5, 0.5, 0))
     }.toTable
   )
 
@@ -155,7 +155,7 @@
 
   # INIT RENDERER:
   const
-    shaderConfiguration = createShaderConfiguration(
+    shaderConfiguration1 = createShaderConfiguration(
       inputs=[
         attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
         attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite),
@@ -174,9 +174,20 @@
       vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""",
       fragmentCode="color = texture(my_little_texture[materialIndexOut], outcolor.xy) * 0.5 + outcolor * 0.5;",
     )
+    shaderConfiguration2 = createShaderConfiguration(
+      inputs=[
+        attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
+        attr[Vec3f]("translate", perInstance=true),
+      ],
+      intermediates=[attr[Vec4f]("outcolor")],
+      outputs=[attr[Vec4f]("color")],
+      uniforms=[attr[Vec4f]("color")],
+      vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = Uniforms.color;""",
+      fragmentCode="color = outcolor;",
+    )
   engine.initRenderer({
-    "my_material": shaderConfiguration,
-    "my_special_material": shaderConfiguration,
+    "my_material": shaderConfiguration1,
+    "my_special_material": shaderConfiguration2,
   }.toTable)
 
   # INIT SCENES