Mercurial > games > semicongine
diff tests/test_mesh.nim @ 708:3bb199dd45ba
fix: gltf loading
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 23 May 2023 01:05:06 +0700 |
parents | 3742bba2293f |
children | ad078e26a1c7 |
line wrap: on
line diff
--- a/tests/test_mesh.nim Mon May 22 19:27:17 2023 +0700 +++ b/tests/test_mesh.nim Tue May 23 01:05:06 2023 +0700 @@ -1,13 +1,19 @@ import semicongine proc main() = + var ent1 = newEntity("hoho", rect()) + var ent2 = newEntity("hehe", ent1) + var myScene = newScene("hi", ent2) + myScene.root.transform = translate3d(0.2'f32, 0'f32, 0'f32) + myScene.root.children[0].transform = translate3d(0'f32, 0.2'f32, 0'f32) var scenes = [ - loadScene("default_cube.glb", "1"), - loadScene("default_cube1.glb", "3"), - loadScene("default_cube2.glb", "4"), - loadScene("flat.glb", "5"), + # loadScene("default_cube.glb", "1"), + # loadScene("default_cube1.glb", "3"), + # loadScene("default_cube2.glb", "4"), + # loadScene("flat.glb", "5"), loadScene("tutorialk-donat.glb", "6"), - loadScene("personv3.glb", "2"), + # myScene, + # loadScene("personv3.glb", "2"), ] var engine = initEngine("Test meshes") @@ -15,37 +21,46 @@ vertexInput = @[ attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), attr[uint8]("material", memoryPerformanceHint=PreferFastRead), + attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), + attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), ] - vertexOutput = @[attr[Vec4f]("vertexColor")] + vertexOutput = @[attr[Vec4f]("vertexColor"), attr[Vec2f]("colorTexCoord")] fragOutput = @[attr[Vec4f]("color")] uniforms = @[ attr[Mat4]("projection"), attr[Mat4]("view"), - attr[Mat4]("model"), attr[Vec4f]("material_color", arrayCount=16), ] + samplers = @[ + attr[Sampler2DType]("material_color_texture", arrayCount=1), + ] vertexCode = compileGlslShader( stage=VK_SHADER_STAGE_VERTEX_BIT, inputs=vertexInput, outputs=vertexOutput, uniforms=uniforms, - main="""gl_Position = Uniforms.projection * Uniforms.view * Uniforms.model * vec4(position, 1.0); vertexColor = Uniforms.material_color[material];""" + samplers=samplers, + main=""" +gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); +vertexColor = Uniforms.material_color[material]; +colorTexCoord = texcoord_0; +""" ) fragmentCode = compileGlslShader( stage=VK_SHADER_STAGE_FRAGMENT_BIT, inputs=vertexOutput, outputs=fragOutput, uniforms=uniforms, - main="""color = vertexColor;""" + samplers=samplers, + main="""color = texture(material_color_texture[0], colorTexCoord) * vertexColor;""" ) engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) for scene in scenes.mitems: - engine.addScene(scene, vertexInput) + engine.addScene(scene, vertexInput, transformAttribute="transform") scene.addShaderGlobal("projection", Unit4) scene.addShaderGlobal("view", Unit4) - scene.addShaderGlobal("model", Unit4) var - size = 0.3'f32 + size = 1'f32 elevation = 0'f32 azimut = 0'f32 currentScene = 0 @@ -78,10 +93,8 @@ "view", scale3d(size, size, size) * rotate3d(elevation, newVec3f(1, 0, 0)) * rotate3d(azimut, Yf32) ) - scenes[currentScene].setShaderGlobal("model", Unit4f32) engine.renderScene(scenes[currentScene]) engine.destroy() - when isMainModule: main()