annotate tests/test_materials.nim @ 842:611f9cee7495

fix: more animation issues
author Sam <sam@basx.dev>
date Mon, 27 Nov 2023 23:14:09 +0700
parents 0d46e6638bd6
children eaf084ba80e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
9848403320f0 add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 661
diff changeset
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
9848403320f0 add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 661
diff changeset
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
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
6 let
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST)
813
fb22fd8142b9 fix: tests
Sam <sam@basx.dev>
parents: 805
diff changeset
8 (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel)
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
9 thai = Image(width: 7, height: 5, imagedata: @[
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
10 RT, RT, RT, RT, RT, RT, RT,
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
11 WT, WT, WT, WT, WT, WT, WT,
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
12 PT, PT, PT, PT, PT, PT, PT,
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
13 WT, WT, WT, WT, WT, WT, WT,
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
14 RT, RT, RT, RT, RT, RT, RT,
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
15 ])
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
16 swiss = loadImage("flag.png")
834
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
17 doubleTextureMaterial = MaterialType(
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
18 name:"Double texture",
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
19 meshAttributes: {
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
20 "position": Vec3F32,
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
21 "uv": Vec2F32,
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
22 }.toTable,
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
24 )
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
25 material = MaterialData(
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
26 theType: doubleTextureMaterial,
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
27 name: "swiss-thai",
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
28 attributes: {
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
29 "tex1": initDataList(@[Texture(image: thai, sampler: sampler)]),
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
30 "tex2": initDataList(@[Texture(image: swiss, sampler: sampler)]),
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
31 }.toTable
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
32 )
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
33
660
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
34 proc main() =
776
002d9c576756 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 763
diff changeset
35 var flag = rect()
834
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
36 flag.material = material
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
37 var scene = Scene(name: "main", meshes: @[flag])
691
9182a5d2ea3a add: test mesh
Sam <sam@basx.dev>
parents: 672
diff changeset
38 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
39
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
40 var engine = initEngine("Test materials")
714
5f7ec8d1bd33 fix: API changes
sam <sam@basx.dev>
parents: 705
diff changeset
41
660
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
42 const
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
43 shaderConfiguration1 = createShaderConfiguration(
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
44 inputs=[
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
45 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
46 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead),
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
47 ],
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
48 intermediates=[
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
49 attr[Vec2f]("uvout"),
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
50 ],
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
51 uniforms=[attr[float32]("test2", arrayCount=2)],
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
52 samplers = @[
837
0d46e6638bd6 fix: all tests
Sam <sam@basx.dev>
parents: 834
diff changeset
53 attr[Texture]("tex1", arrayCount=1),
0d46e6638bd6 fix: all tests
Sam <sam@basx.dev>
parents: 834
diff changeset
54 attr[Texture]("tex2", arrayCount=1),
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
55 ],
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
56 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
57 vertexCode="""
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 776
diff changeset
58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0);
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
59 uvout = uv;""",
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 776
diff changeset
60 fragmentCode="""
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 776
diff changeset
61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5;
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
62 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
63 """,
660
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
64 )
793
c31e42d72253 fix: material tests
Sam <sam@basx.dev>
parents: 777
diff changeset
65 engine.initRenderer({
834
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
66 doubleTextureMaterial: shaderConfiguration1,
805
7a13941ba204 fix: all tests
Sam <sam@basx.dev>
parents: 795
diff changeset
67 })
834
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 814
diff changeset
68 engine.loadScene(scene)
662
9848403320f0 add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 661
diff changeset
69 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
70 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
691
9182a5d2ea3a add: test mesh
Sam <sam@basx.dev>
parents: 672
diff changeset
71 var d = float32(cpuTime() - t)
9182a5d2ea3a add: test mesh
Sam <sam@basx.dev>
parents: 672
diff changeset
72 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
73 engine.renderScene(scene)
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
74 engine.destroy()
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
75
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
76
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
77 when isMainModule:
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
78 main()