Mercurial > games > semicongine
annotate tests/test_materials.nim @ 814:6a09fe5dc99b
add: multi-material for meshes
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 20 Sep 2023 22:35:04 +0700 |
parents | fb22fd8142b9 |
children | f4f1474dc70a |
rev | line source |
---|---|
662 | 1 import std/times |
733
07c755e65a4a
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
714
diff
changeset
|
2 import std/tables |
662 | 3 |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 import semicongine |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 |
793 | 6 let |
7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST) | |
813 | 8 (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel) |
793 | 9 thai = Image(width: 7, height: 5, imagedata: @[ |
10 RT, RT, RT, RT, RT, RT, RT, | |
11 WT, WT, WT, WT, WT, WT, WT, | |
12 PT, PT, PT, PT, PT, PT, PT, | |
13 WT, WT, WT, WT, WT, WT, WT, | |
14 RT, RT, RT, RT, RT, RT, RT, | |
15 ]) | |
16 swiss = loadImage("flag.png") | |
17 material = Material(name: "material", textures: { | |
18 "tex1": Texture(image: thai, sampler: sampler), | |
19 "tex2": Texture(image: swiss, sampler: sampler), | |
20 }.toTable) | |
21 | |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 proc main() = |
776
002d9c576756
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
763
diff
changeset
|
23 var flag = rect() |
814 | 24 flag.materials = @[material] |
793 | 25 var scene = Scene(name: "main", meshes: @[flag]) |
691 | 26 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 var engine = initEngine("Test materials") |
714 | 29 |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 const |
793 | 31 shaderConfiguration1 = createShaderConfiguration( |
32 inputs=[ | |
33 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | |
34 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), | |
35 ], | |
36 intermediates=[ | |
37 attr[Vec2f]("uvout"), | |
38 ], | |
39 uniforms=[attr[float32]("test2", arrayCount=2)], | |
40 samplers = @[ | |
795
4a15d94d9418
fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents:
793
diff
changeset
|
41 attr[Texture]("tex1", arrayCount=2), |
4a15d94d9418
fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents:
793
diff
changeset
|
42 attr[Texture]("tex2", arrayCount=2), |
793 | 43 ], |
44 outputs=[attr[Vec4f]("color")], | |
777
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
776
diff
changeset
|
45 vertexCode=""" |
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
776
diff
changeset
|
46 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); |
793 | 47 uvout = uv;""", |
777
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
776
diff
changeset
|
48 fragmentCode=""" |
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
776
diff
changeset
|
49 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; |
793 | 50 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d; |
777
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
776
diff
changeset
|
51 """, |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 ) |
793 | 53 engine.initRenderer({ |
54 "material": shaderConfiguration1, | |
805 | 55 }) |
793 | 56 engine.addScene(scene) |
662 | 57 var t = cpuTime() |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
58 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
691 | 59 var d = float32(cpuTime() - t) |
60 setShaderGlobalArray(scene, "test2", @[d, d * 2]) | |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
61 engine.renderScene(scene) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 engine.destroy() |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 when isMainModule: |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 main() |