Mercurial > games > semicongine
comparison examples/E02_squares.nim @ 68:bdef52f3bc0d
fix: API changes
| author | Sam <sam@basx.dev> |
|---|---|
| date | Sun, 05 Feb 2023 00:28:18 +0700 |
| parents | 0f04ba283558 |
| children | 779607656b12 |
comparison
equal
deleted
inserted
replaced
| 67:31ccaeee09c9 | 68:bdef52f3bc0d |
|---|---|
| 59 1), uint16(vertIndex + 2)] | 59 1), uint16(vertIndex + 2)] |
| 60 indices[squareIndex * 2 + 1] = [uint16(vertIndex + 2), uint16(vertIndex + | 60 indices[squareIndex * 2 + 1] = [uint16(vertIndex + 2), uint16(vertIndex + |
| 61 3), uint16(vertIndex + 0)] | 61 3), uint16(vertIndex + 0)] |
| 62 | 62 |
| 63 | 63 |
| 64 type PIndexedMesh = IndexedMesh[VertexDataA, | 64 type PIndexedMesh = Mesh[VertexDataA, |
| 65 uint16] # required so we can use ctor with ref/on heap | 65 uint16] # required so we can use ctor with ref/on heap |
| 66 var squaremesh = PIndexedMesh( | 66 var squaremesh = PIndexedMesh( |
| 67 vertexData: VertexDataA( | 67 vertexData: VertexDataA( |
| 68 position11: PositionAttribute[Vec2](data: @vertices), | 68 position11: PositionAttribute[Vec2](data: @vertices), |
| 69 color22: ColorAttribute[Vec3](data: @colors), | 69 color22: ColorAttribute[Vec3](data: @colors), |
| 70 index: GenericAttribute[uint32](data: @iValues), | 70 index: GenericAttribute[uint32](data: @iValues), |
| 71 ), | 71 ), |
| 72 indexed: true, | |
| 72 indices: @indices | 73 indices: @indices |
| 73 ) | 74 ) |
| 74 var scene = newThing("scene", newThing("squares", squaremesh)) | 75 var scene = newThing("scene", newThing("squares", squaremesh)) |
| 75 | 76 |
| 76 const vertexShader = generateVertexShaderCode[VertexDataA, Uniforms]( | 77 const vertexShader = generateVertexShaderCode[VertexDataA, Uniforms]( |
| 77 """ | 78 """ |
| 78 float pos_weight = index / 100.0; // add some gamma correction? | 79 float pos_weight = index / 100.0; // add some gamma correction? |
| 79 float t = sin(uniforms.t * 0.5) * 0.5 + 0.5; | 80 float t = sin(uniforms.t * 0.5) * 0.5 + 0.5; |
| 80 float v = min(1, max(0, pow(pos_weight - t, 2))); | 81 float v = min(1, max(0, pow(pos_weight - t, 2))); |
| 81 v = pow(1 - v, 3000); | 82 v = pow(1 - v, 3000); |
| 82 out_color = vec3(in_color.r, in_color.g, v * 0.5); | 83 out_color = vec4(in_color.r, in_color.g, v * 0.5, 1.0); |
| 83 """ | 84 """ |
| 84 ) | 85 ) |
| 85 const fragmentShader = generateFragmentShaderCode[VertexDataA]() | 86 const fragmentShader = generateFragmentShaderCode[VertexDataA]() |
| 87 static: | |
| 88 echo vertexShader | |
| 86 pipeline = setupPipeline[VertexDataA, Uniforms, uint16]( | 89 pipeline = setupPipeline[VertexDataA, Uniforms, uint16]( |
| 87 myengine, | 90 myengine, |
| 88 scene, | 91 scene, |
| 89 vertexShader, | 92 vertexShader, |
| 90 fragmentShader | 93 fragmentShader |
