Skip to content

Commit

Permalink
Hydrogent: added option to control winding order + mesh transform
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 19, 2023
1 parent f7b934b commit d6075d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Hydrogent/interface/HnRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct HnRendererCreateInfo
/// Depth-buffer format.
TEXTURE_FORMAT DSVFormat = TEX_FORMAT_UNKNOWN;

bool FrontCCW = false;

bool ConvertOutputToSRGB = false;

/// Camera attributes constant buffer.
Expand All @@ -60,7 +62,7 @@ struct HnRendererCreateInfo

struct HnDrawAttribs
{
float4x4 CameraViewProj = float4x4::Identity();
float4x4 Transform = float4x4::Identity();

int DebugView = 0;
float OcclusionStrength = 1;
Expand Down
13 changes: 7 additions & 6 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters,
PBRRendererCI.RTVFmt = CI.RTVFormat;
PBRRendererCI.DSVFmt = CI.DSVFormat;

PBRRendererCI.FrontCCW = CI.FrontCCW;
PBRRendererCI.AllowDebugView = true;
PBRRendererCI.UseIBL = true;
PBRRendererCI.UseAO = true;
Expand Down Expand Up @@ -253,15 +254,15 @@ void HnRendererImpl::Draw(IDeviceContext* pCtx, const HnDrawAttribs& Attribs)
pCtx->SetIndexBuffer(pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);

{
MapHelper<HLSL::PBRShaderAttribs> pAttribs{pCtx, m_PBRRenderer->GetPBRAttribsCB(), MAP_WRITE, MAP_FLAG_DISCARD};
MapHelper<HLSL::PBRShaderAttribs> pDstShaderAttribs{pCtx, m_PBRRenderer->GetPBRAttribsCB(), MAP_WRITE, MAP_FLAG_DISCARD};

pAttribs->Transforms.NodeMatrix = Mesh.GetTransform();
pAttribs->Transforms.JointCount = 0;
pDstShaderAttribs->Transforms.NodeMatrix = Mesh.GetTransform() * Attribs.Transform;
pDstShaderAttribs->Transforms.JointCount = 0;

static_assert(sizeof(pAttribs->Material) == sizeof(ShaderAttribs), "The sizeof(PBRMaterialShaderInfo) is inconsistent with sizeof(ShaderAttribs)");
memcpy(&pAttribs->Material, &ShaderAttribs, sizeof(ShaderAttribs));
static_assert(sizeof(pDstShaderAttribs->Material) == sizeof(ShaderAttribs), "The sizeof(PBRMaterialShaderInfo) is inconsistent with sizeof(ShaderAttribs)");
memcpy(&pDstShaderAttribs->Material, &ShaderAttribs, sizeof(ShaderAttribs));

auto& RendererParams = pAttribs->Renderer;
auto& RendererParams = pDstShaderAttribs->Renderer;

RendererParams.DebugViewType = Attribs.DebugView;
RendererParams.OcclusionStrength = Attribs.OcclusionStrength;
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 @@ -660,8 +660,8 @@ void PBR_Renderer::CreatePSO(IRenderDevice* pDevice, IRenderStateCache* pStateCa
RT0.SrcBlend = BLEND_FACTOR_SRC_ALPHA;
RT0.DestBlend = BLEND_FACTOR_INV_SRC_ALPHA;
RT0.BlendOp = BLEND_OPERATION_ADD;
RT0.SrcBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
RT0.DestBlendAlpha = BLEND_FACTOR_ZERO;
RT0.SrcBlendAlpha = BLEND_FACTOR_ONE;
RT0.DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
RT0.BlendOpAlpha = BLEND_OPERATION_ADD;

{
Expand Down

0 comments on commit d6075d6

Please sign in to comment.