Skip to content

Commit

Permalink
Hydrogent: use dome light intensity, color and temperature attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed May 14, 2024
1 parent a90d7c7 commit 7ddd97e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
17 changes: 9 additions & 8 deletions Hydrogent/interface/HnLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ class HnLight final : public pxr::HdLight
// change tracker for use in the first sync of this prim.
virtual pxr::HdDirtyBits GetInitialDirtyBitsMask() const override final;

const float3& GetPosition() const { return m_Position; }
const float3& GetDirection() const { return m_Direction; }
const GLTF::Light& GetParams() const { return m_Params; }
bool IsVisible() const { return m_IsVisible; }
const float4x4& GetViewMatrix() const { return m_ViewMatrix; }
const float4x4& GetProjMatrix() const { return m_ProjMatrix; }
const float4x4& GetViewProjMatrix() const { return m_ViewProjMatrix; }
bool ShadowsEnabled() const { return m_ShadowMapSuballocation != nullptr && m_SceneBounds.IsValid(); }
const pxr::TfToken& GetTypeId() const { return m_TypeId; }
const float3& GetPosition() const { return m_Position; }
const float3& GetDirection() const { return m_Direction; }
const GLTF::Light& GetParams() const { return m_Params; }
bool IsVisible() const { return m_IsVisible; }
const float4x4& GetViewMatrix() const { return m_ViewMatrix; }
const float4x4& GetProjMatrix() const { return m_ProjMatrix; }
const float4x4& GetViewProjMatrix() const { return m_ViewProjMatrix; }
bool ShadowsEnabled() const { return m_ShadowMapSuballocation != nullptr && m_SceneBounds.IsValid(); }

/// Sets the index of the light's frame attributes data in the frame attribs buffer.
/// This index is passed to the HnRenderDelegate::GetShadowPassFrameAttribsSRB
Expand Down
14 changes: 8 additions & 6 deletions Hydrogent/src/HnLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
m_TypeId == pxr::HdPrimTypeTokens->diskLight ||
m_TypeId == pxr::HdPrimTypeTokens->distantLight ||
m_TypeId == pxr::HdPrimTypeTokens->rectLight ||
m_TypeId == pxr::HdPrimTypeTokens->sphereLight)
m_TypeId == pxr::HdPrimTypeTokens->sphereLight ||
m_TypeId == pxr::HdPrimTypeTokens->domeLight)
{
float MetersPerUnit = 1;
if (RenderParam != nullptr)
Expand All @@ -516,7 +517,12 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
LightDirty = true;
}
}
else if (m_TypeId == pxr::HdPrimTypeTokens->domeLight)
else
{
LOG_ERROR_MESSAGE("Unsupported light type: ", m_TypeId);
}

if (m_TypeId == pxr::HdPrimTypeTokens->domeLight)
{
std::string TexturePath = GetTextureFile(*SceneDelegate, Id).GetAssetPath();
if (TexturePath != m_TexturePath)
Expand All @@ -526,10 +532,6 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
m_IsTextureDirty = true;
}
}
else
{
LOG_ERROR_MESSAGE("Unsupported light type: ", m_TypeId);
}

*DirtyBits &= ~DirtyParams;
}
Expand Down
23 changes: 20 additions & 3 deletions Hydrogent/src/Tasks/HnBeginFrameTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,24 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,
UNEXPECTED("Camera is null. It should've been set in Prepare()");
}

int LightCount = 0;
HnLight* DomeLight = nullptr;
int LightCount = 0;
for (HnLight* Light : RenderDelegate->GetLights())
{
if (!Light->IsVisible() || Light->GetParams().Type == GLTF::Light::TYPE::UNKNOWN)
if (!Light->IsVisible())
continue;

if (Light->GetTypeId() == pxr::HdPrimTypeTokens->domeLight)
{
if (DomeLight != nullptr)
{
LOG_DVP_WARNING_MESSAGE("Multiple dome lights are currently not supported.");
}
DomeLight = Light;
continue;
}

if (Light->GetParams().Type == GLTF::Light::TYPE::UNKNOWN)
continue;

GLTF_PBR_Renderer::PBRLightShaderAttribsData LightAttribs{
Expand Down Expand Up @@ -554,7 +568,10 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,

RendererParams.OcclusionStrength = m_Params.Renderer.OcclusionStrength;
RendererParams.EmissionScale = m_Params.Renderer.EmissionScale;
RendererParams.IBLScale = m_Params.Renderer.IBLScale;

RendererParams.IBLScale = DomeLight != nullptr ?
DomeLight->GetParams().Color * DomeLight->GetParams().Intensity * m_Params.Renderer.IBLScale :
float4{0};

RendererParams.UnshadedColor = m_Params.Renderer.UnshadedColor;
RendererParams.HighlightColor = float4{0, 0, 0, 0};
Expand Down

0 comments on commit 7ddd97e

Please sign in to comment.