Skip to content

Commit b15bcc8

Browse files
PBR Renderer: added base color factor to primitive attribs
1 parent 86bd62a commit b15bcc8

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

Hydrogent/src/HnRenderPass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
675675
&Transform.PosBias,
676676
pSkinningData ? reinterpret_cast<const float4x4*>(pSkinningData->GeomBindXform.Data()) : nullptr,
677677
pSkinningData ? reinterpret_cast<const float4x4*>(pSkinningData->GeomBindXform.Data()) : nullptr,
678+
&DisplayColor,
678679
&ListItem.MeshUID, // CustomData
679680
sizeof(ListItem.MeshUID), // CustomDataSize
680681
};

PBR/interface/GLTF_PBR_Renderer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +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;
262263
const void* CustomData = nullptr;
263264
size_t CustomDataSize = 0;
264265
};

PBR/src/GLTF_PBR_Renderer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +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;
769770
// UserDefined CustomData;
770771
//};
771772

@@ -839,6 +840,12 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
839840
}
840841
}
841842

843+
{
844+
const float4& BaseColorFactor = AttribsData.BaseColorFactor != nullptr ? *AttribsData.BaseColorFactor : float4{1, 1, 1, 1};
845+
memcpy(pDstPtr, &BaseColorFactor, sizeof(BaseColorFactor));
846+
pDstPtr += sizeof(BaseColorFactor);
847+
}
848+
842849
{
843850
if (AttribsData.CustomData != nullptr)
844851
{

PBR/src/PBR_Renderer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +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;
20362037
// UserDefined CustomData;
20372038
//};
20382039

@@ -2045,6 +2046,7 @@ Uint32 PBR_Renderer::GetPBRPrimitiveAttribsSize(PSO_FLAGS Flags, Uint32 CustomDa
20452046
(UseSkinPreTransform ? sizeof(float4x4) : 0) + // Transforms.SkinPreTransform
20462047
(UsePrevSkinPreTransform ? sizeof(float4x4) : 0) + // Transforms.PrevSkinPreTransform
20472048

2049+
sizeof(float4) + // BaseColorFactor
20482050
CustomDataSize);
20492051
}
20502052

Shaders/PBR/private/RenderPBR.psh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ PSOutput main(in VSOutput VSOut,
379379
in bool IsFrontFace : SV_IsFrontFace)
380380
{
381381
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias);
382+
BaseColor *= PRIMITIVE.BaseColorFactor;
382383

383384
#if USE_VERTEX_NORMALS
384385
float3 MeshNormal = VSOut.Normal;

Shaders/PBR/private/RenderPBR_Structures.fxh

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

34+
float4 BaseColorFactor;
3435
float4 CustomData;
3536
};
3637
#ifdef CHECK_STRUCT_ALIGNMENT

0 commit comments

Comments
 (0)