From 2eb22f8debec811cdea32ed7b8cf3ec98c752f7c Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 14 Sep 2023 19:24:43 -0400 Subject: Load model textures checkpoint. Refactors some Vulkan items related to CompGrBinds and EntityTypes. Adds some Vulkan globals related to textures. Adds a number of placeholder items: - Iffy use of setting Vulkan globals on instanced structs. - Unimplemented and inaccurate shaders - Iffy gltf sub-buffer logic (ignores vertex color data) - MipMap TODOs - TextureArray TODOs --- assets/models/cube.bin | Bin 840 -> 1224 bytes assets/models/cube.gltf | 69 +++++++++++++++++++++++++++++++------------- assets/models/cube.png | Bin 0 -> 182802 bytes assets/shaders/texture.frag | 16 ++++++++++ assets/shaders/vert.vert | 32 ++++++++++++++++++++ 5 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 assets/models/cube.png create mode 100644 assets/shaders/texture.frag create mode 100644 assets/shaders/vert.vert (limited to 'assets') diff --git a/assets/models/cube.bin b/assets/models/cube.bin index c59221c..6223cf0 100644 Binary files a/assets/models/cube.bin and b/assets/models/cube.bin differ diff --git a/assets/models/cube.gltf b/assets/models/cube.gltf index 5077394..9bc8a22 100644 --- a/assets/models/cube.gltf +++ b/assets/models/cube.gltf @@ -21,14 +21,11 @@ "materials":[ { "doubleSided":true, - "name":"Material", + "name":"Material.001", "pbrMetallicRoughness":{ - "baseColorFactor":[ - 0.800000011920929, - 0.800000011920929, - 0.800000011920929, - 1 - ], + "baseColorTexture":{ + "index":0 + }, "metallicFactor":0, "roughnessFactor":0.5 } @@ -36,25 +33,45 @@ ], "meshes":[ { - "name":"Cube", + "name":"Cube.001", "primitives":[ { "attributes":{ - "POSITION":0, - "NORMAL":1, - "TEXCOORD_0":2 + "COLOR_0":0, + "POSITION":1, + "NORMAL":2, + "TEXCOORD_0":3 }, - "indices":3, + "indices":4, "material":0 } ] } ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"cube", + "uri":"cube.png" + } + ], "accessors":[ { "bufferView":0, "componentType":5126, "count":24, + "type":"VEC4" + }, + { + "bufferView":1, + "componentType":5126, + "count":24, "max":[ 1, 1, @@ -68,19 +85,19 @@ "type":"VEC3" }, { - "bufferView":1, + "bufferView":2, "componentType":5126, "count":24, "type":"VEC3" }, { - "bufferView":2, + "bufferView":3, "componentType":5126, "count":24, "type":"VEC2" }, { - "bufferView":3, + "bufferView":4, "componentType":5123, "count":36, "type":"SCALAR" @@ -89,32 +106,44 @@ "bufferViews":[ { "buffer":0, - "byteLength":288, + "byteLength":384, "byteOffset":0, "target":34962 }, { "buffer":0, "byteLength":288, - "byteOffset":288, + "byteOffset":384, + "target":34962 + }, + { + "buffer":0, + "byteLength":288, + "byteOffset":672, "target":34962 }, { "buffer":0, "byteLength":192, - "byteOffset":576, + "byteOffset":960, "target":34962 }, { "buffer":0, "byteLength":72, - "byteOffset":768, + "byteOffset":1152, "target":34963 } ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], "buffers":[ { - "byteLength":840, + "byteLength":1224, "uri":"cube.bin" } ] diff --git a/assets/models/cube.png b/assets/models/cube.png new file mode 100644 index 0000000..74a7e29 Binary files /dev/null and b/assets/models/cube.png differ diff --git a/assets/shaders/texture.frag b/assets/shaders/texture.frag new file mode 100644 index 0000000..e63995f --- /dev/null +++ b/assets/shaders/texture.frag @@ -0,0 +1,16 @@ +# version 450 + +layout(location = 0) in vec3 fragColor; +layout(location = 1) in vec3 fragTexCoord; + +layout(location = 0) out vec4 outColor; + +layout(binding = 1) uniform sampler2D texSampler; + +void main() { + vec4 color = texture(texSampler, fragTexCoord.xy); + if (color.w == 0) { + discard; + } + outColor = color; +} diff --git a/assets/shaders/vert.vert b/assets/shaders/vert.vert new file mode 100644 index 0000000..f3e7cf2 --- /dev/null +++ b/assets/shaders/vert.vert @@ -0,0 +1,32 @@ +#version 450 + +layout(binding = 0) uniform UniformBufferObject { + mat4 model; + mat4 view; + mat4 proj; +} ubo; + +// vertex +layout(location = 0) in vec4 inColor; +layout(location = 1) in vec3 inPosition; +layout(location = 2) in vec3 inNorm; +layout(location = 3) in vec2 inTexCoord; + +// instance +layout(location = 4) in mat4 instPosRotScale; +layout(location = 8) in float textureIndex; + +// output +layout(location = 0) out vec3 fragColor; +layout(location = 1) out vec3 fragTexCoord; + +void main() { + gl_Position = + ubo.proj * + ubo.view * + ubo.model * + instPosRotScale * + vec4(inPosition, 1.0); + fragColor = inColor; + fragTexCoord = vec3(inTexCoord, textureIndex); +} -- cgit v1.2.3