Mercurial > games > semicongine
comparison examples/E03_hello_cube.nim @ 210:f3912838cd69
fix: always use rgba
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 09 May 2023 18:19:17 +0700 |
parents | 6e2017cb8b8b |
children | ad078e26a1c7 |
comparison
equal
deleted
inserted
replaced
209:461c18ee759b | 210:f3912838cd69 |
---|---|
28 TopLeftBack, TopLeftFront, BottomLeftFront, BottomLeftBack, # left | 28 TopLeftBack, TopLeftFront, BottomLeftFront, BottomLeftBack, # left |
29 TopRightBack, TopRightFront, BottomRightFront, BottomRightBack, # right | 29 TopRightBack, TopRightFront, BottomRightFront, BottomRightBack, # right |
30 TopLeftBack, TopRightBack, TopRightFront, TopLeftFront, # top | 30 TopLeftBack, TopRightBack, TopRightFront, TopLeftFront, # top |
31 BottomLeftFront, BottomRightFront, BottomRightBack, BottomLeftBack, # bottom | 31 BottomLeftFront, BottomRightFront, BottomRightBack, BottomLeftBack, # bottom |
32 ] | 32 ] |
33 R = newVec4f(1, 0, 0, 1) | |
34 G = newVec4f(0, 1, 0, 1) | |
35 B = newVec4f(0, 0, 1, 1) | |
33 cube_color = @[ | 36 cube_color = @[ |
34 Rf32, Rf32, Rf32, Rf32, | 37 R, R, R, R, |
35 Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'f32, | 38 R * 0.5'f32, R * 0.5'f32, R * 0.5'f32, R * 0.5'f32, |
36 Gf32, Gf32, Gf32, Gf32, | 39 G, G, G, G, |
37 Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'f32, | 40 G * 0.5'f32, G * 0.5'f32, G * 0.5'f32, G * 0.5'f32, |
38 Bf32, Bf32, Bf32, Bf32, | 41 B, B, B, B, |
39 Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'f32, | 42 B * 0.5'f32, B * 0.5'f32, B * 0.5'f32, B * 0.5'f32, |
40 ] | 43 ] |
41 var | 44 var |
42 tris: seq[array[3, uint16]] | 45 tris: seq[array[3, uint16]] |
43 for i in 0'u16 ..< 6'u16: | 46 for i in 0'u16 ..< 6'u16: |
44 let off = i * 4 | 47 let off = i * 4 |
49 var myengine = initEngine("Hello cube") | 52 var myengine = initEngine("Hello cube") |
50 | 53 |
51 const | 54 const |
52 vertexInput = @[ | 55 vertexInput = @[ |
53 attr[Vec3f]("position"), | 56 attr[Vec3f]("position"), |
54 attr[Vec3f]("color", memoryPerformanceHint=PreferFastWrite), | 57 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
55 ] | 58 ] |
56 vertexOutput = @[attr[Vec3f]("outcolor")] | 59 vertexOutput = @[attr[Vec4f]("outcolor")] |
57 uniforms = @[ | 60 uniforms = @[ |
58 attr[Mat4]("projection"), | 61 attr[Mat4]("projection"), |
59 attr[Mat4]("view"), | 62 attr[Mat4]("view"), |
60 attr[Mat4]("model"), | 63 attr[Mat4]("model"), |
61 ] | 64 ] |
70 fragmentCode = compileGlslShader( | 73 fragmentCode = compileGlslShader( |
71 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | 74 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
72 inputs=vertexOutput, | 75 inputs=vertexOutput, |
73 uniforms=uniforms, | 76 uniforms=uniforms, |
74 outputs=fragOutput, | 77 outputs=fragOutput, |
75 main="color = vec4(outcolor, 1);" | 78 main="color = outcolor;" |
76 ) | 79 ) |
77 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 80 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
78 var cube = newScene("scene", newEntity("cube", newMesh(positions=cube_pos, indices=tris, colors=cube_color))) | 81 var cube = newScene("scene", newEntity("cube", newMesh(positions=cube_pos, indices=tris, colors=cube_color))) |
79 cube.addShaderGlobal("projection", Unit4f32) | 82 cube.addShaderGlobal("projection", Unit4f32) |
80 cube.addShaderGlobal("view", Unit4f32) | 83 cube.addShaderGlobal("view", Unit4f32) |