浏览代码

GC fix (saves 4.9KB/frame)

/main
Thomas 7 年前
当前提交
77910e79
共有 2 个文件被更改,包括 20 次插入6 次删除
  1. 12
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 14
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs

12
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


// and per-object light lists.
private List<int> m_SortedLightIndexMap = new List<int>();
private Dictionary<VisibleLight, int> m_VisibleLightsIDMap = new Dictionary<VisibleLight, int>(new LightEqualityComparer());
private Mesh m_BlitQuad;
private Material m_BlitMaterial;
private Material m_CopyDepthMaterial;

{
int totalVisibleLights = visibleLights.Length;
Dictionary<int, int> visibleLightsIDMap = new Dictionary<int, int>();
m_VisibleLightsIDMap.Clear();
visibleLightsIDMap.Add(visibleLights[i].GetHashCode(), i);
m_VisibleLightsIDMap.Add(visibleLights[i], i);
// Sorts light so we have all directionals first, then local lights.
// Directionals are sorted further by shadow, cookie and intensity

for (int i = 0; i < totalVisibleLights; ++i)
m_SortedLightIndexMap.Add(visibleLightsIDMap[visibleLights[i].GetHashCode()]);
m_SortedLightIndexMap.Add(m_VisibleLightsIDMap[visibleLights[i]]);
return GetMainLight(visibleLights);
}

bias = light.shadowBias * proj.m22 * 0.5f * sign;
// Currently only square POT cascades resolutions are used.
// We scale normalBias
// We scale normalBias
double frustumWidth = 2.0 / (double)proj.m00;
double frustumHeight = 2.0 / (double)proj.m11;
float texelSizeX = (float)(frustumWidth / (double)cascadeResolution);

worldToShadow = cascadeAtlas * worldToShadow;
m_ShadowSlices[cascadeIndex].atlasX = atlasX;
m_ShadowSlices[cascadeIndex].atlasY = atlasY;
m_ShadowSlices[cascadeIndex].atlasY = atlasY;
m_ShadowSlices[cascadeIndex].shadowResolution = shadowResolution;
m_ShadowSlices[cascadeIndex].shadowTransform = worldToShadow;
}

14
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

{
Vector3 lightCameraVector = lightPos - CurrCamera.transform.position;
return Vector3.Dot(lightCameraVector, lightCameraVector);
}
}
public class LightEqualityComparer : IEqualityComparer<VisibleLight>
{
public bool Equals(VisibleLight x, VisibleLight y)
{
return x.light.GetInstanceID() == y.light.GetInstanceID();
}
public int GetHashCode(VisibleLight obj)
{
return obj.light.GetInstanceID();
}
}

正在加载...
取消
保存