Mercurial > games > semicongine
comparison examples/E10_pong.nim @ 316:b145a05c2459
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 | da0bd61abe91 |
children | 887ddc8d45fd |
comparison
equal
deleted
inserted
replaced
315:4921ec86dcb4 | 316:b145a05c2459 |
---|---|
29 var ball = newEntity("ball", {"mesh": Component(ballmesh)}) | 29 var ball = newEntity("ball", {"mesh": Component(ballmesh)}) |
30 ball.transform = scale3d(ballSize, ballSize, 1'f) * translate3d(10'f, 10'f, 0'f) | 30 ball.transform = scale3d(ballSize, ballSize, 1'f) * translate3d(10'f, 10'f, 0'f) |
31 level.root.add ball | 31 level.root.add ball |
32 | 32 |
33 const | 33 const |
34 vertexInput = @[ | 34 inputs = @[ |
35 attr[Vec3f]("position"), | 35 attr[Vec3f]("position"), |
36 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), | 36 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
37 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), | 37 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), |
38 ] | 38 ] |
39 vertexOutput = @[attr[Vec4f]("outcolor")] | 39 intermediate = @[attr[Vec4f]("outcolor")] |
40 uniforms = @[attr[Mat4]("projection")] | 40 uniforms = @[attr[Mat4]("projection")] |
41 fragOutput = @[attr[Vec4f]("color")] | 41 outputs = @[attr[Vec4f]("color")] |
42 vertexCode = compileGlslShader( | 42 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( |
43 stage=VK_SHADER_STAGE_VERTEX_BIT, | 43 inputs=inputs, |
44 inputs=vertexInput, | 44 intermediate=intermediate, |
45 outputs=outputs, | |
45 uniforms=uniforms, | 46 uniforms=uniforms, |
46 outputs=vertexOutput, | 47 vertexCode="""outcolor = color; gl_Position = vec4(position, 1) * (transform * Uniforms.projection);""", |
47 main="""outcolor = color; gl_Position = vec4(position, 1) * (transform * Uniforms.projection);""" | 48 fragmentCode="color = outcolor;", |
48 ) | |
49 fragmentCode = compileGlslShader( | |
50 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | |
51 inputs=vertexOutput, | |
52 uniforms=uniforms, | |
53 outputs=fragOutput, | |
54 main="color = outcolor;" | |
55 ) | 49 ) |
56 | 50 |
57 # set up rendering | 51 # set up rendering |
58 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=backgroundColor)) | 52 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=backgroundColor)) |
59 myengine.addScene(level, vertexInput, @[], transformAttribute="transform") | 53 myengine.addScene(level, inputs, @[], transformAttribute="transform") |
60 level.addShaderGlobal("projection", Unit4f32) | 54 level.addShaderGlobal("projection", Unit4f32) |
61 | 55 |
62 var | 56 var |
63 winsize = myengine.getWindow().size | 57 winsize = myengine.getWindow().size |
64 height = float32(winsize[1]) / float32(winsize[0]) | 58 height = float32(winsize[1]) / float32(winsize[0]) |