comparison tests/test_mesh.nim @ 253:ad078e26a1c7

fix: API changes
author sam <sam@basx.dev>
date Wed, 24 May 2023 01:31:21 +0700
parents beb41c93aa3f
children d16fd73959c1
comparison
equal deleted inserted replaced
252:f31d848ab551 253:ad078e26a1c7
5 var ent2 = newEntity("hehe", ent1) 5 var ent2 = newEntity("hehe", ent1)
6 var myScene = newScene("hi", ent2) 6 var myScene = newScene("hi", ent2)
7 myScene.root.transform = translate3d(0.2'f32, 0'f32, 0'f32) 7 myScene.root.transform = translate3d(0.2'f32, 0'f32, 0'f32)
8 myScene.root.children[0].transform = translate3d(0'f32, 0.2'f32, 0'f32) 8 myScene.root.children[0].transform = translate3d(0'f32, 0.2'f32, 0'f32)
9 var scenes = [ 9 var scenes = [
10 # loadScene("default_cube.glb", "1"), 10 loadScene("default_cube.glb", "1"),
11 # loadScene("default_cube1.glb", "3"), 11 # loadScene("default_cube1.glb", "3"),
12 # loadScene("default_cube2.glb", "4"), 12 # loadScene("default_cube2.glb", "4"),
13 # loadScene("flat.glb", "5"), 13 # loadScene("flat.glb", "5"),
14 loadScene("tutorialk-donat.glb", "6"), 14 # loadScene("tutorialk-donat.glb", "6"),
15 # myScene, 15 # myScene,
16 # loadScene("personv3.glb", "2"), 16 # loadScene("personv3.glb", "2"),
17 ] 17 ]
18 18
19 var engine = initEngine("Test meshes") 19 var engine = initEngine("Test meshes")
22 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), 22 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
23 attr[uint8]("material", memoryPerformanceHint=PreferFastRead), 23 attr[uint8]("material", memoryPerformanceHint=PreferFastRead),
24 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), 24 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead),
25 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), 25 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true),
26 ] 26 ]
27 vertexOutput = @[attr[Vec4f]("vertexColor"), attr[Vec2f]("colorTexCoord")] 27 vertexOutput = @[attr[Vec4f]("vertexColor"), #[ attr[Vec2f]("colorTexCoord")]#]
28 fragOutput = @[attr[Vec4f]("color")] 28 fragOutput = @[attr[Vec4f]("color")]
29 uniforms = @[ 29 uniforms = @[
30 attr[Mat4]("projection"), 30 attr[Mat4]("projection"),
31 attr[Mat4]("view"), 31 attr[Mat4]("view"),
32 attr[Vec4f]("material_color", arrayCount=16), 32 attr[Vec4f]("material_color", arrayCount=16),
33 ] 33 ]
34 samplers = @[ 34 samplers = @[
35 attr[Sampler2DType]("material_color_texture", arrayCount=1), 35 # attr[Sampler2DType]("material_color_texture", arrayCount=1),
36 ] 36 ]
37 vertexCode = compileGlslShader( 37 vertexCode = compileGlslShader(
38 stage=VK_SHADER_STAGE_VERTEX_BIT, 38 stage=VK_SHADER_STAGE_VERTEX_BIT,
39 inputs=vertexInput, 39 inputs=vertexInput,
40 outputs=vertexOutput, 40 outputs=vertexOutput,
41 uniforms=uniforms, 41 uniforms=uniforms,
42 samplers=samplers, 42 samplers=samplers,
43 main=""" 43 main="""
44 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); 44 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection);
45 vertexColor = Uniforms.material_color[material]; 45 vertexColor = Uniforms.material_color[material];
46 colorTexCoord = texcoord_0; 46 // colorTexCoord = texcoord_0;
47 """ 47 """
48 ) 48 )
49 fragmentCode = compileGlslShader( 49 fragmentCode = compileGlslShader(
50 stage=VK_SHADER_STAGE_FRAGMENT_BIT, 50 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
51 inputs=vertexOutput, 51 inputs=vertexOutput,
52 outputs=fragOutput, 52 outputs=fragOutput,
53 uniforms=uniforms, 53 uniforms=uniforms,
54 samplers=samplers, 54 samplers=samplers,
55 main="""color = texture(material_color_texture[0], colorTexCoord) * vertexColor;""" 55 # main="""color = texture(material_color_texture[0], colorTexCoord) * vertexColor;"""
56 main="""color = vertexColor;"""
56 ) 57 )
57 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) 58 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1)))
58 for scene in scenes.mitems: 59 for scene in scenes.mitems:
59 engine.addScene(scene, vertexInput, transformAttribute="transform") 60 engine.addScene(scene, vertexInput, samplers, transformAttribute="transform")
60 scene.addShaderGlobal("projection", Unit4) 61 scene.addShaderGlobal("projection", Unit4)
61 scene.addShaderGlobal("view", Unit4) 62 scene.addShaderGlobal("view", Unit4)
62 var 63 var
63 size = 1'f32 64 size = 1'f32
64 elevation = 0'f32 65 elevation = 0'f32