Skip to content

Commit

Permalink
Hydrogent: combined MeshId rendering with main render pass
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 17, 2023
1 parent aaf655d commit 027f3a8
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 179 deletions.
5 changes: 3 additions & 2 deletions Components/interface/EnvMapRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class EnvMapRenderer
IRenderStateCache* pStateCache = nullptr;
IBuffer* pCameraAttribsCB = nullptr;

TEXTURE_FORMAT RTVFormat = TEX_FORMAT_RGBA8_UNORM_SRGB;
TEXTURE_FORMAT DSVFormat = TEX_FORMAT_D32_FLOAT;
Uint8 NumRenderTargets = 1;
TEXTURE_FORMAT RTVFormats[DILIGENT_MAX_RENDER_TARGETS] = {TEX_FORMAT_RGBA8_UNORM_SRGB};
TEXTURE_FORMAT DSVFormat = TEX_FORMAT_D32_FLOAT;

int ToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;

Expand Down
3 changes: 2 additions & 1 deletion Components/src/EnvMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ EnvMapRenderer::EnvMapRenderer(const CreateInfo& CI)
.AddShader(pVS)
.AddShader(pPS)
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.AddRenderTarget(CI.RTVFormat)
.SetDepthFormat(CI.DSVFormat);
for (Uint32 i = 0; i < CI.NumRenderTargets; ++i)
PsoCI.AddRenderTarget(CI.RTVFormats[i]);

PsoCI.GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_LESS_EQUAL;

Expand Down
24 changes: 19 additions & 5 deletions Hydrogent/include/HnRendererImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>

virtual const pxr::SdfPath* QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) override final;

void RenderPrimId(IDeviceContext* pContext, ITextureView* pDepthBuffer, const float4x4& Transform) override final;

private:
void RenderMesh(IDeviceContext* pCtx,
const HnMesh& Mesh,
Expand All @@ -93,19 +91,23 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>
USD_Renderer::ALPHA_MODE AlphaMode);
void RenderMeshes(IDeviceContext* pCtx, const HnDrawAttribs& Attribs);

void PrepareRenderTargets(ITextureView* pDstRtv);
void PreparePostProcess(TEXTURE_FORMAT RTVFmt);

private:
RenderDeviceWithCache_N m_Device;
RefCntAutoPtr<IDeviceContext> m_Context;

RefCntAutoPtr<IBuffer> m_CameraAttribsCB;
RefCntAutoPtr<IBuffer> m_LightAttribsCB;

const bool m_ConvertOutputToSRGB;

std::shared_ptr<USD_Renderer> m_USDRenderer;
std::unique_ptr<EnvMapRenderer> m_EnvMapRenderer;

USD_Renderer::PbrPsoCacheAccessor m_PbrPSOCache;
USD_Renderer::WireframePsoCacheAccessor m_WireframePSOCache;
USD_Renderer::MeshIdPsoCacheAccessor m_MeshIdPSOCache;

std::unique_ptr<HnRenderDelegate> m_RenderDelegate;

Expand All @@ -116,13 +118,18 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>
pxr::TfTokenVector m_RenderTags;
pxr::HdRenderPassSharedPtr m_GeometryPass;

RefCntAutoPtr<ITexture> m_MeshIdTexture;
RefCntAutoPtr<ITexture> m_DepthBuffer;
RefCntAutoPtr<ITexture> m_ColorBuffer;
RefCntAutoPtr<ITexture> m_MeshIdTexture;
RefCntAutoPtr<ITextureView> m_DepthBufferDSV;

GPUCompletionAwaitQueue<RefCntAutoPtr<ITexture>> m_MeshIdReadBackQueue;

PBR_Renderer::PSO_FLAGS m_DefaultPSOFlags = PBR_Renderer::PSO_FLAG_NONE;

static constexpr TEXTURE_FORMAT ColorBufferFormat = TEX_FORMAT_R11G11B10_FLOAT;
static constexpr TEXTURE_FORMAT MeshIdFormat = TEX_FORMAT_RGBA8_UNORM;
static constexpr TEXTURE_FORMAT DepthFormat = TEX_FORMAT_D32_FLOAT;

struct MeshRenderInfo
{
const HnMesh& Mesh;
Expand All @@ -134,6 +141,13 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>
{}
};
std::array<std::vector<MeshRenderInfo>, USD_Renderer::ALPHA_MODE_NUM_MODES> m_RenderLists;

struct PostProcessState
{
RefCntAutoPtr<IPipelineState> PSO;
RefCntAutoPtr<IShaderResourceBinding> SRB;
};
PostProcessState m_PostProcess;
};

} // namespace USD
Expand Down
4 changes: 2 additions & 2 deletions Hydrogent/interface/HnRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct HnDrawAttribs
{
float4x4 Transform = float4x4::Identity();

ITextureView* pDstRTV = nullptr;

int DebugView = 0;
float OcclusionStrength = 1;
float EmissionScale = 1;
Expand Down Expand Up @@ -114,8 +116,6 @@ class IHnRenderer : public IObject
///
/// \remarks Only a single query per frame is supported.
virtual const pxr::SdfPath* QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) = 0;

virtual void RenderPrimId(IDeviceContext* pCtx, ITextureView* pDepthBuffer, const float4x4& Transform) = 0;
};

void CreateHnRenderer(IRenderDevice* pDevice, IDeviceContext* pContext, const HnRendererCreateInfo& CI, IHnRenderer** ppRenderer);
Expand Down
Loading

0 comments on commit 027f3a8

Please sign in to comment.