public void RenderShadows(ScriptableRenderContext renderContext, CommandBuffer cmd, CullingResults cullResults, HDCamera hdCamera) { // Avoid to do any commands if there is no shadow to draw if (m_ShadowRequestCount == 0) { return; } // TODO remove DrawShadowSettings, lightIndex and splitData when scriptable culling is available ShadowDrawingSettings dss = new ShadowDrawingSettings(cullResults, 0); dss.useRenderingLayerMaskTest = hdCamera.frameSettings.IsEnabled(FrameSettingsField.LightLayers); // Clear atlas render targets and draw shadows using (new ProfilingSample(cmd, "Punctual Lights Shadows rendering", CustomSamplerId.RenderShadows.GetSampler())) { m_Atlas.RenderShadows(renderContext, cmd, dss); } using (new ProfilingSample(cmd, "Directional Light Shadows rendering", CustomSamplerId.RenderShadows.GetSampler())) { m_CascadeAtlas.RenderShadows(renderContext, cmd, dss); } using (new ProfilingSample(cmd, "Area Light Shadows rendering", CustomSamplerId.RenderShadows.GetSampler())) { m_AreaLightShadowAtlas.RenderShadows(renderContext, cmd, dss); if (m_AreaLightShadowAtlas.HasBlurredEVSM()) { m_AreaLightShadowAtlas.AreaShadowBlurMoments(cmd, hdCamera); } } // If the shadow algorithm is the improved moment shadow if (GetDirectionalShadowAlgorithm() == DirectionalShadowAlgorithm.IMS) { m_CascadeAtlas.ComputeMomentShadows(cmd, hdCamera); } }
HDShadowData CreateShadowData(HDShadowRequest shadowRequest, HDShadowAtlas atlas) { HDShadowData data = new HDShadowData(); var devProj = shadowRequest.deviceProjection; var view = shadowRequest.view; data.proj = new Vector4(devProj.m00, devProj.m11, devProj.m22, devProj.m23); data.pos = shadowRequest.position; data.rot0 = new Vector3(view.m00, view.m01, view.m02); data.rot1 = new Vector3(view.m10, view.m11, view.m12); data.rot2 = new Vector3(view.m20, view.m21, view.m22); data.shadowToWorld = shadowRequest.shadowToWorld; data.cacheTranslationDelta = new Vector3(0.0f, 0.0f, 0.0f); // Compute the scale and offset (between 0 and 1) for the atlas coordinates float rWidth = 1.0f / atlas.width; float rHeight = 1.0f / atlas.height; data.atlasOffset = Vector2.Scale(new Vector2(rWidth, rHeight), new Vector2(shadowRequest.atlasViewport.x, shadowRequest.atlasViewport.y)); data.shadowMapSize = new Vector4(shadowRequest.atlasViewport.width, shadowRequest.atlasViewport.height, 1.0f / shadowRequest.atlasViewport.width, 1.0f / shadowRequest.atlasViewport.height); data.viewBias = shadowRequest.viewBias; data.normalBias = shadowRequest.normalBias; data.flags = shadowRequest.flags; data.edgeTolerance = shadowRequest.edgeTolerance; data.shadowFilterParams0.x = shadowRequest.shadowSoftness; data.shadowFilterParams0.y = HDShadowUtils.Asfloat(shadowRequest.blockerSampleCount); data.shadowFilterParams0.z = HDShadowUtils.Asfloat(shadowRequest.filterSampleCount); data.shadowFilterParams0.w = shadowRequest.minFilterSize; var hdAsset = (GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset); if (hdAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowQuality == HDShadowQuality.VeryHigh && shadowRequest.lightType == (int)LightType.Directional) { data.shadowFilterParams0.x = shadowRequest.kernelSize; data.shadowFilterParams0.y = shadowRequest.lightAngle; data.shadowFilterParams0.z = shadowRequest.maxDepthBias; } if (atlas.HasBlurredEVSM()) { data.shadowFilterParams0 = shadowRequest.evsmParams; } return(data); }