Skip to content

Commit

Permalink
Hydrogent: enable materials with emissive textures
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 2, 2023
1 parent d5742f4 commit 97c24ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Hydrogent/include/HnTokens.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace USD
(roughness) \
(normal) \
(occlusion) \
(emissive)
(emissiveColor)

#define HN_MATERIAL_TAG_TOKENS \
(defaultTag) \
Expand Down
2 changes: 1 addition & 1 deletion Hydrogent/interface/HnRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions Hydrogent/src/HnMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<float>(TexNameToCoordSetMap[HnTokens->normal]);
m_ShaderAttribs.UVSelector3 = static_cast<float>(TexNameToCoordSetMap[HnTokens->occlusion]);
m_ShaderAttribs.UVSelector4 = static_cast<float>(TexNameToCoordSetMap[HnTokens->emissive]);
m_ShaderAttribs.UVSelector4 = static_cast<float>(TexNameToCoordSetMap[HnTokens->emissiveColor]);
m_ShaderAttribs.TextureSlice0 = 0;
m_ShaderAttribs.TextureSlice1 = 0;
m_ShaderAttribs.TextureSlice2 = 0;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 97c24ea

Please sign in to comment.