Mercurial > games > semicongine
annotate tests/test_gltf.nim @ 1279:e0ba4aead324
merge
author | sam <sam@basx.dev> |
---|---|
date | Mon, 29 Jul 2024 15:43:44 +0700 |
parents | 772bb32c4368 01138e6257dd |
children | c09cdff9a97e |
rev | line source |
---|---|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/os |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/sequtils |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/monotimes |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
4 import std/times |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
5 import std/options |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
6 import std/random |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
7 |
1267 | 8 import ../semicongine |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
9 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
10 proc test_gltf(time: float32) = |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
11 var renderdata = InitRenderData() |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
12 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
13 type |
1253 | 14 ObjectData = object |
15 transform: Mat4 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
16 materialId: int32 |
1253 | 17 Camera = object |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
18 view: Mat4 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
19 normal: Mat4 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
20 projection: Mat4 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
21 Material = object |
1248 | 22 color: Vec4f = NewVec4f(1, 1, 1, 1) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
23 # colorTexture: int32 = -1 |
1248 | 24 metallic: float32 = 0 |
25 roughness: float32 = 0 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
26 # metallicRoughnessTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
27 # normalTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
28 # occlusionTexture: int32 = -1 |
1248 | 29 emissive: Vec4f = NewVec4f(0, 0, 0, 0) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
30 # emissiveTexture: int32 = -1 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
31 MainDescriptors = object |
1278
772bb32c4368
replcae lodepng with stb_image, some cleanup
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
32 materials: array[50, GPUValue[Material, UniformBuffer]] |
1253 | 33 camera: GPUValue[Camera, UniformBufferMapped] |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
34 Shader = object |
1253 | 35 objectData {.PushConstantAttribute.}: ObjectData |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
36 position {.VertexAttribute.}: Vec3f |
1254 | 37 color {.VertexAttribute.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
38 normal {.VertexAttribute.}: Vec3f |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
39 fragmentPosition {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
40 fragmentColor {.Pass.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
41 fragmentNormal {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
42 outColor {.ShaderOutput.}: Vec4f |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
43 descriptors {.DescriptorSets.}: (MainDescriptors, ) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
44 # code |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
45 vertexCode: string = """ |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
46 void main() { |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
47 mat4 modelView = objectData.transform * camera.view; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
48 mat3 normalMat = mat3(transpose(inverse(objectData.transform))); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
49 vec4 posTransformed = vec4(position, 1) * modelView; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
50 fragmentPosition = posTransformed.xyz / posTransformed.w; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
51 fragmentColor = color * materials[objectData.materialId].color; |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
52 fragmentNormal = normal * normalMat; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
53 gl_Position = vec4(position, 1) * (modelView * camera.projection); |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
54 }""" |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
55 fragmentCode: string = """ |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
56 const vec3 lightPosition = vec3(7, 9, -12); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
57 const float shininess = 40; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
58 const vec3 ambientColor = vec3(0, 0, 0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
59 const vec3 lightColor = vec3(1, 1, 1); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
60 // const vec3 specColor = vec3(1, 1, 1); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
61 const float lightPower = 20; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
62 void main() { |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
63 // some setup |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
64 vec3 normal = normalize(fragmentNormal); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
65 vec3 lightDir = lightPosition - fragmentPosition; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
66 float dist = length(lightDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
67 lightDir = normalize(lightDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
68 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
69 float lambertian = max(dot(lightDir, normal), 0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
70 float specular = 0; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
71 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
72 // blinn-phong |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
73 if (lambertian > 0) { |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
74 vec3 viewDir = normalize(-fragmentPosition); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
75 vec3 halfDir = normalize(lightDir + viewDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
76 float specAngle = max(dot(halfDir, normal), 0.0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
77 specular = pow(specAngle, shininess); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
78 } |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
79 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
80 vec3 diffuseColor = fragmentColor.rgb; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
81 vec3 specColor = diffuseColor; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
82 vec3 color = ambientColor + diffuseColor * lambertian * lightColor * lightPower / dist + specColor * specular * lightColor * lightPower / dist; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
83 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
84 outColor = vec4(color, fragmentColor.a); |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
85 }""" |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
86 Mesh = object |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
87 position: GPUArray[Vec3f, VertexBuffer] |
1254 | 88 color: GPUArray[Vec4f, VertexBuffer] |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
89 normal: GPUArray[Vec3f, VertexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
90 indices: GPUArray[uint32, IndexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
91 material: int32 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
92 |
1251 | 93 var gltfData = LoadMeshes[Mesh, Material]( |
1259 | 94 "town.glb", |
95 # "forest.glb", | |
1248 | 96 MeshAttributeNames( |
97 POSITION: "position", | |
1254 | 98 COLOR: @["color"], |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
99 NORMAL: "normal", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
100 indices: "indices", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
101 material: "material", |
1254 | 102 ), |
1248 | 103 MaterialAttributeNames( |
104 baseColorFactor: "color", | |
105 baseColorTexture: "colorTexture", | |
106 metallicFactor: "metallic", | |
107 roughnessFactor: "roughness", | |
108 metallicRoughnessTexture: "metallicRoughnessTexture", | |
109 normalTexture: "normalTexture", | |
110 occlusionTexture: "occlusionTexture", | |
111 emissiveTexture: "emissiveTexture", | |
112 emissiveFactor: "emissive", | |
113 ) | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
114 ) |
1253 | 115 var descriptors = asDescriptorSet( |
116 MainDescriptors( | |
117 camera: asGPUValue(Camera( | |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
118 view: Unit4, |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
119 normal: Unit4, |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
120 projection: Unit4, |
1254 | 121 ), UniformBufferMapped) |
122 ) | |
1253 | 123 ) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
124 for i in 0 ..< gltfData.materials.len: |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
125 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer) |
1251 | 126 for mesh in mitems(gltfData.meshes): |
1249
d83726af7abb
did: first triangles getting loaded from gltf
sam <sam@basx.dev>
parents:
1248
diff
changeset
|
127 for primitive in mitems(mesh): |
1254 | 128 primitive[0].color = asGPUArray(newSeqWith(primitive[0].position.data.len, NewVec4f(1, 1, 1, 1)), VertexBuffer) |
1249
d83726af7abb
did: first triangles getting loaded from gltf
sam <sam@basx.dev>
parents:
1248
diff
changeset
|
129 renderdata.AssignBuffers(primitive[0]) |
1253 | 130 renderdata.AssignBuffers(descriptors) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
131 |
1278
772bb32c4368
replcae lodepng with stb_image, some cleanup
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
132 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, cullMode=[]) |
1253 | 133 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) |
1254 | 134 |
1253 | 135 renderdata.FlushAllMemory() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
136 |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
137 proc drawNode(commandbuffer: VkCommandBuffer, pipeline: Pipeline, nodeId: int, transform: Mat4) = |
1251 | 138 let nodeTransform = gltfData.nodes[nodeId].transform * transform |
139 if gltfData.nodes[nodeId].mesh >= 0: | |
140 for primitive in gltfData.meshes[gltfData.nodes[nodeId].mesh]: | |
1254 | 141 RenderWithPushConstant( |
142 commandbuffer = commandbuffer, | |
143 pipeline = pipeline, | |
144 mesh = primitive[0], | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
145 pushConstant = ObjectData(transform: nodeTransform, materialId: primitive[0].material) |
1254 | 146 ) |
1251 | 147 for childNode in gltfData.nodes[nodeId].children: |
148 drawNode(commandbuffer = commandbuffer, pipeline = pipeline, nodeId = childNode, transform = nodeTransform) | |
149 | |
1254 | 150 var camPos: Vec3f |
151 var camYaw: float32 | |
152 var camPitch: float32 | |
153 | |
154 discard UpdateInputs() # clear inputs, otherwise MouseMove will have stuff | |
1251 | 155 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
156 var start = getMonoTime() |
1254 | 157 var lastT = getMonoTime() |
158 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time and UpdateInputs(): | |
159 let dt = ((getMonoTime() - lastT).inNanoseconds().int / 1_000_000_000).float32 | |
160 lastT = getMonoTime() | |
161 | |
162 camYaw -= MouseMove().x / 1000 | |
163 camPitch -= MouseMove().y / 1000 | |
164 var | |
165 forward = 0'f32 | |
166 sideward = 0'f32 | |
167 if KeyIsDown(W): forward += 2 | |
168 if KeyIsDown(S): forward -= 2 | |
169 if KeyIsDown(A): sideward -= 2 | |
170 if KeyIsDown(D): sideward += 2 | |
171 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
172 let camDir = (Rotate(camYaw, Y) * Rotate(camPitch, X)) * Z |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
173 let camDirSide = camDir.Cross(-Y).Normalized |
1254 | 174 camPos += camDir * forward * dt |
175 camPos += camDirSide * sideward * dt | |
176 | |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
177 let view = Rotate(-camPitch, X) * Rotate(-camYaw, Y) * Translate(-camPos) |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
178 descriptors.data.camera.data.view = view |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
179 descriptors.data.camera.data.normal = view |
1277 | 180 descriptors.data.camera.data.projection = Projection(PI / 2, aspect = GetAspectRatio(), zNear = 0.01, zFar = 20) |
1254 | 181 |
182 UpdateGPUBuffer(descriptors.data.camera) | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
183 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
184 WithNextFrame(framebuffer, commandbuffer): |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
185 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
186 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
187 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
188 WithPipeline(commandbuffer, pipeline): |
1253 | 189 WithBind(commandbuffer, (descriptors, ), pipeline): |
190 for nodeId in gltfData.scenes[0]: | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
191 drawNode( |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
192 commandbuffer = commandbuffer, |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
193 pipeline = pipeline, |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
194 nodeId = nodeId, |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
195 transform = Rotate(PI / 2, Z) |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
196 ) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
197 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
198 # cleanup |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
199 checkVkResult vkDeviceWaitIdle(vulkan.device) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
200 DestroyPipeline(pipeline) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
201 DestroyRenderData(renderdata) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
202 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
203 when isMainModule: |
1254 | 204 var time = 1000'f32 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
205 InitVulkan() |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
206 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
207 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
208 SetupSwapchain(renderpass = renderpass) |
1254 | 209 LockMouse(true) |
1256
bfb75c934f4e
add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents:
1255
diff
changeset
|
210 ShowSystemCursor(false) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
211 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
212 # tests a simple triangle with minimalistic shader and vertex format |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
213 test_gltf(time) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
214 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
215 checkVkResult vkDeviceWaitIdle(vulkan.device) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
216 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
217 ClearSwapchain() |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
218 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
219 DestroyVulkan() |