# HG changeset patch # User Sam # Date 1684228086 -25200 # Node ID 027f6ff06585cbe0f6fca3320b3650e453e56a79 # Parent 7741bca03e7c65f7ee922c75179aeb27f74316d7 add: test mesh diff -r 7741bca03e7c -r 027f6ff06585 tests/resources/default/default_cube.glb Binary file tests/resources/default/default_cube.glb has changed diff -r 7741bca03e7c -r 027f6ff06585 tests/test_materials.nim --- 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() diff -r 7741bca03e7c -r 027f6ff06585 tests/test_mesh.nim --- 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()