annotate tests/test_gltf.nim @ 1254:b0f4c8ccd49a

did: stuff to test gltf importer
author sam <sam@basx.dev>
date Sat, 27 Jul 2024 20:47:54 +0700
parents c4f98eb4bb05
children 2b5ca798f6d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
8 import ../semiconginev2
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
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
14 ObjectData = object
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
15 transform: Mat4
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
16 Camera = object
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
17 viewPerspective: Mat4
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
18 Material = object
1248
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
19 color: Vec4f = NewVec4f(1, 1, 1, 1)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
20 colorTexture: int32 = -1
1248
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
21 metallic: float32 = 0
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
22 roughness: float32 = 0
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
23 metallicRoughnessTexture: int32 = -1
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
24
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
25 normalTexture: int32 = -1
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
26 occlusionTexture: int32 = -1
1248
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
27 emissive: Vec4f = NewVec4f(0, 0, 0, 0)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
28 emissiveTexture: int32 = -1
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
29 MainDescriptors = object
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
30 material: GPUValue[Material, UniformBuffer]
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
31 camera: GPUValue[Camera, UniformBufferMapped]
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
32 Shader = object
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
33 objectData {.PushConstantAttribute.}: ObjectData
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
34 position {.VertexAttribute.}: Vec3f
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
35 color {.VertexAttribute.}: Vec4f
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
36 # uv {.VertexAttribute.}: Vec2f
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
37 fragmentColor {.Pass.}: Vec4f
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
38 fragmentUv {.Pass.}: Vec2f
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
39 outColor {.ShaderOutput.}: Vec4f
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
40 descriptors {.DescriptorSets.}: (MainDescriptors, )
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
41 # code
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
42 vertexCode: string = """
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
43 void main() {
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
44 fragmentColor = color;
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
45 // fragmentUv = uv;
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
46 gl_Position = vec4(position, 1) * camera.viewPerspective;
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
47 }"""
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
48 fragmentCode: string = """void main() { outColor = fragmentColor;}"""
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
49 Mesh = object
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
50 position: GPUArray[Vec3f, VertexBuffer]
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
51 color: GPUArray[Vec4f, VertexBuffer]
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
52 uv: GPUArray[Vec2f, VertexBuffer]
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
53 DebugMesh = object
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
54 position: GPUArray[Vec3f, VertexBuffer]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
55 color: GPUArray[Vec4f, VertexBuffer]
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
56
1251
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
57 var gltfData = LoadMeshes[Mesh, Material](
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
58 "town.glb",
1248
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
59 MeshAttributeNames(
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
60 POSITION: "position",
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
61 COLOR: @["color"],
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
62 TEXCOORD: @["uv"],
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
63 ),
1248
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
64 MaterialAttributeNames(
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
65 baseColorFactor: "color",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
66 baseColorTexture: "colorTexture",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
67 metallicFactor: "metallic",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
68 roughnessFactor: "roughness",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
69 metallicRoughnessTexture: "metallicRoughnessTexture",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
70 normalTexture: "normalTexture",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
71 occlusionTexture: "occlusionTexture",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
72 emissiveTexture: "emissiveTexture",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
73 emissiveFactor: "emissive",
317bb5a73606 did: continue on gltf importer
sam <sam@basx.dev>
parents: 1247
diff changeset
74 )
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
75 )
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
76 var descriptors = asDescriptorSet(
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
77 MainDescriptors(
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
78 camera: asGPUValue(Camera(
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
79 viewPerspective: Unit4,
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
80 ), UniformBufferMapped)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
81 )
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
82 )
1251
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
83 for mesh in mitems(gltfData.meshes):
1249
d83726af7abb did: first triangles getting loaded from gltf
sam <sam@basx.dev>
parents: 1248
diff changeset
84 for primitive in mitems(mesh):
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
85 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
86 renderdata.AssignBuffers(primitive[0])
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
87 renderdata.AssignBuffers(descriptors)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
88
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
89 let O = default(Vec3f)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
90 let Gray = NewVec4f(0.5, 0.5, 0.5, 1)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
91 var gridPos = @[O, X, O, Y, O, Z]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
92 var gridColor = @[R, R, G, G, B, B]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
93 for i in 0 ..< 10:
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
94 gridPos.add [NewVec3f(-5, -0.001, i.float32 - 5), NewVec3f(5, -0.001, i.float32 - 5)]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
95 gridPos.add [NewVec3f(i.float32 - 5, -0.001, -5), NewVec3f(i.float32 - 5, -0.001, 5)]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
96 gridColor.add [Gray, Gray, Gray, Gray]
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
97 var grid = DebugMesh(
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
98 position: asGPUArray(gridPos, VertexBuffer),
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
99 color: asGPUArray(gridColor, VertexBuffer),
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
100 )
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
101 renderdata.AssignBuffers(grid)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
102
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
103 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, cullMode = [])
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
104 var debugpipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST, lineWidth=10)
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
105 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors)
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
106
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
107 renderdata.FlushAllMemory()
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
108
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
109 proc drawNode(commandbuffer: VkCommandBuffer, pipeline: Pipeline, nodeId: int,
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
110 transform: Mat4 = Unit4) =
1251
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
111 let nodeTransform = gltfData.nodes[nodeId].transform * transform
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
112 if gltfData.nodes[nodeId].mesh >= 0:
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
113 for primitive in gltfData.meshes[gltfData.nodes[nodeId].mesh]:
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
114 RenderWithPushConstant(
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
115 commandbuffer = commandbuffer,
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
116 pipeline = pipeline,
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
117 mesh = primitive[0],
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
118 pushConstant = ObjectData(transform: nodeTransform)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
119 )
1251
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
120 for childNode in gltfData.nodes[nodeId].children:
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
121 drawNode(commandbuffer = commandbuffer, pipeline = pipeline, nodeId = childNode, transform = nodeTransform)
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
122
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
123 var camPos: Vec3f
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
124 var camYaw: float32
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
125 var camPitch: float32
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
126
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
127 discard UpdateInputs() # clear inputs, otherwise MouseMove will have stuff
1251
3f98ad20a9d3 add: render by-node instead of by-mesh
sam <sam@basx.dev>
parents: 1249
diff changeset
128
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
129 var start = getMonoTime()
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
130 var lastT = getMonoTime()
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
131 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time and UpdateInputs():
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
132 let dt = ((getMonoTime() - lastT).inNanoseconds().int / 1_000_000_000).float32
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
133 lastT = getMonoTime()
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
134
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
135 camYaw -= MouseMove().x / 1000
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
136 camPitch -= MouseMove().y / 1000
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
137 var
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
138 forward = 0'f32
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
139 sideward = 0'f32
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
140 if KeyIsDown(W): forward += 2
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
141 if KeyIsDown(S): forward -= 2
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
142 if KeyIsDown(A): sideward -= 2
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
143 if KeyIsDown(D): sideward += 2
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
144
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
145 let camDir = (Rotate(camPitch, X) * Rotate(camYaw, Y)) * Z
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
146 echo camDir
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
147 let camDirSide = (Rotate(camPitch, X) * Rotate(camYaw, Y)) * X
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
148 # echo camDir
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
149 # echo camDirSide
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
150 camPos += camDir * forward * dt
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
151 camPos += camDirSide * sideward * dt
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
152
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
153 descriptors.data.camera.data.viewPerspective = (
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
154 Perspective(PI/3, aspect = GetAspectRatio(), zNear = 0.001, zFar = 100) *
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
155 Rotate(-camPitch, X) * Rotate(-camYaw, Y) * Translate(-camPos)
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
156 )
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
157
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
158 UpdateGPUBuffer(descriptors.data.camera)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
159
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
160 WithNextFrame(framebuffer, commandbuffer):
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
161
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
162 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
163
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
164 WithPipeline(commandbuffer, pipeline):
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
165 WithBind(commandbuffer, (descriptors, ), pipeline):
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
166 for nodeId in gltfData.scenes[0]:
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1251
diff changeset
167 drawNode(commandbuffer = commandbuffer, pipeline = pipeline, nodeId = nodeId)
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
168 WithBind(commandbuffer, (descriptors, ), pipeline):
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
169 WithPipeline(commandbuffer, debugpipeline):
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
170 Render(commandbuffer = commandbuffer, pipeline = debugpipeline, mesh = grid)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
171
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
172 # cleanup
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
173 checkVkResult vkDeviceWaitIdle(vulkan.device)
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
174 DestroyPipeline(pipeline)
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
175 DestroyPipeline(debugpipeline)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
176 DestroyRenderData(renderdata)
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
177 when isMainModule:
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
178 var time = 1000'f32
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
179 InitVulkan()
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
180
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
181 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
182 SetupSwapchain(renderpass = renderpass)
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1253
diff changeset
183 LockMouse(true)
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
184
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
185 # 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
186 test_gltf(time)
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 checkVkResult vkDeviceWaitIdle(vulkan.device)
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
189 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
190 ClearSwapchain()
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
191
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff changeset
192 DestroyVulkan()