Mercurial > games > semicongine
annotate tests/test_gltf.nim @ 1315:27395a38d882
add: support for int8 vectors
author | sam <sam@basx.dev> |
---|---|
date | Sun, 11 Aug 2024 19:24:47 +0700 |
parents | 7be3628298f5 |
children | 385dbd68a947 |
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 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
8 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
9 proc test_gltf(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
10 var renderdata = initRenderData() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
12 type |
1253 | 13 ObjectData = object |
14 transform: Mat4 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
15 materialId: int32 |
1253 | 16 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
|
17 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
|
18 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
|
19 projection: Mat4 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
20 Material = object |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
21 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
|
22 # colorTexture: int32 = -1 |
1248 | 23 metallic: float32 = 0 |
24 roughness: float32 = 0 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
25 # metallicRoughnessTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
26 # normalTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
27 # occlusionTexture: int32 = -1 |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
28 emissive: Vec4f = vec4(0, 0, 0, 0) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
29 # emissiveTexture: int32 = -1 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
30 MainDescriptors = object |
1278
772bb32c4368
replcae lodepng with stb_image, some cleanup
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
31 materials: array[50, GPUValue[Material, UniformBuffer]] |
1253 | 32 camera: GPUValue[Camera, UniformBufferMapped] |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
33 Shader = object |
1253 | 34 objectData {.PushConstantAttribute.}: ObjectData |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
35 position {.VertexAttribute.}: Vec3f |
1254 | 36 color {.VertexAttribute.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
37 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
|
38 fragmentPosition {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
39 fragmentColor {.Pass.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
40 fragmentNormal {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
41 outColor {.ShaderOutput.}: Vec4f |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
42 descriptors {.DescriptorSets.}: (MainDescriptors, ) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
43 # code |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
44 vertexCode: string = """ |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 fragmentPosition = posTransformed.xyz / posTransformed.w; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 }""" |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 // 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
|
60 const float lightPower = 20; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
61 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
|
62 // 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
68 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
|
69 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
|
70 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
71 // 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 } |
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 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
|
80 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
|
81 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
|
82 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
83 outColor = vec4(color, fragmentColor.a); |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
84 }""" |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
85 Mesh = object |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
86 position: GPUArray[Vec3f, VertexBuffer] |
1254 | 87 color: GPUArray[Vec4f, VertexBuffer] |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
88 normal: GPUArray[Vec3f, VertexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
89 indices: GPUArray[uint32, IndexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
90 material: int32 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
91 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
92 var gltfData = loadMeshes[Mesh, Material]( |
1259 | 93 "town.glb", |
94 # "forest.glb", | |
1248 | 95 MeshAttributeNames( |
96 POSITION: "position", | |
1254 | 97 COLOR: @["color"], |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
98 NORMAL: "normal", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
99 indices: "indices", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
100 material: "material", |
1254 | 101 ), |
1248 | 102 MaterialAttributeNames( |
103 baseColorFactor: "color", | |
104 baseColorTexture: "colorTexture", | |
105 metallicFactor: "metallic", | |
106 roughnessFactor: "roughness", | |
107 metallicRoughnessTexture: "metallicRoughnessTexture", | |
108 normalTexture: "normalTexture", | |
109 occlusionTexture: "occlusionTexture", | |
110 emissiveTexture: "emissiveTexture", | |
111 emissiveFactor: "emissive", | |
112 ) | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
113 ) |
1253 | 114 var descriptors = asDescriptorSet( |
115 MainDescriptors( | |
116 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
|
117 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
|
118 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
|
119 projection: Unit4, |
1254 | 120 ), UniformBufferMapped) |
121 ) | |
1253 | 122 ) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
123 for i in 0 ..< gltfData.materials.len: |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
124 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer) |
1251 | 125 for mesh in mitems(gltfData.meshes): |
1249
d83726af7abb
did: first triangles getting loaded from gltf
sam <sam@basx.dev>
parents:
1248
diff
changeset
|
126 for primitive in mitems(mesh): |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
127 primitive[0].color = asGPUArray(newSeqWith(primitive[0].position.data.len, vec4(1, 1, 1, 1)), VertexBuffer) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
128 renderdata.assignBuffers(primitive[0]) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
129 renderdata.assignBuffers(descriptors) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
130 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
131 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass, cullMode=[]) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
132 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) |
1254 | 133 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
134 renderdata.flushAllMemory() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
135 |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
136 proc drawNode(commandbuffer: VkCommandBuffer, pipeline: Pipeline, nodeId: int, transform: Mat4) = |
1251 | 137 let nodeTransform = gltfData.nodes[nodeId].transform * transform |
138 if gltfData.nodes[nodeId].mesh >= 0: | |
139 for primitive in gltfData.meshes[gltfData.nodes[nodeId].mesh]: | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
140 renderWithPushConstant( |
1254 | 141 commandbuffer = commandbuffer, |
142 pipeline = pipeline, | |
143 mesh = primitive[0], | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
144 pushConstant = ObjectData(transform: nodeTransform, materialId: primitive[0].material) |
1254 | 145 ) |
1251 | 146 for childNode in gltfData.nodes[nodeId].children: |
147 drawNode(commandbuffer = commandbuffer, pipeline = pipeline, nodeId = childNode, transform = nodeTransform) | |
148 | |
1254 | 149 var camPos: Vec3f |
150 var camYaw: float32 | |
151 var camPitch: float32 | |
152 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
153 discard updateInputs() # clear inputs, otherwise MouseMove will have stuff |
1251 | 154 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
155 var start = getMonoTime() |
1254 | 156 var lastT = getMonoTime() |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
157 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time and updateInputs(): |
1254 | 158 let dt = ((getMonoTime() - lastT).inNanoseconds().int / 1_000_000_000).float32 |
159 lastT = getMonoTime() | |
160 | |
1306 | 161 camYaw += mouseMove().x.float32 / 1000'f32 |
162 camPitch += mouseMove().y.float32 / 1000'f32 | |
1254 | 163 var |
164 forward = 0'f32 | |
165 sideward = 0'f32 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
166 if keyIsDown(W): forward += 2 |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
167 if keyIsDown(S): forward -= 2 |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
168 if keyIsDown(A): sideward -= 2 |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
169 if keyIsDown(D): sideward += 2 |
1254 | 170 |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
171 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
|
172 let camDirSide = camDir.cross(-Y).normalized |
1254 | 173 camPos += camDir * forward * dt |
174 camPos += camDirSide * sideward * dt | |
175 | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
176 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
|
177 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
|
178 descriptors.data.camera.data.normal = view |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
179 descriptors.data.camera.data.projection = projection(PI / 2, aspect = getAspectRatio(), zNear = 0.01, zFar = 20) |
1254 | 180 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
181 updateGPUBuffer(descriptors.data.camera) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
182 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
183 withNextFrame(framebuffer, commandbuffer): |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
184 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
185 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
186 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
187 withPipeline(commandbuffer, pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
188 withBind(commandbuffer, (descriptors, ), pipeline): |
1253 | 189 for nodeId in gltfData.scenes[0]: |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
190 drawNode( |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
191 commandbuffer = commandbuffer, |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
192 pipeline = pipeline, |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
193 nodeId = nodeId, |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
194 transform = rotate(PI / 2, Z) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
195 ) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
196 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
197 # cleanup |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
198 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
199 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
200 destroyRenderData(renderdata) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
201 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
202 when isMainModule: |
1254 | 203 var time = 1000'f32 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
204 initVulkan() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
205 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
206 var renderpass = createDirectPresentationRenderPass(depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
207 setupSwapchain(renderpass = renderpass) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
208 lockMouse(true) |
1305
21c4e598d820
did: work on cursor issues, but now sync unfinished things to notebook
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
209 # showSystemCursor(false) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
210 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
211 # 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
|
212 test_gltf(time) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
213 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
214 checkVkResult vkDeviceWaitIdle(vulkan.device) |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
215 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
216 clearSwapchain() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
217 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
218 destroyVulkan() |