浏览代码

Setting up light indices much earliear in the pipeline for better thread scheduling.

/main
Felipe Lira 6 年前
当前提交
84d6783d
共有 2 个文件被更改,包括 42 次插入37 次删除
  1. 75
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl

75
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


lightData.localLightIndices = m_LocalLightIndices;
m_MixedLightingSetup = MixedLightingSetup.None;
if (lightData.totalAdditionalLightsCount > 0)
{
int[] perObjectLightIndexMap = m_CullResults.GetLightIndexMap();
int directionalLightCount = 0;
// Disable all directional lights from the perobject light indices
for (int i = 0; i < visibleLights.Count; ++i)
{
VisibleLight light = visibleLights[i];
if (light.lightType == LightType.Directional)
perObjectLightIndexMap[i] = -1;
else
perObjectLightIndexMap[i] -= directionalLightCount;
}
m_CullResults.SetLightIndexMap(perObjectLightIndexMap);
// if not using a compute buffer, engine will set indices in 2 vec4 constants
// unity_4LightIndices0 and unity_4LightIndices1
if (m_UseComputeBuffer)
{
int lightIndicesCount = m_CullResults.GetLightIndicesCount();
if (lightIndicesCount > 0)
{
if (m_LightIndicesBuffer == null)
{
m_LightIndicesBuffer = new ComputeBuffer(lightIndicesCount, sizeof(int));
}
else if (m_LightIndicesBuffer.count < lightIndicesCount)
{
m_LightIndicesBuffer.Release();
m_LightIndicesBuffer = new ComputeBuffer(lightIndicesCount, sizeof(int));
}
m_CullResults.FillLightIndices(m_LightIndicesBuffer);
}
}
}
}
// Main Light is always a directional light

List<VisibleLight> lights = lightData.visibleLights;
if (lightData.totalAdditionalLightsCount > 0)
{
// We need to update per-object light list with the proper map to our global additional light buffer
// First we initialize all lights in the map to -1 to tell the system to discard main light index and
// remaining lights in the scene that don't fit the max additional light buffer (kMaxVisibileAdditionalLights)
int[] perObjectLightIndexMap = m_CullResults.GetLightIndexMap();
int directionalLightCount = 0;
if (light.lightType == LightType.Directional)
{
perObjectLightIndexMap[i] = -1;
directionalLightCount++;
}
else
if (light.lightType != LightType.Directional)
perObjectLightIndexMap[i] -= directionalLightCount;
InitializeLightConstants(lights, i, out m_LightPositions[localLightsCount],
out m_LightColors[localLightsCount],
out m_LightDistanceAttenuations[localLightsCount],

}
}
m_CullResults.SetLightIndexMap(perObjectLightIndexMap);
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount,
lightData.totalAdditionalLightsCount, 0.0f, 0.0f));

// TODO: We can benefit from better thread usage if we set LightIndex map and call
// FillLightIndices way earlier.
{
int lightIndicesCount = m_CullResults.GetLightIndicesCount();
if (lightIndicesCount > 0)
{
if (m_LightIndicesBuffer == null)
{
m_LightIndicesBuffer = new ComputeBuffer(lightIndicesCount, sizeof(int));
}
else if (m_LightIndicesBuffer.count < lightIndicesCount)
{
m_LightIndicesBuffer.Release();
m_LightIndicesBuffer = new ComputeBuffer(lightIndicesCount, sizeof(int));
}
m_CullResults.FillLightIndices(m_LightIndicesBuffer);
cmd.SetGlobalBuffer(PerCameraBuffer._LightIndexBuffer, m_LightIndicesBuffer);
}
}
cmd.SetGlobalBuffer("_LightIndexBuffer", m_LightIndicesBuffer);
}
else
{

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl


half4 _AdditionalLightSpotAttenuation[MAX_VISIBLE_LIGHTS];
float4 _ScaledScreenParams;
CBUFFER_END
#if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA
#endif
CBUFFER_END
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject

正在加载...
取消
保存