Mercurial > games > semicongine
annotate old_tests/test_materials.nim @ 1354:8ad6e4cfcb2d
merge
author | sam <sam@basx.dev> |
---|---|
date | Fri, 27 Sep 2024 23:45:13 +0700 |
parents | 6360c8d17ce0 |
children |
rev | line source |
---|---|
201 | 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 | 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 | 6 let |
7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST) | |
1137 | 8 (RT, WT, PT) = (ToRGBA("A51931").AsPixel, ToRGBA("F4F5F8").AsPixel, ToRGBA("2D2A4A").AsPixel) |
420 | 9 thai = Image[RGBAPixel](width: 7, height: 5, imagedata: @[ |
332 | 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 ]) | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
16 swiss = LoadImage[RGBAPixel]("flag.png") |
373 | 17 doubleTextureMaterial = MaterialType( |
420 | 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 | 20 "position": Vec3F32, |
21 "uv": Vec2F32, | |
22 }.toTable, | |
23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable | |
24 ) | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
25 material = InitMaterialData( |
420 | 26 theType = doubleTextureMaterial, |
27 name = "swiss-thai", | |
28 attributes = { | |
1137 | 29 "tex1": InitDataList(@[Texture(colorImage: thai, sampler: sampler, isGrayscale: false)]), |
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 | 32 ) |
332 | 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() = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
35 var flag = Rect() |
373 | 36 flag.material = material |
332 | 37 var scene = Scene(name: "main", meshes: @[flag]) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
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 |
1138 | 40 var engine = InitEngine("Test materials") |
253 | 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 |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
43 shaderConfiguration1 = CreateShaderConfiguration( |
1021 | 44 name = "shader 1", |
420 | 45 inputs = [ |
1137 | 46 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
47 Attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead), | |
332 | 48 ], |
420 | 49 intermediates = [ |
1137 | 50 Attr[Vec2f]("uvout"), |
332 | 51 ], |
1137 | 52 uniforms = [Attr[Vec4f]("test2", arrayCount = 2)], |
332 | 53 samplers = @[ |
1137 | 54 Attr[Texture]("tex1"), |
55 Attr[Texture]("tex2"), | |
332 | 56 ], |
1137 | 57 outputs = [Attr[Vec4f]("color")], |
420 | 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 | 60 uvout = uv;""", |
420 | 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 | 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 ) |
1138 | 66 engine.InitRenderer({ |
373 | 67 doubleTextureMaterial: shaderConfiguration1, |
344 | 68 }) |
1138 | 69 engine.LoadScene(scene) |
201 | 70 var t = cpuTime() |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
71 while engine.UpdateInputs() and not KeyIsDown(Escape): |
230 | 72 var d = float32(cpuTime() - t) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
73 SetShaderGlobalArray(scene, "test2", @[NewVec4f(d), NewVec4f(d * 2)]) |
1138 | 74 engine.RenderScene(scene) |
75 engine.Destroy() | |
199
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() |