comparison tests/test_materials.nim @ 420:91e018270832

fix: all tests (once more)
author Sam <sam@basx.dev>
date Mon, 29 Jan 2024 00:19:35 +0700
parents ffc265916415
children 6406766a222d
comparison
equal deleted inserted replaced
419:18e5443e4f83 420:91e018270832
4 import semicongine 4 import semicongine
5 5
6 let 6 let
7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST) 7 sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST)
8 (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel) 8 (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel)
9 thai = Image(width: 7, height: 5, imagedata: @[ 9 thai = Image[RGBAPixel](width: 7, height: 5, imagedata: @[
10 RT, RT, RT, RT, RT, RT, RT, 10 RT, RT, RT, RT, RT, RT, RT,
11 WT, WT, WT, WT, WT, WT, WT, 11 WT, WT, WT, WT, WT, WT, WT,
12 PT, PT, PT, PT, PT, PT, PT, 12 PT, PT, PT, PT, PT, PT, PT,
13 WT, WT, WT, WT, WT, WT, WT, 13 WT, WT, WT, WT, WT, WT, WT,
14 RT, RT, RT, RT, RT, RT, RT, 14 RT, RT, RT, RT, RT, RT, RT,
15 ]) 15 ])
16 swiss = loadImage("flag.png") 16 swiss = loadImage[RGBAPixel]("flag.png")
17 doubleTextureMaterial = MaterialType( 17 doubleTextureMaterial = MaterialType(
18 name:"Double texture", 18 name: "Double texture",
19 vertexAttributes: { 19 vertexAttributes: {
20 "position": Vec3F32, 20 "position": Vec3F32,
21 "uv": Vec2F32, 21 "uv": Vec2F32,
22 }.toTable, 22 }.toTable,
23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable 23 attributes: {"tex1": TextureType, "tex2": TextureType}.toTable
24 ) 24 )
25 material = initMaterialData( 25 material = initMaterialData(
26 theType=doubleTextureMaterial, 26 theType = doubleTextureMaterial,
27 name="swiss-thai", 27 name = "swiss-thai",
28 attributes={ 28 attributes = {
29 "tex1": initDataList(@[Texture(image: thai, sampler: sampler)]), 29 "tex1": initDataList(@[Texture(colorImage: thai, sampler: sampler, isGrayscale: false)]),
30 "tex2": initDataList(@[Texture(image: swiss, sampler: sampler)]), 30 "tex2": initDataList(@[Texture(colorImage: swiss, sampler: sampler, isGrayscale: false)]),
31 } 31 }
32 ) 32 )
33 33
34 proc main() = 34 proc main() =
35 var flag = rect() 35 var flag = rect()
39 39
40 var engine = initEngine("Test materials") 40 var engine = initEngine("Test materials")
41 41
42 const 42 const
43 shaderConfiguration1 = createShaderConfiguration( 43 shaderConfiguration1 = createShaderConfiguration(
44 inputs=[ 44 inputs = [
45 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), 45 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead),
46 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), 46 attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead),
47 ], 47 ],
48 intermediates=[ 48 intermediates = [
49 attr[Vec2f]("uvout"), 49 attr[Vec2f]("uvout"),
50 ], 50 ],
51 uniforms=[attr[float32]("test2", arrayCount=2)], 51 uniforms = [attr[float32]("test2", arrayCount = 2)],
52 samplers = @[ 52 samplers = @[
53 attr[Texture]("tex1", arrayCount=1), 53 attr[Texture]("tex1", arrayCount = 1),
54 attr[Texture]("tex2", arrayCount=1), 54 attr[Texture]("tex2", arrayCount = 1),
55 ], 55 ],
56 outputs=[attr[Vec4f]("color")], 56 outputs = [attr[Vec4f]("color")],
57 vertexCode=""" 57 vertexCode = """
58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); 58 gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0);
59 uvout = uv;""", 59 uvout = uv;""",
60 fragmentCode=""" 60 fragmentCode = """
61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; 61 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5;
62 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d; 62 color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d;
63 """, 63 """,
64 ) 64 )
65 engine.initRenderer({ 65 engine.initRenderer({