Skip to content

Commit

Permalink
PBR Renderer: handle fall-back primitive color
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 23, 2024
1 parent 8909177 commit 67b9491
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion PBR/interface/GLTF_PBR_Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class GLTF_PBR_Renderer : public PBR_Renderer
const float3* PosBias = nullptr;
const float4x4* SkinPreTransform = nullptr; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM
const float4x4* PrevSkinPreTransform = nullptr; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
const float4* BaseColorFactor = nullptr;
const float4* FallbackColor = nullptr;
const void* CustomData = nullptr;
size_t CustomDataSize = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions PBR/src/GLTF_PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
// float4x4 PrevSkinPreTransform; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
// } Transforms;
//
// float4 BaseColorFactor;
// float4 FallbackColor;
// UserDefined CustomData;
//};

Expand Down Expand Up @@ -841,9 +841,9 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
}

{
const float4& BaseColorFactor = AttribsData.BaseColorFactor != nullptr ? *AttribsData.BaseColorFactor : float4{1, 1, 1, 1};
memcpy(pDstPtr, &BaseColorFactor, sizeof(BaseColorFactor));
pDstPtr += sizeof(BaseColorFactor);
const float4& FallbackColor = AttribsData.FallbackColor != nullptr ? *AttribsData.FallbackColor : float4{1, 1, 1, 1};
memcpy(pDstPtr, &FallbackColor, sizeof(FallbackColor));
pDstPtr += sizeof(FallbackColor);
}

{
Expand Down
4 changes: 2 additions & 2 deletions PBR/src/PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ Uint32 PBR_Renderer::GetPBRPrimitiveAttribsSize(PSO_FLAGS Flags, Uint32 CustomDa
// float4x4 PrevSkinPreTransform; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
// } Transforms;
//
// float4 BaseColorFactor;
// float4 FallbackColor;
// UserDefined CustomData;
//};

Expand All @@ -2046,7 +2046,7 @@ Uint32 PBR_Renderer::GetPBRPrimitiveAttribsSize(PSO_FLAGS Flags, Uint32 CustomDa
(UseSkinPreTransform ? sizeof(float4x4) : 0) + // Transforms.SkinPreTransform
(UsePrevSkinPreTransform ? sizeof(float4x4) : 0) + // Transforms.PrevSkinPreTransform

sizeof(float4) + // BaseColorFactor
sizeof(float4) + // FallbackColor
CustomDataSize);
}

Expand Down
7 changes: 4 additions & 3 deletions Shaders/PBR/private/PBR_Textures.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,10 @@ float4 SampleTexture(Texture2DArray Tex,

float4 GetBaseColor(VSOutput VSOut,
PBRMaterialShaderInfo Material,
float MipBias)
float MipBias,
float4 DefaultValue)
{
float4 BaseColor = float4(1.0, 1.0, 1.0, 1.0);
float4 BaseColor = DefaultValue;

# if USE_COLOR_MAP
{
Expand All @@ -441,7 +442,7 @@ float4 GetBaseColor(VSOutput VSOut,
VSOut,
Material.Textures[BaseColorTextureAttribId],
MipBias,
float4(1.0, 1.0, 1.0, 1.0));
DefaultValue);
BaseColor = float4(TO_LINEAR(BaseColor.rgb), BaseColor.a);
}
# endif
Expand Down
3 changes: 1 addition & 2 deletions Shaders/PBR/private/RenderPBR.psh
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ float4 GetLoadingAnimationColor(float3 WorldPos, float Factor)
PSOutput main(in VSOutput VSOut,
in bool IsFrontFace : SV_IsFrontFace)
{
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias);
BaseColor *= PRIMITIVE.BaseColorFactor;
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias, PRIMITIVE.FallbackColor);

#if USE_VERTEX_NORMALS
float3 MeshNormal = VSOut.Normal;
Expand Down
2 changes: 1 addition & 1 deletion Shaders/PBR/private/RenderPBR_Structures.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct PBRPrimitiveAttribs
{
GLTFNodeShaderTransforms Transforms;

float4 BaseColorFactor;
float4 FallbackColor;
float4 CustomData;
};
#ifdef CHECK_STRUCT_ALIGNMENT
Expand Down

0 comments on commit 67b9491

Please sign in to comment.