diff examples/E03_hello_cube.nim @ 671:d84b2e88776a

fix: always use rgba
author Sam <sam@basx.dev>
date Tue, 09 May 2023 18:19:17 +0700
parents e85f54b88afb
children 5f7ec8d1bd33
line wrap: on
line diff
--- a/examples/E03_hello_cube.nim	Tue May 09 01:37:46 2023 +0700
+++ b/examples/E03_hello_cube.nim	Tue May 09 18:19:17 2023 +0700
@@ -30,13 +30,16 @@
     TopLeftBack, TopRightBack, TopRightFront, TopLeftFront, # top
     BottomLeftFront, BottomRightFront, BottomRightBack, BottomLeftBack, # bottom
   ]
+  R = newVec4f(1, 0, 0, 1)
+  G = newVec4f(0, 1, 0, 1)
+  B = newVec4f(0, 0, 1, 1)
   cube_color = @[
-    Rf32, Rf32, Rf32, Rf32,
-    Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'f32,
-    Gf32, Gf32, Gf32, Gf32,
-    Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'f32,
-    Bf32, Bf32, Bf32, Bf32,
-    Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'f32,
+    R, R, R, R,
+    R * 0.5'f32, R * 0.5'f32, R * 0.5'f32, R * 0.5'f32,
+    G, G, G, G,
+    G * 0.5'f32, G * 0.5'f32, G * 0.5'f32, G * 0.5'f32,
+    B, B, B, B,
+    B * 0.5'f32, B * 0.5'f32, B * 0.5'f32, B * 0.5'f32,
   ]
 var
   tris: seq[array[3, uint16]]
@@ -51,9 +54,9 @@
   const
     vertexInput = @[
       attr[Vec3f]("position"),
-      attr[Vec3f]("color", memoryPerformanceHint=PreferFastWrite),
+      attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite),
     ]
-    vertexOutput = @[attr[Vec3f]("outcolor")]
+    vertexOutput = @[attr[Vec4f]("outcolor")]
     uniforms = @[
       attr[Mat4]("projection"),
       attr[Mat4]("view"),
@@ -72,7 +75,7 @@
       inputs=vertexOutput,
       uniforms=uniforms,
       outputs=fragOutput,
-      main="color = vec4(outcolor, 1);"
+      main="color = outcolor;"
     )
   myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
   var cube = newScene("scene", newEntity("cube", newMesh(positions=cube_pos, indices=tris, colors=cube_color)))