Mercurial > games > semicongine
comparison tests/test_materials.nim @ 230:027f6ff06585
add: test mesh
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 16 May 2023 16:08:06 +0700 |
parents | 744285b47a4d |
children | 3918e42bf26e |
comparison
equal
deleted
inserted
replaced
229:7741bca03e7c | 230:027f6ff06585 |
---|---|
20 PT, PT, PT, PT, PT, PT, PT, | 20 PT, PT, PT, PT, PT, PT, PT, |
21 WT, WT, WT, WT, WT, WT, WT, | 21 WT, WT, WT, WT, WT, WT, WT, |
22 RT, RT, RT, RT, RT, RT, RT, | 22 RT, RT, RT, RT, RT, RT, RT, |
23 ]) | 23 ]) |
24 scene.addTextures("my_texture", @[t1, t2], interpolation=VK_FILTER_NEAREST) | 24 scene.addTextures("my_texture", @[t1, t2], interpolation=VK_FILTER_NEAREST) |
25 scene.addShaderGlobal("time", 0'f32) | 25 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) |
26 var m: Mesh = Mesh(scene.root.components[0]) | |
27 | 26 |
28 var engine = initEngine("Test materials") | 27 var engine = initEngine("Test materials") |
29 const | 28 const |
30 vertexInput = @[ | 29 vertexInput = @[ |
31 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 30 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
32 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), | 31 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), |
33 ] | 32 ] |
34 vertexOutput = @[attr[Vec2f]("uvout")] | 33 vertexOutput = @[attr[Vec2f]("uvout")] |
35 uniforms = @[attr[float32]("time")] | 34 uniforms = @[attr[float32]("test2", arrayCount=2)] |
36 samplers = @[attr[Sampler2DType]("my_texture", arrayCount=2)] | 35 samplers = @[attr[Sampler2DType]("my_texture", arrayCount=2)] |
37 fragOutput = @[attr[Vec4f]("color")] | 36 fragOutput = @[attr[Vec4f]("color")] |
38 vertexCode = compileGlslShader( | 37 vertexCode = compileGlslShader( |
39 stage=VK_SHADER_STAGE_VERTEX_BIT, | 38 stage=VK_SHADER_STAGE_VERTEX_BIT, |
40 inputs=vertexInput, | 39 inputs=vertexInput, |
41 uniforms=uniforms, | 40 uniforms=uniforms, |
42 samplers=samplers, | 41 samplers=samplers, |
43 outputs=vertexOutput, | 42 outputs=vertexOutput, |
44 main="""gl_Position = vec4(position, 1.0); uvout = uv;""" | 43 main="""gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); uvout = uv;""" |
45 ) | 44 ) |
46 fragmentCode = compileGlslShader( | 45 fragmentCode = compileGlslShader( |
47 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | 46 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
48 inputs=vertexOutput, | 47 inputs=vertexOutput, |
49 uniforms=uniforms, | 48 uniforms=uniforms, |
50 samplers=samplers, | 49 samplers=samplers, |
51 outputs=fragOutput, | 50 outputs=fragOutput, |
52 main=""" | 51 main=""" |
53 float d = sin(Uniforms.time * 0.5) * 0.5 + 0.5; | 52 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; |
54 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d; | 53 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d; |
55 """ | 54 """ |
56 ) | 55 ) |
57 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 56 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
58 engine.addScene(scene, vertexInput) | 57 engine.addScene(scene, vertexInput) |
59 var t = cpuTime() | 58 var t = cpuTime() |
60 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 59 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
61 setShaderGlobal(scene, "time", float32(cpuTime() - t)) | 60 var d = float32(cpuTime() - t) |
61 setShaderGlobalArray(scene, "test2", @[d, d * 2]) | |
62 engine.renderScene(scene) | 62 engine.renderScene(scene) |
63 engine.destroy() | 63 engine.destroy() |
64 | 64 |
65 | 65 |
66 when isMainModule: | 66 when isMainModule: |