diff --git a/samples/03_model_render/model_render.cpp b/samples/03_model_render/model_render.cpp index d5880c7..6c2f77a 100644 --- a/samples/03_model_render/model_render.cpp +++ b/samples/03_model_render/model_render.cpp @@ -29,23 +29,8 @@ constexpr u32 MAX_FRAMES_IN_FLIGHT = 3; constexpr auto MODEL_FILE = "model/OrientationTest.glb"; -struct ImageFile -{ - u8 *m_Data = nullptr; - u32 m_Width = 0; - u32 m_Height = 0; - u32 m_NumChannels = 0; - bool m_Constant = false; - - bool Load(cstr fileName); - bool Load(vec4 color); - [[nodiscard]] usize GetSize() const; - ~ImageFile(); -}; - struct Camera { - mat4 m_Model; mat4 m_View; mat4 m_Perspective; }; @@ -94,7 +79,6 @@ main(int, char **) Pipeline pipeline = CreatePipeline(&device, &swapchain, &resourceManager); Camera camera = { - .m_Model = {1.0f}, .m_View = glm::lookAt(vec3(0.0f, 12.0f, 12.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)), .m_Perspective = glm::perspective( 70_deg, Cast(swapchain.m_Extent.width) / Cast(swapchain.m_Extent.height), 0.1f, 100.0f), @@ -326,65 +310,3 @@ main(int, char **) return 0; } - -bool -ImageFile::Load(vec4 color) -{ - constexpr usize size = 512llu * 512llu * 4llu; - u8 *pData = new u8[size]; - - const vec4 color255 = 255.999f * color; - const glm::vec<4, u8> color8 = color255; - - for (usize i = 0; i < size; i += 4) - { - memcpy(pData + i, &color8, sizeof color8); - } - - m_Data = pData; - m_Constant = true; - m_Height = 512; - m_Width = 512; - m_NumChannels = 4; - - return true; -} - -bool -ImageFile::Load(cstr fileName) -{ - int width, height, nrChannels; - m_Data = stbi_load(fileName, &width, &height, &nrChannels, 4); - ERROR_IF(!m_Data, "Could not load {}", fileName); - - if (!m_Data) - { - return false; - } - - m_Width = width; - m_Height = height; - m_NumChannels = 4; - m_Constant = false; - - return true; -} - -usize -ImageFile::GetSize() const -{ - return Cast(m_Width) * m_Height * m_NumChannels; -} - -ImageFile::~ImageFile() -{ - if (m_Constant) - { - delete[] Cast(m_Data); - } - else - { - stbi_image_free(m_Data); - } - m_Data = nullptr; -} \ No newline at end of file diff --git a/samples/03_model_render/shader/bindless_structs.hlsli b/samples/03_model_render/shader/bindless_structs.hlsli index 4f4a5b0..fe8925b 100644 --- a/samples/03_model_render/shader/bindless_structs.hlsli +++ b/samples/03_model_render/shader/bindless_structs.hlsli @@ -1,9 +1,4 @@ -typedef float4 PositionData; -typedef float2 UVData; -typedef float4 NormalData; -typedef float4 ColorData; - struct VertexData { float4 m_Normal; @@ -42,14 +37,13 @@ struct Block struct Camera { - float4x4 model; float4x4 view; float4x4 proj; }; #define INVALID_HANDLE 0xFFFFFFFF -[[vk::binding(0, 0)]] StructuredBuffer vertexBuffer[]; +[[vk::binding(0, 0)]] StructuredBuffer vertexBuffer[]; [[vk::binding(0, 0)]] StructuredBuffer vertexDataBuffer[]; [[vk::binding(0, 0)]] StructuredBuffer materialsBuffer[]; [[vk::binding(0, 0)]] StructuredBuffer nodeBuffer[]; diff --git a/samples/03_model_render/shader/model.ps.hlsl b/samples/03_model_render/shader/model.ps.hlsl index 9a5caee..68138c6 100644 --- a/samples/03_model_render/shader/model.ps.hlsl +++ b/samples/03_model_render/shader/model.ps.hlsl @@ -17,12 +17,17 @@ float4 ArrayToVector(float arr[4]) return float4(arr[0], arr[1], arr[2], arr[3]); } +float4 ArrayToVector(float4 arr) +{ + return arr; +} + float4 GetAlbedo(uint materialBufferId, int materialId, float2 uv) { uint albedoTexId = materialsBuffer[materialBufferId][materialId].m_AlbedoTex; if (albedoTexId == INVALID_HANDLE) { - return ArrayToVector(materialsBuffer[materialBufferId][materialId].m_AlbedoFactor); + return (float4) materialsBuffer[materialBufferId][materialId].m_AlbedoFactor; } else { diff --git a/samples/03_model_render/shader/model.vs.hlsl b/samples/03_model_render/shader/model.vs.hlsl index 2de5a59..701b38f 100644 --- a/samples/03_model_render/shader/model.vs.hlsl +++ b/samples/03_model_render/shader/model.vs.hlsl @@ -13,34 +13,38 @@ struct VS_Output float4 position : SV_Position; }; -float2 GetUV(uint bufferId, uint vertexIdx) +float2 GetUV(uint vertexIdx) { - return (bufferId == INVALID_HANDLE) ? 0.0f.xx : vertexDataBuffer[bufferId][vertexIdx].m_TexCoord0.xy; + uint bufferId = pcb.vertexDataHandle; + return vertexDataBuffer[bufferId][vertexIdx].m_TexCoord0.xy; } -float4 GetPosition(uint bufferId, uint vertexIdx) +float4 GetPosition(uint vertexIdx) { + uint bufferId = pcb.vertexBufferHandle; return float4(vertexBuffer[bufferId][vertexIdx].xyz, 1.0f); } -float4 GetColor(uint bufferId, uint vertexIdx) +float4 GetColor(uint vertexIdx) { - return (bufferId == INVALID_HANDLE) ? float4(1.0f, 0.0f, 1.0f, 1.0f) : vertexDataBuffer[bufferId][vertexIdx].m_Color0; + uint bufferId = pcb.vertexDataHandle; + return vertexDataBuffer[bufferId][vertexIdx].m_Color0; } -float4x4 GetModel(uint bufferId, uint index) +float4x4 GetModel(uint index) { + uint bufferId = pcb.nodeBufferHandle; return nodeBuffer[bufferId][index].transform; } VS_Output main(VS_Input stage_input) { VS_Output output; - output.outPosition = GetPosition(pcb.vertexBufferHandle, stage_input.vertexIndex); - output.outUV = GetUV(pcb.vertexDataHandle, stage_input.vertexIndex); - output.outColor = GetColor(pcb.vertexDataHandle, stage_input.vertexIndex); + output.outPosition = GetPosition(stage_input.vertexIndex); + output.outUV = GetUV(stage_input.vertexIndex); + output.outColor = GetColor(stage_input.vertexIndex); - float4 globalPosition = mul(camera.model, mul(GetModel(pcb.nodeBufferHandle, pcb.m_NodeIdx), GetPosition(pcb.vertexBufferHandle, stage_input.vertexIndex))); + float4 globalPosition = mul(GetModel(pcb.m_NodeIdx), GetPosition(stage_input.vertexIndex)); float4 clipSpace = mul(camera.view, globalPosition); output.position = mul(camera.proj, clipSpace); return output;