Mercurial > games > semicongine
annotate tests/test_materials.nim @ 684:3e81b82852b2
did: update progress
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 15 May 2023 00:36:25 +0700 |
parents | d7c61e6580ea |
children | 027f6ff06585 |
rev | line source |
---|---|
662 | 1 import std/times |
2 | |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import semicongine |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 proc main() = |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 var scene = newScene("main", root=newEntity("rect", rect())) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 let (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
661
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
8 let (RT, WT, PT) = (hexToColorAlpha("A51931").asPixel, hexToColorAlpha("F4F5F8").asPixel, hexToColorAlpha("2D2A4A").asPixel) |
662 | 9 let |
672 | 10 t1 = Image(width: 5, height: 5, imagedata: @[ |
662 | 11 R, R, R, R, R, |
12 R, R, W, R, R, | |
13 R, W, W, W, R, | |
14 R, R, W, R, R, | |
15 R, R, R, R, R, | |
16 ]) | |
672 | 17 t2 = Image(width: 7, height: 5, imagedata: @[ |
662 | 18 RT, RT, RT, RT, RT, RT, RT, |
19 WT, WT, WT, WT, WT, WT, WT, | |
20 PT, PT, PT, PT, PT, PT, PT, | |
21 WT, WT, WT, WT, WT, WT, WT, | |
22 RT, RT, RT, RT, RT, RT, RT, | |
23 ]) | |
672 | 24 scene.addTextures("my_texture", @[t1, t2], interpolation=VK_FILTER_NEAREST) |
662 | 25 scene.addShaderGlobal("time", 0'f32) |
661
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
26 var m: Mesh = Mesh(scene.root.components[0]) |
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") |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 const |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 vertexInput = @[ |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 ] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 vertexOutput = @[attr[Vec2f]("uvout")] |
662 | 35 uniforms = @[attr[float32]("time")] |
36 samplers = @[attr[Sampler2DType]("my_texture", arrayCount=2)] | |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 fragOutput = @[attr[Vec4f]("color")] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 vertexCode = compileGlslShader( |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 stage=VK_SHADER_STAGE_VERTEX_BIT, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 inputs=vertexInput, |
662 | 41 uniforms=uniforms, |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 samplers=samplers, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 outputs=vertexOutput, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 main="""gl_Position = vec4(position, 1.0); uvout = uv;""" |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 ) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 fragmentCode = compileGlslShader( |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
47 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 inputs=vertexOutput, |
662 | 49 uniforms=uniforms, |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 samplers=samplers, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
51 outputs=fragOutput, |
662 | 52 main=""" |
53 float d = sin(Uniforms.time * 0.5) * 0.5 + 0.5; | |
54 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d; | |
55 """ | |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 ) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
58 engine.addScene(scene, vertexInput) |
662 | 59 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
|
60 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
662 | 61 setShaderGlobal(scene, "time", float32(cpuTime() - t)) |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 engine.renderScene(scene) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 engine.destroy() |
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 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 when isMainModule: |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 main() |