comparison tests/test_materials.nim @ 373:f4f1474dc70a

fix: make tests working again
author Sam <sam@basx.dev>
date Sat, 25 Nov 2023 22:59:06 +0700
parents 61c5d5fe9d93
children fa38cd28f041
comparison
equal deleted inserted replaced
372:eb2ac324a162 373:f4f1474dc70a
12 PT, PT, PT, PT, PT, PT, PT, 12 PT, PT, PT, PT, PT, PT, PT,
13 WT, WT, WT, WT, WT, WT, WT, 13 WT, WT, WT, WT, WT, WT, WT,
14 RT, RT, RT, RT, RT, RT, RT, 14 RT, RT, RT, RT, RT, RT, RT,
15 ]) 15 ])
16 swiss = loadImage("flag.png") 16 swiss = loadImage("flag.png")
17 material = Material(name: "material", textures: { 17 doubleTextureMaterial = MaterialType(
18 "tex1": Texture(image: thai, sampler: sampler), 18 name:"Double texture",
19 "tex2": Texture(image: swiss, sampler: sampler), 19 meshAttributes: {
20 }.toTable) 20 "position": Vec3F32,
21 "uv": Vec2F32,
22 }.toTable,
23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable
24 )
25 material = MaterialData(
26 theType: doubleTextureMaterial,
27 name: "swiss-thai",
28 attributes: {
29 "tex1": initDataList(@[Texture(image: thai, sampler: sampler)]),
30 "tex2": initDataList(@[Texture(image: swiss, sampler: sampler)]),
31 }.toTable
32 )
21 33
22 proc main() = 34 proc main() =
23 var flag = rect() 35 var flag = rect()
24 flag.materials = @[material] 36 flag.material = material
25 var scene = Scene(name: "main", meshes: @[flag]) 37 var scene = Scene(name: "main", meshes: @[flag])
26 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) 38 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32])
27 39
28 var engine = initEngine("Test materials") 40 var engine = initEngine("Test materials")
29 41
49 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; 61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5;
50 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d; 62 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d;
51 """, 63 """,
52 ) 64 )
53 engine.initRenderer({ 65 engine.initRenderer({
54 "material": shaderConfiguration1, 66 doubleTextureMaterial: shaderConfiguration1,
55 }) 67 })
56 engine.addScene(scene) 68 engine.loadScene(scene)
57 var t = cpuTime() 69 var t = cpuTime()
58 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 70 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
59 var d = float32(cpuTime() - t) 71 var d = float32(cpuTime() - t)
60 setShaderGlobalArray(scene, "test2", @[d, d * 2]) 72 setShaderGlobalArray(scene, "test2", @[d, d * 2])
61 engine.renderScene(scene) 73 engine.renderScene(scene)