Fixed bug in Model Loading.
Model Loader was loading indexes into image instead of going via texture. TODO: Textures also have samplers.
This commit is contained in:
parent
b8b620a723
commit
668189acb5
|
|
@ -367,14 +367,21 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref<Texture> &texture, vk
|
|||
#endif
|
||||
}
|
||||
|
||||
std::tuple<systems::ResId<TextureView>, Ref<Buffer>>
|
||||
AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const
|
||||
std::tuple<systems::ResId<TextureView>, Ref<StagingBuffer>>
|
||||
AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) const
|
||||
{
|
||||
// TODO(Something not loading properly).
|
||||
|
||||
assert(image->component == 4);
|
||||
assert(image->height > 0 && image->width > 0);
|
||||
|
||||
#if !defined(ASTER_NDEBUG)
|
||||
auto assignedName = name ? name : image->name.empty() ? image->uri.c_str() : image->name.c_str();
|
||||
#else
|
||||
auto assignedName = nullptr;
|
||||
#endif
|
||||
|
||||
|
||||
u32 height = Cast<u32>(image->height);
|
||||
u32 width = Cast<u32>(image->width);
|
||||
|
||||
|
|
@ -384,7 +391,7 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const
|
|||
auto texture = m_ResourceManager->Images().CreateTexture2D<Texture>({
|
||||
.m_Format = imageFormat,
|
||||
.m_Extent = {width, height},
|
||||
.m_Name = image->name.c_str(),
|
||||
.m_Name = assignedName,
|
||||
.m_IsSampled = true,
|
||||
.m_IsMipMapped = true,
|
||||
.m_IsStorage = false,
|
||||
|
|
@ -395,7 +402,7 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const
|
|||
|
||||
#if !defined(ASTER_NDEBUG)
|
||||
StackString<128> loadActionName = "Load: ";
|
||||
loadActionName += image->name.empty() ? "<texture>" : image->name.c_str();
|
||||
loadActionName += assignedName;
|
||||
vk::DebugUtilsLabelEXT debugLabel = {
|
||||
.pLabelName = loadActionName.c_str(),
|
||||
.color = std::array{1.0f, 1.0f, 1.0f, 1.0f},
|
||||
|
|
@ -541,7 +548,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
|
|||
m_CommandBuffer.beginDebugUtilsLabelEXT(&debugLabel);
|
||||
#endif
|
||||
|
||||
eastl::vector<Ref<Buffer>> stagingBuffers;
|
||||
eastl::vector<Ref<StagingBuffer>> stagingBuffers;
|
||||
|
||||
eastl::hash_map<i32, systems::ResId<TextureView>> textureHandleMap;
|
||||
|
||||
|
|
@ -562,8 +569,9 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
|
|||
return iter->second;
|
||||
}
|
||||
|
||||
auto *image = &model.images[index];
|
||||
auto [handle, staging] = LoadImageToGpu(image, isSrgb);
|
||||
const auto &texture = model.textures[index];
|
||||
auto *image = &model.images[texture.source];
|
||||
auto [handle, staging] = LoadImageToGpu(image, isSrgb, texture.name.empty() ? nullptr : texture.name.c_str());
|
||||
textureHandleMap.emplace(index, handle);
|
||||
stagingBuffers.emplace_back(std::move(staging));
|
||||
return handle;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ struct AssetLoader
|
|||
u32 m_GraphicsQueueIndex;
|
||||
|
||||
Ref<TextureView> LoadHdrImage(cstr path, cstr name = nullptr) const;
|
||||
std::tuple<systems::ResId<TextureView>, Ref<Buffer>> LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const;
|
||||
Model LoadModelToGpu(cstr path, cstr name = nullptr);
|
||||
|
||||
constexpr static auto ANormal = "NORMAL";
|
||||
|
|
@ -132,6 +131,10 @@ struct AssetLoader
|
|||
AssetLoader &operator=(AssetLoader &&other) noexcept;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetLoader);
|
||||
|
||||
private:
|
||||
std::tuple<systems::ResId<TextureView>, Ref<StagingBuffer>>
|
||||
LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name = nullptr) const;
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
|
||||
constexpr auto PIPELINE_CACHE_FILE = "PipelineCacheData.bin";
|
||||
constexpr auto MODEL_FILE = "model/DamagedHelmet.glb";
|
||||
constexpr auto MODEL_FILE = "model/Sponza/Sponza.gltf";
|
||||
constexpr auto BACKDROP_FILE = "image/photo_studio_loft_hall_4k.hdr";
|
||||
constexpr u32 INIT_WIDTH = 1280;
|
||||
constexpr u32 INIT_HEIGHT = 720;
|
||||
|
|
|
|||
|
|
@ -15,38 +15,38 @@ struct FS_Output
|
|||
|
||||
float4 GetAlbedo(float2 UV, float4 InColor)
|
||||
{
|
||||
float4 AlbedoFactor = (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].AlbedoFactor;
|
||||
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].AlbedoTex;
|
||||
float4 AlbedoFactor = (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoFactor;
|
||||
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoTex;
|
||||
|
||||
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[AlbedoTexId].Sample(ImmutableSamplers[AlbedoTexId], UV) : 1.0f.xxxx);
|
||||
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(AlbedoTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(AlbedoTexId)], UV) : 1.0f.xxxx);
|
||||
}
|
||||
|
||||
float GetOcclusion(float2 UV)
|
||||
{
|
||||
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].OcclusionTex;
|
||||
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].OcclusionTex;
|
||||
|
||||
return OcclusionTexId != INVALID_HANDLE ? Textures[OcclusionTexId].Sample(ImmutableSamplers[OcclusionTexId], UV).r : 1.0f;
|
||||
return OcclusionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(OcclusionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(OcclusionTexId)], UV).r : 1.0f;
|
||||
}
|
||||
|
||||
float3 GetEmissive(float2 UV)
|
||||
{
|
||||
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionFactor;
|
||||
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionTex;
|
||||
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionFactor;
|
||||
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionTex;
|
||||
|
||||
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[EmissionTexId].Sample(ImmutableSamplers[EmissionTexId], UV).rgb : 1.0f.xxx);
|
||||
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(EmissionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(EmissionTexId)], UV).rgb : 1.0f.xxx);
|
||||
}
|
||||
|
||||
float3 GetNormal(float3 Position, float3 Normal, float2 UV)
|
||||
{
|
||||
float3 N = normalize(Normal);
|
||||
|
||||
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].NormalTex;
|
||||
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].NormalTex;
|
||||
if (NormalTexId == INVALID_HANDLE)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
float3 TangentSpaceNormal = Textures[NormalTexId].Sample(ImmutableSamplers[NormalTexId], UV).xyz * 2.0f - 1.0f;
|
||||
float3 TangentSpaceNormal = Textures[NonUniformResourceIndex(NormalTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(NormalTexId)], UV).xyz * 2.0f - 1.0f;
|
||||
|
||||
float3 q1 = ddx(Position);
|
||||
float3 q2 = ddy(Position);
|
||||
|
|
@ -62,10 +62,10 @@ float3 GetNormal(float3 Position, float3 Normal, float2 UV)
|
|||
|
||||
float2 GetMetalRough(float2 UV)
|
||||
{
|
||||
float2 MetalRoughFactors = float2(MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].RoughFactor);
|
||||
uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].MetalRoughTex;
|
||||
float2 MetalRoughFactors = float2(MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].RoughFactor);
|
||||
uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].MetalRoughTex;
|
||||
|
||||
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[MetalRoughTexId].Sample(ImmutableSamplers[MetalRoughTexId], UV).bg : 1.0f.xx); // Metal is B, Rough is G.
|
||||
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(MetalRoughTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(MetalRoughTexId)], UV).bg : 1.0f.xx); // Metal is B, Rough is G.
|
||||
}
|
||||
|
||||
float3 SampleIrradiance(float3 Direction)
|
||||
|
|
|
|||
Loading…
Reference in New Issue