Skip to content

Commit

Permalink
PBR Renderer: added base color factor to primitive attribs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 23, 2024
1 parent 86bd62a commit b15bcc8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Hydrogent/src/HnRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
&Transform.PosBias,
pSkinningData ? reinterpret_cast<const float4x4*>(pSkinningData->GeomBindXform.Data()) : nullptr,
pSkinningData ? reinterpret_cast<const float4x4*>(pSkinningData->GeomBindXform.Data()) : nullptr,
&DisplayColor,
&ListItem.MeshUID, // CustomData
sizeof(ListItem.MeshUID), // CustomDataSize
};
Expand Down
1 change: 1 addition & 0 deletions PBR/interface/GLTF_PBR_Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +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 void* CustomData = nullptr;
size_t CustomDataSize = 0;
};
Expand Down
7 changes: 7 additions & 0 deletions PBR/src/GLTF_PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ void* GLTF_PBR_Renderer::WritePBRPrimitiveShaderAttribs(void*
// float4x4 PrevSkinPreTransform; // #if USE_JOINTS && USE_SKIN_PRE_TRANSFORM && COMPUTE_MOTION_VECTORS
// } Transforms;
//
// float4 BaseColorFactor;
// UserDefined CustomData;
//};

Expand Down Expand Up @@ -839,6 +840,12 @@ 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);
}

{
if (AttribsData.CustomData != nullptr)
{
Expand Down
2 changes: 2 additions & 0 deletions PBR/src/PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +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;
// UserDefined CustomData;
//};

Expand All @@ -2045,6 +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
CustomDataSize);
}

Expand Down
1 change: 1 addition & 0 deletions Shaders/PBR/private/RenderPBR.psh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ PSOutput main(in VSOutput VSOut,
in bool IsFrontFace : SV_IsFrontFace)
{
float4 BaseColor = GetBaseColor(VSOut, g_Material, g_Frame.Renderer.MipBias);
BaseColor *= PRIMITIVE.BaseColorFactor;

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

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

0 comments on commit b15bcc8

Please sign in to comment.