Mercurial > games > semicongine
annotate tests/test_gltf.nim @ 1476:5d91e8328c3b
did: small fix for text-centering, add: timestamp to world-storage api
| author | sam <sam@basx.dev> |
|---|---|
| date | Sat, 19 Apr 2025 16:32:54 +0700 |
| parents | 96753bec055c |
| children |
| rev | line source |
|---|---|
|
1299
6d0162bfe48a
did: finish mentioned refactoring, no API changes still
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
1 import std/math |
|
1247
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 |
| 1267 | 7 import ../semicongine |
| 1427 | 8 import ../semicongine/rendering |
| 9 import ../semicongine/loaders | |
| 10 import ../semicongine/input | |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
11 import ../semicongine/gltf |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
12 |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
13 proc test_gltf(time: float32, renderPass: RenderPass) = |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
14 var renderdata = initRenderData() |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
15 |
|
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
16 type |
| 1253 | 17 ObjectData = object |
| 18 transform: Mat4 | |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
19 materialId: int32 |
| 1332 | 20 |
| 1253 | 21 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
|
22 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
|
23 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
|
24 projection: Mat4 |
| 1332 | 25 |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
26 Material = object |
|
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
27 color: Vec4f = vec4(1, 1, 1, 1) |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
28 # colorTexture: int32 = -1 |
| 1248 | 29 metallic: float32 = 0 |
| 30 roughness: float32 = 0 | |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
31 # metallicRoughnessTexture: int32 = -1 |
|
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
32 # normalTexture: int32 = -1 |
|
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
33 # occlusionTexture: int32 = -1 |
| 1332 | 34 emissive: Vec4f = vec4(0, 0, 0, 0) # emissiveTexture: int32 = -1 |
| 35 | |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
36 MainDescriptors = object |
|
1278
772bb32c4368
replcae lodepng with stb_image, some cleanup
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
37 materials: array[50, GPUValue[Material, UniformBuffer]] |
| 1253 | 38 camera: GPUValue[Camera, UniformBufferMapped] |
| 1332 | 39 |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
40 Shader = object |
| 1323 | 41 objectData {.PushConstant.}: ObjectData |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
42 position {.VertexAttribute.}: Vec3f |
| 1254 | 43 color {.VertexAttribute.}: Vec4f |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
44 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
|
45 fragmentPosition {.Pass.}: Vec3f |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
46 fragmentColor {.Pass.}: Vec4f |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
47 fragmentNormal {.Pass.}: Vec3f |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
48 outColor {.ShaderOutput.}: Vec4f |
| 1323 | 49 descriptors {.DescriptorSet: 0.}: MainDescriptors |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
50 # code |
| 1332 | 51 vertexCode: string = |
| 52 """ | |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 fragmentPosition = posTransformed.xyz / posTransformed.w; |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 }""" |
| 1332 | 62 fragmentCode: string = |
| 63 """ | |
|
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 // 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
|
69 const float lightPower = 20; |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
70 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
|
71 // 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 |
|
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
77 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
|
78 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
|
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 // 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 } |
|
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
87 |
|
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 |
|
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
92 outColor = vec4(color, fragmentColor.a); |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
93 }""" |
| 1332 | 94 |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
95 Mesh = object |
|
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
96 position: GPUArray[Vec3f, VertexBuffer] |
| 1254 | 97 color: GPUArray[Vec4f, VertexBuffer] |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
98 normal: GPUArray[Vec3f, VertexBuffer] |
|
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
99 indices: GPUArray[uint32, IndexBuffer] |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
100 |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
101 var gltfData = loadMeshes[Mesh, Material]( |
| 1259 | 102 "town.glb", |
| 103 # "forest.glb", | |
| 1248 | 104 MeshAttributeNames( |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
105 POSITION: "position", COLOR: @["color"], NORMAL: "normal", indices: "indices" |
| 1254 | 106 ), |
| 1248 | 107 MaterialAttributeNames( |
| 108 baseColorFactor: "color", | |
| 109 baseColorTexture: "colorTexture", | |
| 110 metallicFactor: "metallic", | |
| 111 roughnessFactor: "roughness", | |
| 112 metallicRoughnessTexture: "metallicRoughnessTexture", | |
| 113 normalTexture: "normalTexture", | |
| 114 occlusionTexture: "occlusionTexture", | |
| 115 emissiveTexture: "emissiveTexture", | |
| 116 emissiveFactor: "emissive", | |
| 1332 | 117 ), |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
118 ) |
| 1323 | 119 var descriptors = asDescriptorSetData( |
| 1253 | 120 MainDescriptors( |
| 1332 | 121 camera: asGPUValue( |
| 122 Camera(view: Unit4, normal: Unit4, projection: Unit4), UniformBufferMapped | |
| 123 ) | |
| 1254 | 124 ) |
| 1253 | 125 ) |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
126 for i in 0 ..< gltfData.materials.len: |
|
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
127 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer) |
| 1251 | 128 for mesh in mitems(gltfData.meshes): |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
129 for primitive in mitems(mesh.primitives): |
|
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
130 primitive.data.color = asGPUArray( |
|
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
131 newSeqWith(primitive.data.position.data.len, vec4(1, 1, 1, 1)), VertexBuffer |
| 1332 | 132 ) |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
133 renderdata.assignBuffers(primitive.data) |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
134 renderdata.assignBuffers(descriptors) |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
135 |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
136 var pipeline = createPipeline(Shader(), renderPass = renderPass, cullMode = []) |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
137 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) |
| 1254 | 138 |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
139 renderdata.flushAllMemory() |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
140 |
| 1332 | 141 proc drawNode( |
| 142 commandbuffer: VkCommandBuffer, pipeline: Pipeline, nodeId: int, transform: Mat4 | |
| 143 ) = | |
| 1251 | 144 let nodeTransform = gltfData.nodes[nodeId].transform * transform |
| 145 if gltfData.nodes[nodeId].mesh >= 0: | |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
146 for primitive in gltfData.meshes[gltfData.nodes[nodeId].mesh].primitives: |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
147 renderWithPushConstant( |
| 1254 | 148 commandbuffer = commandbuffer, |
| 149 pipeline = pipeline, | |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
150 mesh = primitive.data, |
| 1332 | 151 pushConstant = |
|
1448
96753bec055c
add: support for "name" and "extras" on gltf nodes
sam <sam@basx.dev>
parents:
1427
diff
changeset
|
152 ObjectData(transform: nodeTransform, materialId: primitive.material.int32), |
| 1254 | 153 ) |
| 1251 | 154 for childNode in gltfData.nodes[nodeId].children: |
| 1332 | 155 drawNode( |
| 156 commandbuffer = commandbuffer, | |
| 157 pipeline = pipeline, | |
| 158 nodeId = childNode, | |
| 159 transform = nodeTransform, | |
| 160 ) | |
| 1251 | 161 |
| 1254 | 162 var camPos: Vec3f |
| 163 var camYaw: float32 | |
| 164 var camPitch: float32 | |
| 165 | |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
166 discard updateInputs() # clear inputs, otherwise MouseMove will have stuff |
| 1251 | 167 |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
168 var start = getMonoTime() |
| 1254 | 169 var lastT = getMonoTime() |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
170 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time and updateInputs(): |
| 1254 | 171 let dt = ((getMonoTime() - lastT).inNanoseconds().int / 1_000_000_000).float32 |
| 172 lastT = getMonoTime() | |
| 173 | |
| 1332 | 174 camYaw += mouseMove().x.float32 / 1000'f32 |
| 1306 | 175 camPitch += mouseMove().y.float32 / 1000'f32 |
| 1254 | 176 var |
| 177 forward = 0'f32 | |
| 178 sideward = 0'f32 | |
| 1332 | 179 if keyIsDown(W): |
| 180 forward += 2 | |
| 181 if keyIsDown(S): | |
| 182 forward -= 2 | |
| 183 if keyIsDown(A): | |
| 184 sideward -= 2 | |
| 185 if keyIsDown(D): | |
| 186 sideward += 2 | |
| 1254 | 187 |
|
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
188 let camDir = (rotate(camYaw, Y) * rotate(camPitch, X)) * Z |
|
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
189 let camDirSide = camDir.cross(-Y).normalized |
| 1254 | 190 camPos += camDir * forward * dt |
| 191 camPos += camDirSide * sideward * dt | |
| 192 | |
|
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
193 let view = rotate(-camPitch, X) * rotate(-camYaw, Y) * translate(-camPos) |
|
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
194 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
|
195 descriptors.data.camera.data.normal = view |
| 1332 | 196 descriptors.data.camera.data.projection = |
| 197 projection(PI / 2, aspect = getAspectRatio(), zNear = 0.01, zFar = 20) | |
| 1254 | 198 |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
199 updateGPUBuffer(descriptors.data.camera) |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
200 |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
201 withNextFrame(framebuffer, commandbuffer): |
| 1332 | 202 withRenderPass( |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
203 renderPass, |
| 1332 | 204 framebuffer, |
| 205 commandbuffer, | |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
206 frameWidth(), |
|
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
207 frameHeight(), |
| 1332 | 208 vec4(0, 0, 0, 0), |
| 209 ): | |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
210 withPipeline(commandbuffer, pipeline): |
| 1323 | 211 bindDescriptorSet(commandbuffer, descriptors, 0, pipeline) |
| 212 for nodeId in gltfData.scenes[0]: | |
| 213 drawNode( | |
| 214 commandbuffer = commandbuffer, | |
| 215 pipeline = pipeline, | |
| 216 nodeId = nodeId, | |
| 1332 | 217 transform = rotate(PI / 2, Z), |
| 1323 | 218 ) |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
219 |
|
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
220 # cleanup |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
221 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
222 destroyPipeline(pipeline) |
|
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
223 destroyRenderData(renderdata) |
|
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
224 |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
225 when isMainModule: |
| 1254 | 226 var time = 1000'f32 |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
227 initEngine("Test glTF") |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
228 |
| 1332 | 229 var renderpass = createDirectPresentationRenderPass( |
| 230 depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT | |
| 231 ) | |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
232 setupSwapchain(renderpass = renderpass) |
|
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
233 lockMouse(true) |
|
1305
21c4e598d820
did: work on cursor issues, but now sync unfinished things to notebook
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
234 # showSystemCursor(false) |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
235 |
|
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
236 # tests a simple triangle with minimalistic shader and vertex format |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
237 test_gltf(time, renderpass) |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
238 |
|
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
239 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
|
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
240 destroyRenderPass(renderpass) |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
241 clearSwapchain() |
|
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
242 |
|
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
243 destroyVulkan() |
