| 221 | } |
| 222 | |
| 223 | void HnRenderShadowsTask::Prepare(pxr::HdTaskContext* TaskCtx, |
| 224 | pxr::HdRenderIndex* RenderIndex) |
| 225 | { |
| 226 | m_RenderIndex = RenderIndex; |
| 227 | |
| 228 | m_LightsByShadowSlice.clear(); |
| 229 | |
| 230 | const HnRenderDelegate* RenderDelegate = static_cast<const HnRenderDelegate*>(m_RenderIndex->GetRenderDelegate()); |
| 231 | const HnRenderParam* pRenderParam = static_cast<const HnRenderParam*>(RenderDelegate->GetRenderParam()); |
| 232 | if (pRenderParam == nullptr) |
| 233 | { |
| 234 | UNEXPECTED("Render param is null"); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (!pRenderParam->GetUseShadows()) |
| 239 | return; |
| 240 | |
| 241 | PrepareClearDepthPSO(*RenderDelegate); |
| 242 | PrepareClearDepthVB(*RenderDelegate); |
| 243 | |
| 244 | const Uint32 GeometryVersion = |
| 245 | (pRenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::GeometrySubsetDrawItems) + |
| 246 | pRenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::MeshGeometry) + |
| 247 | pRenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::MeshTransform) + |
| 248 | pRenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::MeshVisibility) + |
| 249 | pRenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::MeshMaterial)); |
| 250 | static_assert(static_cast<int>(HnRenderParam::GlobalAttrib::Count) == 9, "Please update the code above to handle the new attribute, if necessary."); |
| 251 | |
| 252 | bool GeometryChanged = m_LastGeometryVersion != GeometryVersion; |
| 253 | m_LastGeometryVersion = GeometryVersion; |
| 254 | |
| 255 | const auto& Lights = RenderDelegate->GetLights(); |
| 256 | |
| 257 | // Sort all shadow lights with dirty shadow maps by shadow map slice |
| 258 | for (HnLight* Light : Lights) |
| 259 | { |
| 260 | if (!Light->ShadowsEnabled()) |
| 261 | continue; |
| 262 | |
| 263 | if (GeometryChanged) |
| 264 | { |
| 265 | // Make shadow map dirty even if the light is disabled so that |
| 266 | // when it is enabled, the shadow map will be updated. |
| 267 | Light->SetShadowMapDirty(true); |
| 268 | } |
| 269 | |
| 270 | if (!Light->IsShadowMapDirty()) |
| 271 | continue; |
| 272 | |
| 273 | Int32 ShadowCatingLightId = Light->GetFrameAttribsIndex(); |
| 274 | if (ShadowCatingLightId < 0) |
| 275 | continue; |
| 276 | |
| 277 | VERIFY(Light->IsVisible(), "Invisible lights should not be assigned shadow casting light index"); |
| 278 | |
| 279 | ITextureAtlasSuballocation* pAtlasRegion = Light->GetShadowMapSuballocation(); |
| 280 | m_LightsByShadowSlice.emplace(pAtlasRegion->GetSlice(), Light); |
nothing calls this directly
no test coverage detected