浏览代码

precompute the list of local light shadows so we only generate the shadow CB if there is at least one local shadow casting light.

/main
Felipe Lira 7 年前
当前提交
ca30e010
共有 1 个文件被更改,包括 25 次插入20 次删除
  1. 45
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs

45
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


Bounds bounds;
bool success = false;
for (int i = 0; i < visibleLights.Count; ++i)
{
VisibleLight shadowLight = visibleLights[i];
if (m_LocalShadowLightIndices.Count >= kMaxLocalPixelLightPerPass)
break;
if (shadowLight.lightType == LightType.Spot && shadowLight.light.shadows != LightShadows.None)
m_LocalShadowLightIndices.Add(i);
}
if (m_LocalShadowLightIndices.Count == 0)
return;
int sliceResolution = GetMaxTileResolutionInAtlas(m_LocalLightShadowAtlasResolution, m_LocalLightShadowAtlasResolution, kMaxLocalPixelLightPerPass);
int sliceResolution = GetMaxTileResolutionInAtlas(m_LocalLightShadowAtlasResolution, m_LocalLightShadowAtlasResolution, m_LocalShadowLightIndices.Count);
int shadowSampling = 0;
RenderTextureDescriptor shadowmapDescriptor = new RenderTextureDescriptor(m_LocalLightShadowAtlasResolution, m_LocalLightShadowAtlasResolution, m_ShadowSettings.shadowmapTextureFormat, kShadowBufferBits);

// LightweightPipeline.SetRenderTarget is meant to be used with camera targets, not shadowmaps
CoreUtils.SetRenderTarget(cmd, m_AdditionalShadowmapRT, ClearFlag.Depth, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor));
int shadowSliceIndex = 0;
for (int i = 0; i < visibleLights.Count; ++i)
for (int i = 0; i < m_LocalShadowLightIndices.Count; ++i)
VisibleLight shadowLight = visibleLights[i];
int shadowLightIndex = m_LocalShadowLightIndices[i];
VisibleLight shadowLight = visibleLights[shadowLightIndex];
if (m_LocalShadowLightIndices.Count >= kMaxLocalPixelLightPerPass)
break;
if (shadowLight.lightType != LightType.Spot || light.shadows == LightShadows.None)
if (!m_CullResults.GetShadowCasterBounds(shadowLightIndex, out bounds))
if (!m_CullResults.GetShadowCasterBounds(i, out bounds))
continue;
var settings = new DrawShadowsSettings(m_CullResults, shadowLightIndex);
var settings = new DrawShadowsSettings(m_CullResults, i);
success = m_CullResults.ComputeSpotShadowMatricesAndCullingPrimitives(i, out view, out proj, out settings.splitData);
success = m_CullResults.ComputeSpotShadowMatricesAndCullingPrimitives(shadowLightIndex, out view, out proj, out settings.splitData);
int atlasX = (shadowSliceIndex % 2) * sliceResolution;
int atlasY = (shadowSliceIndex / 2) * sliceResolution;
int atlasX = (i % 2) * sliceResolution;
int atlasY = (i / 2) * sliceResolution;
SetupShadowSliceTransform(ref shadowSliceRect, sliceResolution, proj, view, out m_LocalLightShadowSlices[shadowSliceIndex]);
RenderShadowSlice(cmd, ref context, ref m_LocalLightShadowSlices[shadowSliceIndex], proj, view, settings);
m_LocalShadowStrength[shadowSliceIndex] = light.shadowStrength;
m_LocalShadowLightIndices.Add(i);
SetupShadowSliceTransform(ref shadowSliceRect, sliceResolution, proj, view, out m_LocalLightShadowSlices[i]);
RenderShadowSlice(cmd, ref context, ref m_LocalLightShadowSlices[i], proj, view, settings);
m_LocalShadowStrength[i] = light.shadowStrength;
shadowSliceIndex++;
}
}

正在加载...
取消
保存