Fixed glTF loading around norms and tex coordinates
This commit is contained in:
parent
c0d6d07e7e
commit
c3d27c5c86
@ -43,7 +43,7 @@ Model::Model(vk::PhysicalDevice phys_dev, vk::Device dev, const std::string& fna
|
|||||||
index_buffer = std::make_unique<Buffer>(phys_dev, dev, indices.size()*sizeof(uint16_t),
|
index_buffer = std::make_unique<Buffer>(phys_dev, dev, indices.size()*sizeof(uint16_t),
|
||||||
vk::BufferUsageFlagBits::eIndexBuffer, vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible);
|
vk::BufferUsageFlagBits::eIndexBuffer, vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible);
|
||||||
index_buffer->upload(reinterpret_cast<uint8_t*>(indices.data()), static_cast<vk::DeviceSize>(indices.size()*sizeof(uint16_t)));
|
index_buffer->upload(reinterpret_cast<uint8_t*>(indices.data()), static_cast<vk::DeviceSize>(indices.size()*sizeof(uint16_t)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::initVertices(Node* node, const tinygltf::Primitive& prim) {
|
void Model::initVertices(Node* node, const tinygltf::Primitive& prim) {
|
||||||
@ -74,7 +74,7 @@ void Model::initVertices(Node* node, const tinygltf::Primitive& prim) {
|
|||||||
if(loc != prim.attributes.end()) {
|
if(loc != prim.attributes.end()) {
|
||||||
auto accessor = model->accessors[loc->second];
|
auto accessor = model->accessors[loc->second];
|
||||||
const auto& view = model->bufferViews[accessor.bufferView];
|
const auto& view = model->bufferViews[accessor.bufferView];
|
||||||
norm_buff = reinterpret_cast<const float*>(&model->buffers[view.buffer].data[accessor.byteOffset+view.byteOffset]);
|
uv_buff = reinterpret_cast<const float*>(&model->buffers[view.buffer].data[accessor.byteOffset+view.byteOffset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i < vertex_count; i++) {
|
for(size_t i = 0; i < vertex_count; i++) {
|
||||||
|
|||||||
@ -199,6 +199,7 @@ Renderer::Renderer(Window& win) : win(win) {
|
|||||||
|
|
||||||
/* initialize models */
|
/* initialize models */
|
||||||
models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/dragon.gltf"));
|
models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/dragon.gltf"));
|
||||||
|
models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/monk.gltf"));
|
||||||
|
|
||||||
Log::debug("#%zu vertex indices\n", models[0]->indices.size());
|
Log::debug("#%zu vertex indices\n", models[0]->indices.size());
|
||||||
|
|
||||||
@ -326,6 +327,10 @@ void Renderer::draw() {
|
|||||||
//command_buffer->draw(std::size(triangle), 1, 0, 0);
|
//command_buffer->draw(std::size(triangle), 1, 0, 0);
|
||||||
command_buffer->command_buffer.drawIndexed(models[0]->indices.size(), 1, 0, 0, 0);
|
command_buffer->command_buffer.drawIndexed(models[0]->indices.size(), 1, 0, 0, 0);
|
||||||
|
|
||||||
|
command_buffer->bind(*models[1]->vertex_buffer);
|
||||||
|
command_buffer->command_buffer.bindIndexBuffer(*models[1]->index_buffer, 0, vk::IndexType::eUint16);
|
||||||
|
command_buffer->command_buffer.drawIndexed(models[1]->indices.size(), 1, 0, 0, 0);
|
||||||
|
|
||||||
command_buffer->command_buffer.endRenderPass();
|
command_buffer->command_buffer.endRenderPass();
|
||||||
|
|
||||||
command_buffer->end();
|
command_buffer->end();
|
||||||
|
|||||||
BIN
assets/models/monk.bin
Normal file
BIN
assets/models/monk.bin
Normal file
Binary file not shown.
219
assets/models/monk.gltf
Normal file
219
assets/models/monk.gltf
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
{
|
||||||
|
"asset":{
|
||||||
|
"generator":"Khronos glTF Blender I/O v4.0.44",
|
||||||
|
"version":"2.0"
|
||||||
|
},
|
||||||
|
"scene":0,
|
||||||
|
"scenes":[
|
||||||
|
{
|
||||||
|
"name":"Scene",
|
||||||
|
"nodes":[
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nodes":[
|
||||||
|
{
|
||||||
|
"mesh":0,
|
||||||
|
"name":"Suzanne",
|
||||||
|
"rotation":[
|
||||||
|
0.06356222927570343,
|
||||||
|
0.536848247051239,
|
||||||
|
-0.8056020140647888,
|
||||||
|
0.2424030303955078
|
||||||
|
],
|
||||||
|
"translation":[
|
||||||
|
0.1063065230846405,
|
||||||
|
-0.6601571440696716,
|
||||||
|
-0.6140139698982239
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mesh":1,
|
||||||
|
"name":"Cube",
|
||||||
|
"rotation":[
|
||||||
|
0.1050531193614006,
|
||||||
|
-0.23102691769599915,
|
||||||
|
-0.3264787197113037,
|
||||||
|
0.9104955196380615
|
||||||
|
],
|
||||||
|
"scale":[
|
||||||
|
0.6794998645782471,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"materials":[
|
||||||
|
{
|
||||||
|
"doubleSided":true,
|
||||||
|
"name":"Material",
|
||||||
|
"pbrMetallicRoughness":{
|
||||||
|
"baseColorFactor":[
|
||||||
|
0.800000011920929,
|
||||||
|
0.800000011920929,
|
||||||
|
0.800000011920929,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"metallicFactor":0,
|
||||||
|
"roughnessFactor":0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"meshes":[
|
||||||
|
{
|
||||||
|
"name":"Suzanne",
|
||||||
|
"primitives":[
|
||||||
|
{
|
||||||
|
"attributes":{
|
||||||
|
"POSITION":0,
|
||||||
|
"NORMAL":1,
|
||||||
|
"TEXCOORD_0":2
|
||||||
|
},
|
||||||
|
"indices":3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"Cube",
|
||||||
|
"primitives":[
|
||||||
|
{
|
||||||
|
"attributes":{
|
||||||
|
"POSITION":4,
|
||||||
|
"NORMAL":5,
|
||||||
|
"TEXCOORD_0":6
|
||||||
|
},
|
||||||
|
"indices":7,
|
||||||
|
"material":0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"accessors":[
|
||||||
|
{
|
||||||
|
"bufferView":0,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"max":[
|
||||||
|
1.3671875,
|
||||||
|
0.984375,
|
||||||
|
0.8515625
|
||||||
|
],
|
||||||
|
"min":[
|
||||||
|
-1.3671875,
|
||||||
|
-0.984375,
|
||||||
|
-0.8515625
|
||||||
|
],
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":1,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":2,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"type":"VEC2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":3,
|
||||||
|
"componentType":5123,
|
||||||
|
"count":2904,
|
||||||
|
"type":"SCALAR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":4,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"max":[
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"min":[
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
-1
|
||||||
|
],
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":5,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":6,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"type":"VEC2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":7,
|
||||||
|
"componentType":5123,
|
||||||
|
"count":36,
|
||||||
|
"type":"SCALAR"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bufferViews":[
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":23640,
|
||||||
|
"byteOffset":0,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":23640,
|
||||||
|
"byteOffset":23640,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":15760,
|
||||||
|
"byteOffset":47280,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":5808,
|
||||||
|
"byteOffset":63040,
|
||||||
|
"target":34963
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":288,
|
||||||
|
"byteOffset":68848,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":288,
|
||||||
|
"byteOffset":69136,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":192,
|
||||||
|
"byteOffset":69424,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":72,
|
||||||
|
"byteOffset":69616,
|
||||||
|
"target":34963
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buffers":[
|
||||||
|
{
|
||||||
|
"byteLength":69688,
|
||||||
|
"uri":"monk.bin"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
assets/models/monkebox.bin
Normal file
BIN
assets/models/monkebox.bin
Normal file
Binary file not shown.
219
assets/models/monkebox.gltf
Normal file
219
assets/models/monkebox.gltf
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
{
|
||||||
|
"asset":{
|
||||||
|
"generator":"Khronos glTF Blender I/O v4.0.44",
|
||||||
|
"version":"2.0"
|
||||||
|
},
|
||||||
|
"scene":0,
|
||||||
|
"scenes":[
|
||||||
|
{
|
||||||
|
"name":"Scene",
|
||||||
|
"nodes":[
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nodes":[
|
||||||
|
{
|
||||||
|
"mesh":0,
|
||||||
|
"name":"Suzanne",
|
||||||
|
"rotation":[
|
||||||
|
0.06356222927570343,
|
||||||
|
0.536848247051239,
|
||||||
|
-0.8056020140647888,
|
||||||
|
0.2424030303955078
|
||||||
|
],
|
||||||
|
"translation":[
|
||||||
|
0.1063065230846405,
|
||||||
|
-0.6601571440696716,
|
||||||
|
-0.6140139698982239
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mesh":1,
|
||||||
|
"name":"Cube",
|
||||||
|
"rotation":[
|
||||||
|
0.1050531193614006,
|
||||||
|
-0.23102691769599915,
|
||||||
|
-0.3264787197113037,
|
||||||
|
0.9104955196380615
|
||||||
|
],
|
||||||
|
"scale":[
|
||||||
|
0.6794998645782471,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"materials":[
|
||||||
|
{
|
||||||
|
"doubleSided":true,
|
||||||
|
"name":"Material",
|
||||||
|
"pbrMetallicRoughness":{
|
||||||
|
"baseColorFactor":[
|
||||||
|
0.800000011920929,
|
||||||
|
0.800000011920929,
|
||||||
|
0.800000011920929,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"metallicFactor":0,
|
||||||
|
"roughnessFactor":0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"meshes":[
|
||||||
|
{
|
||||||
|
"name":"Suzanne",
|
||||||
|
"primitives":[
|
||||||
|
{
|
||||||
|
"attributes":{
|
||||||
|
"POSITION":0,
|
||||||
|
"NORMAL":1,
|
||||||
|
"TEXCOORD_0":2
|
||||||
|
},
|
||||||
|
"indices":3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"Cube",
|
||||||
|
"primitives":[
|
||||||
|
{
|
||||||
|
"attributes":{
|
||||||
|
"POSITION":4,
|
||||||
|
"NORMAL":5,
|
||||||
|
"TEXCOORD_0":6
|
||||||
|
},
|
||||||
|
"indices":7,
|
||||||
|
"material":0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"accessors":[
|
||||||
|
{
|
||||||
|
"bufferView":0,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"max":[
|
||||||
|
1.3671875,
|
||||||
|
0.984375,
|
||||||
|
0.8515625
|
||||||
|
],
|
||||||
|
"min":[
|
||||||
|
-1.3671875,
|
||||||
|
-0.984375,
|
||||||
|
-0.8515625
|
||||||
|
],
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":1,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":2,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":1970,
|
||||||
|
"type":"VEC2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":3,
|
||||||
|
"componentType":5123,
|
||||||
|
"count":2904,
|
||||||
|
"type":"SCALAR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":4,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"max":[
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"min":[
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
-1
|
||||||
|
],
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":5,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"type":"VEC3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":6,
|
||||||
|
"componentType":5126,
|
||||||
|
"count":24,
|
||||||
|
"type":"VEC2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bufferView":7,
|
||||||
|
"componentType":5123,
|
||||||
|
"count":36,
|
||||||
|
"type":"SCALAR"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bufferViews":[
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":23640,
|
||||||
|
"byteOffset":0,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":23640,
|
||||||
|
"byteOffset":23640,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":15760,
|
||||||
|
"byteOffset":47280,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":5808,
|
||||||
|
"byteOffset":63040,
|
||||||
|
"target":34963
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":288,
|
||||||
|
"byteOffset":68848,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":288,
|
||||||
|
"byteOffset":69136,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":192,
|
||||||
|
"byteOffset":69424,
|
||||||
|
"target":34962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buffer":0,
|
||||||
|
"byteLength":72,
|
||||||
|
"byteOffset":69616,
|
||||||
|
"target":34963
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buffers":[
|
||||||
|
{
|
||||||
|
"byteLength":69688,
|
||||||
|
"uri":"monkebox.bin"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@ layout (location = 1) in vec2 texCoord;
|
|||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 mpv;
|
mat4 mvp;
|
||||||
float time;
|
float time;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -13,5 +13,6 @@ layout (set = 0, binding = 1) uniform sampler2D tex;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
//FragColor = vec4(1.0);
|
//FragColor = vec4(1.0);
|
||||||
|
// FragColor = texture(tex, texCoord);
|
||||||
FragColor = vec4(norm, 1.0);
|
FragColor = vec4(norm, 1.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -7,12 +7,12 @@ layout (location = 0) out vec3 norm;
|
|||||||
layout (location = 1) out vec2 texCoord;
|
layout (location = 1) out vec2 texCoord;
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 mpv;
|
mat4 mvp;
|
||||||
float time;
|
float time;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = mpv * vec4(aPos - vec3(0.0, 0.0, 3.0) * time/3.0, 1.0);
|
gl_Position = mvp * vec4(aPos - vec3(0.0, 0.0, 3.0) * time/3.0, 1.0);
|
||||||
texCoord = aTexCoord;
|
texCoord = aTexCoord;
|
||||||
norm = aNorm;
|
norm = aNorm;
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -1,10 +1,11 @@
|
|||||||
#version 460 core
|
#version 460 core
|
||||||
|
|
||||||
layout (location = 0) in vec2 texCoord;
|
layout (location = 0) in vec3 norm;
|
||||||
|
layout (location = 1) in vec2 texCoord;
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 mpv;
|
mat4 mvp;
|
||||||
float time;
|
float time;
|
||||||
float aspect_ratio;
|
float aspect_ratio;
|
||||||
};
|
};
|
||||||
@ -50,6 +51,9 @@ void main() {
|
|||||||
|
|
||||||
float d = sphere(sphere_center, 0.5, ray);
|
float d = sphere(sphere_center, 0.5, ray);
|
||||||
|
|
||||||
|
FragColor = vec4(texCoord, 1.0, 1.0);
|
||||||
|
return;
|
||||||
|
|
||||||
if(d < 0.0) {
|
if(d < 0.0) {
|
||||||
FragColor = vec4(0.0);
|
FragColor = vec4(0.0);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user