Mercurial > games > semicongine
comparison examples/E03_hello_cube.nim @ 777:754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
| author | Sam <sam@basx.dev> |
|---|---|
| date | Mon, 07 Aug 2023 00:23:00 +0700 |
| parents | a4c757f5d17f |
| children | 812b5e28f441 |
comparison
equal
deleted
inserted
replaced
| 776:002d9c576756 | 777:754835bf175e |
|---|---|
| 50 | 50 |
| 51 when isMainModule: | 51 when isMainModule: |
| 52 var myengine = initEngine("Hello cube") | 52 var myengine = initEngine("Hello cube") |
| 53 | 53 |
| 54 const | 54 const |
| 55 vertexInput = @[ | 55 inputs = @[ |
| 56 attr[Vec3f]("position"), | 56 attr[Vec3f]("position"), |
| 57 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), | 57 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
| 58 ] | 58 ] |
| 59 vertexOutput = @[attr[Vec4f]("outcolor")] | 59 intermediate = @[attr[Vec4f]("outcolor")] |
| 60 uniforms = @[ | 60 uniforms = @[ |
| 61 attr[Mat4]("projection"), | 61 attr[Mat4]("projection"), |
| 62 attr[Mat4]("view"), | 62 attr[Mat4]("view"), |
| 63 attr[Mat4]("model"), | 63 attr[Mat4]("model"), |
| 64 ] | 64 ] |
| 65 fragOutput = @[attr[Vec4f]("color")] | 65 fragOutput = @[attr[Vec4f]("color")] |
| 66 vertexCode = compileGlslShader( | 66 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( |
| 67 stage=VK_SHADER_STAGE_VERTEX_BIT, | 67 inputs=inputs, |
| 68 inputs=vertexInput, | 68 intermediate=intermediate, |
| 69 outputs=fragOutput, | |
| 69 uniforms=uniforms, | 70 uniforms=uniforms, |
| 70 outputs=vertexOutput, | 71 vertexCode="""outcolor = color; gl_Position = (Uniforms.projection * Uniforms.view * Uniforms.model) * vec4(position, 1);""", |
| 71 main="""outcolor = color; gl_Position = (Uniforms.projection * Uniforms.view * Uniforms.model) * vec4(position, 1);""" | 72 fragmentCode="color = outcolor;", |
| 72 ) | |
| 73 fragmentCode = compileGlslShader( | |
| 74 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | |
| 75 inputs=vertexOutput, | |
| 76 uniforms=uniforms, | |
| 77 outputs=fragOutput, | |
| 78 main="color = outcolor;" | |
| 79 ) | 73 ) |
| 80 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 74 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
| 81 var cube = newScene("scene", newEntity("cube", {"mesh": Component(newMesh(positions=cube_pos, indices=tris, colors=cube_color))})) | 75 var cube = newScene("scene", newEntity("cube", {"mesh": Component(newMesh(positions=cube_pos, indices=tris, colors=cube_color))})) |
| 82 cube.addShaderGlobal("projection", Unit4f32) | 76 cube.addShaderGlobal("projection", Unit4f32) |
| 83 cube.addShaderGlobal("view", Unit4f32) | 77 cube.addShaderGlobal("view", Unit4f32) |
| 84 cube.addShaderGlobal("model", Unit4f32) | 78 cube.addShaderGlobal("model", Unit4f32) |
| 85 myengine.addScene(cube, vertexInput, @[], transformAttribute="") | 79 myengine.addScene(cube, inputs, @[], transformAttribute="") |
| 86 | 80 |
| 87 var t: float32 = cpuTime() | 81 var t: float32 = cpuTime() |
| 88 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): | 82 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
| 89 setShaderGlobal(cube, "model", translate3d(0'f32, 0'f32, 10'f32) * rotate3d(t, Yf32)) | 83 setShaderGlobal(cube, "model", translate3d(0'f32, 0'f32, 10'f32) * rotate3d(t, Yf32)) |
| 90 setShaderGlobal(cube, "projection", | 84 setShaderGlobal(cube, "projection", |
