Mercurial > games > semicongine
comparison tests/test_materials.nim @ 1091:b9401944ba0a
do: try to increase compatability with older hardware...
author | sam <sam@basx.dev> |
---|---|
date | Sat, 06 Apr 2024 17:29:48 +0700 |
parents | ac3025fcc324 |
children | 73b572f82a1f |
comparison
equal
deleted
inserted
replaced
1090:450b8a5042cd | 1091:b9401944ba0a |
---|---|
33 | 33 |
34 proc main() = | 34 proc main() = |
35 var flag = rect() | 35 var flag = rect() |
36 flag.material = material | 36 flag.material = material |
37 var scene = Scene(name: "main", meshes: @[flag]) | 37 var scene = Scene(name: "main", meshes: @[flag]) |
38 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) | 38 scene.addShaderGlobalArray("test2", @[newVec4f(), newVec4f()]) |
39 | 39 |
40 var engine = initEngine("Test materials") | 40 var engine = initEngine("Test materials") |
41 | 41 |
42 const | 42 const |
43 shaderConfiguration1 = createShaderConfiguration( | 43 shaderConfiguration1 = createShaderConfiguration( |
46 attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead), | 46 attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead), |
47 ], | 47 ], |
48 intermediates = [ | 48 intermediates = [ |
49 attr[Vec2f]("uvout"), | 49 attr[Vec2f]("uvout"), |
50 ], | 50 ], |
51 uniforms = [attr[float32]("test2", arrayCount = 2)], | 51 uniforms = [attr[Vec4f]("test2", arrayCount = 2)], |
52 samplers = @[ | 52 samplers = @[ |
53 attr[Texture]("tex1"), | 53 attr[Texture]("tex1"), |
54 attr[Texture]("tex2"), | 54 attr[Texture]("tex2"), |
55 ], | 55 ], |
56 outputs = [attr[Vec4f]("color")], | 56 outputs = [attr[Vec4f]("color")], |
57 vertexCode = """ | 57 vertexCode = """ |
58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); | 58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1].x) / Uniforms.test2[1].x * 0.5, position.z, 1.0); |
59 uvout = uv;""", | 59 uvout = uv;""", |
60 fragmentCode = """ | 60 fragmentCode = """ |
61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; | 61 float d = sin(Uniforms.test2[0].x) * 0.5 + 0.5; |
62 color = texture(tex1, uvout) * (1 - d) + texture(tex2, uvout) * d; | 62 color = texture(tex1, uvout) * (1 - d) + texture(tex2, uvout) * d; |
63 """, | 63 """, |
64 ) | 64 ) |
65 engine.initRenderer({ | 65 engine.initRenderer({ |
66 doubleTextureMaterial: shaderConfiguration1, | 66 doubleTextureMaterial: shaderConfiguration1, |
67 }) | 67 }) |
68 engine.loadScene(scene) | 68 engine.loadScene(scene) |
69 var t = cpuTime() | 69 var t = cpuTime() |
70 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 70 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
71 var d = float32(cpuTime() - t) | 71 var d = float32(cpuTime() - t) |
72 setShaderGlobalArray(scene, "test2", @[d, d * 2]) | 72 setShaderGlobalArray(scene, "test2", @[newVec4f(d), newVec4f(d * 2)]) |
73 engine.renderScene(scene) | 73 engine.renderScene(scene) |
74 engine.destroy() | 74 engine.destroy() |
75 | 75 |
76 | 76 |
77 when isMainModule: | 77 when isMainModule: |