annotate tests/test_materials.nim @ 1022:f888ac4825b8

did: refactor input system, did some renaming, add quering of keys in key-value-store
author sam <sam@basx.dev>
date Wed, 15 May 2024 19:51:23 +0700
parents 73b572f82a1f
children 74957cbf589b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
201
ab626e67a1ee add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 200
diff changeset
1 import std/times
272
bfcb41211c5b add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 253
diff changeset
2 import std/tables
201
ab626e67a1ee add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 200
diff changeset
3
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
4 import semicongine
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
5
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
6 let
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST)
352
00231e014642 fix: tests
Sam <sam@basx.dev>
parents: 344
diff changeset
8 (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel)
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
9 thai = Image[RGBAPixel](width: 7, height: 5, imagedata: @[
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
10 RT, RT, RT, RT, RT, RT, RT,
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
11 WT, WT, WT, WT, WT, WT, WT,
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
12 PT, PT, PT, PT, PT, PT, PT,
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
13 WT, WT, WT, WT, WT, WT, WT,
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
14 RT, RT, RT, RT, RT, RT, RT,
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
15 ])
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
16 swiss = loadImage[RGBAPixel]("flag.png")
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
17 doubleTextureMaterial = MaterialType(
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
18 name: "Double texture",
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 376
diff changeset
19 vertexAttributes: {
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
20 "position": Vec3F32,
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
21 "uv": Vec2F32,
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
22 }.toTable,
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
24 )
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 384
diff changeset
25 material = initMaterialData(
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
26 theType = doubleTextureMaterial,
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
27 name = "swiss-thai",
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
28 attributes = {
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
29 "tex1": initDataList(@[Texture(colorImage: thai, sampler: sampler, isGrayscale: false)]),
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
30 "tex2": initDataList(@[Texture(colorImage: swiss, sampler: sampler, isGrayscale: false)]),
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 384
diff changeset
31 }
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
32 )
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
33
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
34 proc main() =
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 302
diff changeset
35 var flag = rect()
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
36 flag.material = material
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
37 var scene = Scene(name: "main", meshes: @[flag])
982
a40bb0a48e07 do: try to increase compatability with older hardware...
sam <sam@basx.dev>
parents: 979
diff changeset
38 scene.addShaderGlobalArray("test2", @[newVec4f(), newVec4f()])
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
39
da68fe12f600 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")
253
ad078e26a1c7 fix: API changes
sam <sam@basx.dev>
parents: 244
diff changeset
41
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
42 const
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
43 shaderConfiguration1 = createShaderConfiguration(
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 982
diff changeset
44 name = "shader 1",
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
45 inputs = [
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
46 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead),
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
47 attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead),
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
48 ],
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
49 intermediates = [
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
50 attr[Vec2f]("uvout"),
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
51 ],
982
a40bb0a48e07 do: try to increase compatability with older hardware...
sam <sam@basx.dev>
parents: 979
diff changeset
52 uniforms = [attr[Vec4f]("test2", arrayCount = 2)],
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
53 samplers = @[
979
6406766a222d fix: tests
sam <sam@basx.dev>
parents: 420
diff changeset
54 attr[Texture]("tex1"),
6406766a222d fix: tests
sam <sam@basx.dev>
parents: 420
diff changeset
55 attr[Texture]("tex2"),
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
56 ],
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
57 outputs = [attr[Vec4f]("color")],
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
58 vertexCode = """
982
a40bb0a48e07 do: try to increase compatability with older hardware...
sam <sam@basx.dev>
parents: 979
diff changeset
59 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1].x) / Uniforms.test2[1].x * 0.5, position.z, 1.0);
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
60 uvout = uv;""",
420
91e018270832 fix: all tests (once more)
Sam <sam@basx.dev>
parents: 407
diff changeset
61 fragmentCode = """
982
a40bb0a48e07 do: try to increase compatability with older hardware...
sam <sam@basx.dev>
parents: 979
diff changeset
62 float d = sin(Uniforms.test2[0].x) * 0.5 + 0.5;
979
6406766a222d fix: tests
sam <sam@basx.dev>
parents: 420
diff changeset
63 color = texture(tex1, uvout) * (1 - d) + texture(tex2, uvout) * d;
316
b145a05c2459 add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 315
diff changeset
64 """,
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
65 )
332
e4528d97a687 fix: material tests
Sam <sam@basx.dev>
parents: 316
diff changeset
66 engine.initRenderer({
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
67 doubleTextureMaterial: shaderConfiguration1,
344
b83b3a1ccb05 fix: all tests
Sam <sam@basx.dev>
parents: 334
diff changeset
68 })
373
f4f1474dc70a fix: make tests working again
Sam <sam@basx.dev>
parents: 353
diff changeset
69 engine.loadScene(scene)
201
ab626e67a1ee add: support for arrays of samplers
Sam <sam@basx.dev>
parents: 200
diff changeset
70 var t = cpuTime()
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 982
diff changeset
71 while engine.updateInputs() and not keyIsDown(Escape):
230
027f6ff06585 add: test mesh
Sam <sam@basx.dev>
parents: 211
diff changeset
72 var d = float32(cpuTime() - t)
982
a40bb0a48e07 do: try to increase compatability with older hardware...
sam <sam@basx.dev>
parents: 979
diff changeset
73 setShaderGlobalArray(scene, "test2", @[newVec4f(d), newVec4f(d * 2)])
199
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
74 engine.renderScene(scene)
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
75 engine.destroy()
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
76
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
77
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
78 when isMainModule:
da68fe12f600 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
79 main()