Skip to content

Commit

Permalink
Hydrogent: implemented basic mesh highlight using emissive
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 21, 2023
1 parent f7cbd90 commit c8011a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Hydrogent/interface/HnRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ struct HnDrawAttribs
bool EnablePrimIdQueries = false;

float4 WireframeColor = float4{1, 1, 1, 1};
float4 SlectionColor = float4{0.25f, 0.25f, 0.1f, 0.0f};

HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID;

const char* SelectedPrim = nullptr;
};

class IHnRenderer : public IObject
Expand All @@ -99,6 +102,17 @@ class IHnRenderer : public IObject

virtual void SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvironmentMapSRV) = 0;

/// Queries primitive Id from the previously rendered primitive Id texture.
///
/// \param [in] pCtx - device context to run graphics commands.
/// \param [in] X - query x coordinate.
/// \param [in] Y - query x coordinate.
///
/// \return If query result is not available, returns nullptr.
/// If query result is available, but no primitive is selected, returns empty string.
/// Otherwise, returns the primitive SDF path.
///
/// \remarks Only a single query per frame is supported.
virtual const char* QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) = 0;

virtual void RenderPrimId(IDeviceContext* pCtx, ITextureView* pDepthBuffer, const float4x4& Transform) = 0;
Expand Down
4 changes: 3 additions & 1 deletion Hydrogent/src/HnMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void HnMaterial::Sync(pxr::HdSceneDelegate* SceneDelegate,
AllocateTextures(TexRegistry);

m_ShaderAttribs.BaseColorFactor = float4{1, 1, 1, 1};
m_ShaderAttribs.EmissiveFactor = float4{1, 1, 1, 1};
m_ShaderAttribs.EmissiveFactor = float4{0, 0, 0, 0};
m_ShaderAttribs.SpecularFactor = float4{1, 1, 1, 1};
m_ShaderAttribs.MetallicFactor = 1;
m_ShaderAttribs.RoughnessFactor = 1;
Expand Down Expand Up @@ -224,6 +224,8 @@ void HnMaterial::UpdateSRB(IRenderDevice* pDevice,
SetTexture(HnTokens->roughness, PbrRenderer.GetWhiteTexSRV(), "g_RoughnessMap");
SetTexture(HnTokens->normal, PbrRenderer.GetDefaultNormalMapSRV(), "g_NormalMap");
SetTexture(HnTokens->occlusion, PbrRenderer.GetWhiteTexSRV(), "g_AOMap");
if (auto* pVar = m_SRB->GetVariableByName(SHADER_TYPE_PIXEL, "g_EmissiveMap"))
pVar->Set(PbrRenderer.GetWhiteTexSRV());
}

} // namespace USD
Expand Down
15 changes: 12 additions & 3 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters,
USDRendererCI.AllowDebugView = true;
USDRendererCI.UseIBL = true;
USDRendererCI.UseAO = true;
USDRendererCI.UseEmissive = false;
USDRendererCI.UseEmissive = true;
USDRendererCI.EnableMeshIdRendering = true;

// Use samplers from texture views
Expand Down Expand Up @@ -277,6 +277,9 @@ void HnRendererImpl::RenderMesh(IDeviceContext* pCtx, const HnMesh& Mesh, const
static_assert(sizeof(pDstShaderAttribs->Material) == sizeof(ShaderAttribs), "The sizeof(PBRMaterialShaderInfo) is inconsistent with sizeof(ShaderAttribs)");
memcpy(&pDstShaderAttribs->Material, &ShaderAttribs, sizeof(ShaderAttribs));

if (Attribs.SelectedPrim != nullptr && Mesh.GetId().GetString() == Attribs.SelectedPrim)
pDstShaderAttribs->Material.EmissiveFactor = ShaderAttribs.EmissiveFactor + Attribs.SlectionColor;

auto& RendererParams = pDstShaderAttribs->Renderer;

RendererParams.DebugViewType = Attribs.DebugView;
Expand Down Expand Up @@ -306,7 +309,10 @@ void HnRendererImpl::SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvi

const char* HnRendererImpl::QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y)
{
Uint32 MeshUid = 0;
if (!m_MeshIdTexture)
return nullptr;

Uint32 MeshUid = ~0u;
while (auto pStagingTex = m_MeshIdReadBackQueue.GetFirstCompleted())
{
{
Expand Down Expand Up @@ -345,7 +351,10 @@ const char* HnRendererImpl::QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y
pCtx->CopyTexture(CopyAttribs);
m_MeshIdReadBackQueue.Enqueue(pCtx, std::move(pStagingTex));

return MeshUid != 0 ? m_RenderDelegate->GetMeshPrimId(MeshUid) : nullptr;
if (MeshUid == ~0u)
return nullptr;
else
return MeshUid != 0 ? m_RenderDelegate->GetMeshPrimId(MeshUid) : "";
}

void HnRendererImpl::RenderPrimId(IDeviceContext* pContext, ITextureView* pDepthBuffer, const float4x4& Transform)
Expand Down

0 comments on commit c8011a1

Please sign in to comment.