Skip to content

Commit 67b9491

Browse files
PBR Renderer: handle fall-back primitive color
1 parent 8909177 commit 67b9491

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

PBR/interface/GLTF_PBR_Renderer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class GLTF_PBR_Renderer : public PBR_Renderer
259259
const float3* PosBias = nullptr;
260260
const float4x4* SkinPreTransform = nullptr; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM
261261
const float4x4* PrevSkinPreTransform = nullptr; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
262-
const float4* BaseColorFactor = nullptr;
262+
const float4* FallbackColor = nullptr;
263263
const void* CustomData = nullptr;
264264
size_t CustomDataSize = 0;
265265
};

PBR/src/GLTF_PBR_Renderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
766766
// float4x4 PrevSkinPreTransform; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
767767
// } Transforms;
768768
//
769-
// float4 BaseColorFactor;
769+
// float4 FallbackColor;
770770
// UserDefined CustomData;
771771
//};
772772

@@ -841,9 +841,9 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
841841
}
842842

843843
{
844-
const float4& BaseColorFactor = AttribsData.BaseColorFactor != nullptr ? *AttribsData.BaseColorFactor : float4{1, 1, 1, 1};
845-
memcpy(pDstPtr, &BaseColorFactor, sizeof(BaseColorFactor));
846-
pDstPtr += sizeof(BaseColorFactor);
844+
const float4& FallbackColor = AttribsData.FallbackColor != nullptr ? *AttribsData.FallbackColor : float4{1, 1, 1, 1};
845+
memcpy(pDstPtr, &FallbackColor, sizeof(FallbackColor));
846+
pDstPtr += sizeof(FallbackColor);
847847
}
848848

849849
{

PBR/src/PBR_Renderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ Uint32 PBR_Renderer::GetPBRPrimitiveAttribsSize(PSO_FLAGS Flags, Uint32 CustomDa
20332033
// float4x4 PrevSkinPreTransform; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
20342034
// } Transforms;
20352035
//
2036-
// float4 BaseColorFactor;
2036+
// float4 FallbackColor;
20372037
// UserDefined CustomData;
20382038
//};
20392039

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

2049-
sizeof(float4) + // BaseColorFactor
2049+
sizeof(float4) + // FallbackColor
20502050
CustomDataSize);
20512051
}
20522052

Shaders/PBR/private/PBR_Textures.fxh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,10 @@ float4 SampleTexture(Texture2DArray Tex,
430430

431431
float4 GetBaseColor(VSOutput VSOut,
432432
PBRMaterialShaderInfo Material,
433-
float MipBias)
433+
float MipBias,
434+
float4 DefaultValue)
434435
{
435-
float4 BaseColor = float4(1.0, 1.0, 1.0, 1.0);
436+
float4 BaseColor = DefaultValue;
436437

437438
# if USE_COLOR_MAP
438439
{
@@ -441,7 +442,7 @@ float4 GetBaseColor(VSOutput VSOut,
441442
VSOut,
442443
Material.Textures[BaseColorTextureAttribId],
443444
MipBias,
444-
float4(1.0, 1.0, 1.0, 1.0));
445+
DefaultValue);
445446
BaseColor = float4(TO_LINEAR(BaseColor.rgb), BaseColor.a);
446447
}
447448
# endif

Shaders/PBR/private/RenderPBR.psh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ float4 GetLoadingAnimationColor(float3 WorldPos, float Factor)
378378
PSOutput main(in VSOutput VSOut,
379379
in bool IsFrontFace : SV_IsFrontFace)
380380
{
381-
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias);
382-
BaseColor *= PRIMITIVE.BaseColorFactor;
381+
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias, PRIMITIVE.FallbackColor);
383382

384383
#if USE_VERTEX_NORMALS
385384
float3 MeshNormal = VSOut.Normal;

Shaders/PBR/private/RenderPBR_Structures.fxh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct PBRPrimitiveAttribs
3131
{
3232
GLTFNodeShaderTransforms Transforms;
3333

34-
float4 BaseColorFactor;
34+
float4 FallbackColor;
3535
float4 CustomData;
3636
};
3737
#ifdef CHECK_STRUCT_ALIGNMENT

0 commit comments

Comments
 (0)