From 97c24ea41fdf50bb34e2b73160318e748b74c4f8 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 2 Oct 2023 14:15:38 -0700 Subject: [PATCH] Hydrogent: enable materials with emissive textures --- Hydrogent/include/HnTokens.hpp | 2 +- Hydrogent/interface/HnRenderer.hpp | 2 +- Hydrogent/src/HnMaterial.cpp | 7 +++---- Hydrogent/src/HnRendererImpl.cpp | 5 +++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Hydrogent/include/HnTokens.hpp b/Hydrogent/include/HnTokens.hpp index 5cdaed56..9be0a4c8 100644 --- a/Hydrogent/include/HnTokens.hpp +++ b/Hydrogent/include/HnTokens.hpp @@ -68,7 +68,7 @@ namespace USD (roughness) \ (normal) \ (occlusion) \ - (emissive) + (emissiveColor) #define HN_MATERIAL_TAG_TOKENS \ (defaultTag) \ diff --git a/Hydrogent/interface/HnRenderer.hpp b/Hydrogent/interface/HnRenderer.hpp index d6058d03..0fd93dcc 100644 --- a/Hydrogent/interface/HnRenderer.hpp +++ b/Hydrogent/interface/HnRenderer.hpp @@ -84,7 +84,7 @@ struct HnDrawAttribs bool EnablePrimIdQueries = false; float4 WireframeColor = float4{1, 1, 1, 1}; - float4 SlectionColor = float4{0.25f, 0.25f, 0.1f, 0.0f}; + float4 SlectionColor = float4{0.25f, 0.25f, 0.1f, 0.5f}; HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; diff --git a/Hydrogent/src/HnMaterial.cpp b/Hydrogent/src/HnMaterial.cpp index a15f71b0..251b2382 100644 --- a/Hydrogent/src/HnMaterial.cpp +++ b/Hydrogent/src/HnMaterial.cpp @@ -88,7 +88,7 @@ void HnMaterial::Sync(pxr::HdSceneDelegate* SceneDelegate, AllocateTextures(TexRegistry, TexNameToCoordSetMap); m_ShaderAttribs.BaseColorFactor = float4{1, 1, 1, 1}; - m_ShaderAttribs.EmissiveFactor = float4{0, 0, 0, 0}; + m_ShaderAttribs.EmissiveFactor = float4{1, 1, 1, 1}; m_ShaderAttribs.SpecularFactor = float4{1, 1, 1, 1}; m_ShaderAttribs.MetallicFactor = 1; m_ShaderAttribs.RoughnessFactor = 1; @@ -130,7 +130,7 @@ void HnMaterial::Sync(pxr::HdSceneDelegate* SceneDelegate, LOG_ERROR_MESSAGE("Metallic and roughness textures must use the same texture coordinates"); m_ShaderAttribs.UVSelector2 = static_cast(TexNameToCoordSetMap[HnTokens->normal]); m_ShaderAttribs.UVSelector3 = static_cast(TexNameToCoordSetMap[HnTokens->occlusion]); - m_ShaderAttribs.UVSelector4 = static_cast(TexNameToCoordSetMap[HnTokens->emissive]); + m_ShaderAttribs.UVSelector4 = static_cast(TexNameToCoordSetMap[HnTokens->emissiveColor]); m_ShaderAttribs.TextureSlice0 = 0; m_ShaderAttribs.TextureSlice1 = 0; m_ShaderAttribs.TextureSlice2 = 0; @@ -261,8 +261,7 @@ 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()); + SetTexture(HnTokens->emissiveColor, PbrRenderer.GetBlackTexSRV(), "g_EmissiveMap"); } } // namespace USD diff --git a/Hydrogent/src/HnRendererImpl.cpp b/Hydrogent/src/HnRendererImpl.cpp index 22498154..40dde52a 100644 --- a/Hydrogent/src/HnRendererImpl.cpp +++ b/Hydrogent/src/HnRendererImpl.cpp @@ -307,8 +307,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; + pDstShaderAttribs->Renderer.HighlightColor = (Attribs.SelectedPrim != nullptr && Mesh.GetId().GetString() == Attribs.SelectedPrim) ? + Attribs.SlectionColor : + float4{0, 0, 0, 0}; auto& RendererParams = pDstShaderAttribs->Renderer;