comparison tests/test_gltf.nim @ 1280:a89a70ea3da2

did: undo part of stupid API renaming a few weeks back ;(
author sam <sam@basx.dev>
date Mon, 29 Jul 2024 15:49:37 +0700
parents 01138e6257dd
children c09cdff9a97e
comparison
equal deleted inserted replaced
1277:01138e6257dd 1280:a89a70ea3da2
17 Camera = object 17 Camera = object
18 view: Mat4 18 view: Mat4
19 normal: Mat4 19 normal: Mat4
20 projection: Mat4 20 projection: Mat4
21 Material = object 21 Material = object
22 color: Vec4f = NewVec4f(1, 1, 1, 1) 22 color: Vec4f = vec4(1, 1, 1, 1)
23 # colorTexture: int32 = -1 23 # colorTexture: int32 = -1
24 metallic: float32 = 0 24 metallic: float32 = 0
25 roughness: float32 = 0 25 roughness: float32 = 0
26 # metallicRoughnessTexture: int32 = -1 26 # metallicRoughnessTexture: int32 = -1
27 # normalTexture: int32 = -1 27 # normalTexture: int32 = -1
28 # occlusionTexture: int32 = -1 28 # occlusionTexture: int32 = -1
29 emissive: Vec4f = NewVec4f(0, 0, 0, 0) 29 emissive: Vec4f = vec4(0, 0, 0, 0)
30 # emissiveTexture: int32 = -1 30 # emissiveTexture: int32 = -1
31 MainDescriptors = object 31 MainDescriptors = object
32 materials: array[32, GPUValue[Material, UniformBuffer]] 32 materials: array[32, GPUValue[Material, UniformBuffer]]
33 camera: GPUValue[Camera, UniformBufferMapped] 33 camera: GPUValue[Camera, UniformBufferMapped]
34 Shader = object 34 Shader = object
123 ) 123 )
124 for i in 0 ..< gltfData.materials.len: 124 for i in 0 ..< gltfData.materials.len:
125 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer) 125 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer)
126 for mesh in mitems(gltfData.meshes): 126 for mesh in mitems(gltfData.meshes):
127 for primitive in mitems(mesh): 127 for primitive in mitems(mesh):
128 primitive[0].color = asGPUArray(newSeqWith(primitive[0].position.data.len, NewVec4f(1, 1, 1, 1)), VertexBuffer) 128 primitive[0].color = asGPUArray(newSeqWith(primitive[0].position.data.len, vec4(1, 1, 1, 1)), VertexBuffer)
129 renderdata.AssignBuffers(primitive[0]) 129 renderdata.AssignBuffers(primitive[0])
130 renderdata.AssignBuffers(descriptors) 130 renderdata.AssignBuffers(descriptors)
131 131
132 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) 132 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass)
133 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) 133 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors)
167 if KeyIsDown(W): forward += 2 167 if KeyIsDown(W): forward += 2
168 if KeyIsDown(S): forward -= 2 168 if KeyIsDown(S): forward -= 2
169 if KeyIsDown(A): sideward -= 2 169 if KeyIsDown(A): sideward -= 2
170 if KeyIsDown(D): sideward += 2 170 if KeyIsDown(D): sideward += 2
171 171
172 let camDir = (Rotate(camYaw, Y) * Rotate(camPitch, X)) * Z 172 let camDir = (rotate(camYaw, Y) * rotate(camPitch, X)) * Z
173 let camDirSide = camDir.Cross(-Y).Normalized 173 let camDirSide = camDir.cross(-Y).normalized
174 camPos += camDir * forward * dt 174 camPos += camDir * forward * dt
175 camPos += camDirSide * sideward * dt 175 camPos += camDirSide * sideward * dt
176 176
177 let view = Rotate(-camPitch, X) * Rotate(-camYaw, Y) * Translate(-camPos) 177 let view = rotate(-camPitch, X) * rotate(-camYaw, Y) * translate(-camPos)
178 descriptors.data.camera.data.view = view 178 descriptors.data.camera.data.view = view
179 descriptors.data.camera.data.normal = view 179 descriptors.data.camera.data.normal = view
180 descriptors.data.camera.data.projection = Projection(PI / 2, aspect = GetAspectRatio(), zNear = 0.01, zFar = 20) 180 descriptors.data.camera.data.projection = projection(PI / 2, aspect = GetAspectRatio(), zNear = 0.01, zFar = 20)
181 181
182 UpdateGPUBuffer(descriptors.data.camera) 182 UpdateGPUBuffer(descriptors.data.camera)
183 183
184 WithNextFrame(framebuffer, commandbuffer): 184 WithNextFrame(framebuffer, commandbuffer):
185 185
186 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 186 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
187 187
188 WithPipeline(commandbuffer, pipeline): 188 WithPipeline(commandbuffer, pipeline):
189 WithBind(commandbuffer, (descriptors, ), pipeline): 189 WithBind(commandbuffer, (descriptors, ), pipeline):
190 for nodeId in gltfData.scenes[0]: 190 for nodeId in gltfData.scenes[0]:
191 drawNode( 191 drawNode(
192 commandbuffer = commandbuffer, 192 commandbuffer = commandbuffer,
193 pipeline = pipeline, 193 pipeline = pipeline,
194 nodeId = nodeId, 194 nodeId = nodeId,
195 transform = Rotate(PI / 2, Z) 195 transform = rotate(PI / 2, Z)
196 ) 196 )
197 197
198 # cleanup 198 # cleanup
199 checkVkResult vkDeviceWaitIdle(vulkan.device) 199 checkVkResult vkDeviceWaitIdle(vulkan.device)
200 DestroyPipeline(pipeline) 200 DestroyPipeline(pipeline)