changeset 691:9182a5d2ea3a

add: test mesh
author Sam <sam@basx.dev>
date Tue, 16 May 2023 16:08:06 +0700
parents fe20f8013d12
children 924f54ae02ea
files tests/resources/default/default_cube.glb tests/test_materials.nim tests/test_mesh.nim
diffstat 3 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
Binary file tests/resources/default/default_cube.glb has changed
--- a/tests/test_materials.nim	Tue May 16 15:35:43 2023 +0700
+++ b/tests/test_materials.nim	Tue May 16 16:08:06 2023 +0700
@@ -22,8 +22,7 @@
       RT, RT, RT, RT, RT, RT, RT,
     ])
   scene.addTextures("my_texture", @[t1, t2], interpolation=VK_FILTER_NEAREST)
-  scene.addShaderGlobal("time", 0'f32)
-  var m: Mesh = Mesh(scene.root.components[0])
+  scene.addShaderGlobalArray("test2", @[0'f32, 0'f32])
 
   var engine = initEngine("Test materials")
   const
@@ -32,7 +31,7 @@
       attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead),
     ]
     vertexOutput = @[attr[Vec2f]("uvout")]
-    uniforms = @[attr[float32]("time")]
+    uniforms = @[attr[float32]("test2", arrayCount=2)]
     samplers = @[attr[Sampler2DType]("my_texture", arrayCount=2)]
     fragOutput = @[attr[Vec4f]("color")]
     vertexCode = compileGlslShader(
@@ -41,7 +40,7 @@
       uniforms=uniforms,
       samplers=samplers,
       outputs=vertexOutput,
-      main="""gl_Position = vec4(position, 1.0); uvout = uv;"""
+      main="""gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); uvout = uv;"""
     )
     fragmentCode = compileGlslShader(
       stage=VK_SHADER_STAGE_FRAGMENT_BIT,
@@ -50,7 +49,7 @@
       samplers=samplers,
       outputs=fragOutput,
       main="""
-float d = sin(Uniforms.time * 0.5) * 0.5 + 0.5;
+float d = sin(Uniforms.test2[0]) * 0.5 + 0.5;
 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d;
 """
     )
@@ -58,7 +57,8 @@
   engine.addScene(scene, vertexInput)
   var t = cpuTime()
   while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
-    setShaderGlobal(scene, "time", float32(cpuTime() - t))
+    var d = float32(cpuTime() - t)
+    setShaderGlobalArray(scene, "test2", @[d, d * 2])
     engine.renderScene(scene)
   engine.destroy()
 
--- a/tests/test_mesh.nim	Tue May 16 15:35:43 2023 +0700
+++ b/tests/test_mesh.nim	Tue May 16 16:08:06 2023 +0700
@@ -3,8 +3,7 @@
 import semicongine
 
 proc main() =
-  var scene = loadScene("test1.glb")
-  # var scene = loadScene("tutorialk-donat.glb")
+  var scene = loadScene("default_cube.glb")
 
   var engine = initEngine("Test meshes")
   const
@@ -15,7 +14,7 @@
       stage=VK_SHADER_STAGE_VERTEX_BIT,
       inputs=vertexInput,
       uniforms=uniforms,
-      main="""gl_Position = vec4(POSITION * 0.2, 1.0) * Uniforms.transform;"""
+      main="""gl_Position = vec4(POSITION, 1.0) * Uniforms.transform;"""
     )
     fragmentCode = compileGlslShader(
       stage=VK_SHADER_STAGE_FRAGMENT_BIT,
@@ -27,11 +26,14 @@
     )
   engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
   engine.addScene(scene, vertexInput)
-  let rotateAxis = newVec3f(1, 1, 1)
-  scene.addShaderGlobal("transform", rotate3d(0'f32, rotateAxis))
+  let rotateAxis = newVec3f(0, 1, 0)
+  scene.addShaderGlobal("transform", Unit4)
   var t = cpuTime()
   while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
-    scene.setShaderGlobal("transform", rotate3d(float32(cpuTime() - t), rotateAxis))
+    scene.setShaderGlobal(
+      "transform",
+      scale3d(0.2'f32, 0.2'f32, 0.2'f32) * translate3d(0'f32, 0'f32, 1.8'f32) * rotate3d(float32(PI) / 4'f32, newVec3f(1, 0, 0)) * rotate3d(-float32(cpuTime() - t), rotateAxis)
+    )
     engine.renderScene(scene)
   engine.destroy()