Mercurial > games > semicongine
comparison tests/test_mesh.nim @ 230:027f6ff06585
add: test mesh
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 16 May 2023 16:08:06 +0700 |
parents | ddfc54036e00 |
children | f05497ef8fd2 |
comparison
equal
deleted
inserted
replaced
229:7741bca03e7c | 230:027f6ff06585 |
---|---|
1 import std/times | 1 import std/times |
2 | 2 |
3 import semicongine | 3 import semicongine |
4 | 4 |
5 proc main() = | 5 proc main() = |
6 var scene = loadScene("test1.glb") | 6 var scene = loadScene("default_cube.glb") |
7 # var scene = loadScene("tutorialk-donat.glb") | |
8 | 7 |
9 var engine = initEngine("Test meshes") | 8 var engine = initEngine("Test meshes") |
10 const | 9 const |
11 vertexInput = @[attr[Vec3f]("POSITION", memoryPerformanceHint=PreferFastRead)] | 10 vertexInput = @[attr[Vec3f]("POSITION", memoryPerformanceHint=PreferFastRead)] |
12 fragOutput = @[attr[Vec4f]("color")] | 11 fragOutput = @[attr[Vec4f]("color")] |
13 uniforms = @[attr[Mat4]("transform")] | 12 uniforms = @[attr[Mat4]("transform")] |
14 vertexCode = compileGlslShader( | 13 vertexCode = compileGlslShader( |
15 stage=VK_SHADER_STAGE_VERTEX_BIT, | 14 stage=VK_SHADER_STAGE_VERTEX_BIT, |
16 inputs=vertexInput, | 15 inputs=vertexInput, |
17 uniforms=uniforms, | 16 uniforms=uniforms, |
18 main="""gl_Position = vec4(POSITION * 0.2, 1.0) * Uniforms.transform;""" | 17 main="""gl_Position = vec4(POSITION, 1.0) * Uniforms.transform;""" |
19 ) | 18 ) |
20 fragmentCode = compileGlslShader( | 19 fragmentCode = compileGlslShader( |
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | 20 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
22 outputs=fragOutput, | 21 outputs=fragOutput, |
23 uniforms=uniforms, | 22 uniforms=uniforms, |
25 color = vec4(61/255, 43/255, 31/255, 1); | 24 color = vec4(61/255, 43/255, 31/255, 1); |
26 """ | 25 """ |
27 ) | 26 ) |
28 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 27 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
29 engine.addScene(scene, vertexInput) | 28 engine.addScene(scene, vertexInput) |
30 let rotateAxis = newVec3f(1, 1, 1) | 29 let rotateAxis = newVec3f(0, 1, 0) |
31 scene.addShaderGlobal("transform", rotate3d(0'f32, rotateAxis)) | 30 scene.addShaderGlobal("transform", Unit4) |
32 var t = cpuTime() | 31 var t = cpuTime() |
33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 32 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
34 scene.setShaderGlobal("transform", rotate3d(float32(cpuTime() - t), rotateAxis)) | 33 scene.setShaderGlobal( |
34 "transform", | |
35 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) | |
36 ) | |
35 engine.renderScene(scene) | 37 engine.renderScene(scene) |
36 engine.destroy() | 38 engine.destroy() |
37 | 39 |
38 | 40 |
39 when isMainModule: | 41 when isMainModule: |