Mercurial > games > semicongine
annotate tests/test_materials.nim @ 923:27fdf971354d
fix: wording
author | sam <sam@basx.dev> |
---|---|
date | Thu, 21 Mar 2024 15:50:10 +0700 |
parents | 91e018270832 |
children | 6406766a222d |
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) | |
352 | 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 ]) | |
420 | 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 ) | |
407
ffc265916415
did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents:
384
diff
changeset
|
25 material = initMaterialData( |
420 | 26 theType = doubleTextureMaterial, |
27 name = "swiss-thai", | |
28 attributes = { | |
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() = |
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 | 36 flag.material = material |
332 | 37 var scene = Scene(name: "main", meshes: @[flag]) |
230 | 38 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) |
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 | 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 | 43 shaderConfiguration1 = createShaderConfiguration( |
420 | 44 inputs = [ |
45 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | |
46 attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead), | |
332 | 47 ], |
420 | 48 intermediates = [ |
332 | 49 attr[Vec2f]("uvout"), |
50 ], | |
420 | 51 uniforms = [attr[float32]("test2", arrayCount = 2)], |
332 | 52 samplers = @[ |
420 | 53 attr[Texture]("tex1", arrayCount = 1), |
54 attr[Texture]("tex2", arrayCount = 1), | |
332 | 55 ], |
420 | 56 outputs = [attr[Vec4f]("color")], |
57 vertexCode = """ | |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
315
diff
changeset
|
58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); |
332 | 59 uvout = uv;""", |
420 | 60 fragmentCode = """ |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
315
diff
changeset
|
61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; |
332 | 62 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d; |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
315
diff
changeset
|
63 """, |
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 ) |
332 | 65 engine.initRenderer({ |
373 | 66 doubleTextureMaterial: shaderConfiguration1, |
344 | 67 }) |
373 | 68 engine.loadScene(scene) |
201 | 69 var t = cpuTime() |
199
da68fe12f600
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): |
230 | 71 var d = float32(cpuTime() - t) |
72 setShaderGlobalArray(scene, "test2", @[d, d * 2]) | |
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 engine.renderScene(scene) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 engine.destroy() |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 |
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 when isMainModule: |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 main() |