浏览代码

GC fix (saves 188B/frame)

Ultimately `SetShaderKeywords` should be done differently.
/main
Thomas 7 年前
当前提交
d798451c
共有 1 个文件被更改,包括 27 次插入24 次删除
  1. 51
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs

51
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private static readonly int kMaxVertexLights = 4;
// We have no good approach exposed to skip shader variants, e.g, ideally we would like to skip _CASCADE for all punctual lights
// We combine light and shadow classification keywords to reduce the amount of shader variants.
// Lightweight shader library declares defines based on these keywords to avoid having to check them in the shaders
// Core.hlsl defines _MAIN_LIGHT_DIRECTIONAL and _MAIN_LIGHT_SPOT (point lights can't be main light)
// Shadow.hlsl defines _SHADOWS_ENABLED, _SHADOWS_SOFT, _SHADOWS_CASCADE, _SHADOWS_PERSPECTIVE
private static readonly string[] kMainLightKeywords =
{
"_MAIN_LIGHT_DIRECTIONAL_SHADOW",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_SOFT",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE_SOFT",
"_MAIN_LIGHT_SPOT_SHADOW",
"_MAIN_LIGHT_SPOT_SHADOW_SOFT"
};
private StringBuilder m_MainLightKeywordString = new StringBuilder(43);
private bool m_IsOffscreenCamera;
private Vector4[] m_LightPositions = new Vector4[kMaxVisibleLights];

int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount;
int mainLightIndex = lightData.mainLightIndex;
// We have no good approach exposed to skip shader variants, e.g, ideally we would like to skip _CASCADE for all punctual lights
// We combine light and shadow classification keywords to reduce the amount of shader variants.
// Lightweight shader library declares defines based on these keywords to avoid having to check them in the shaders
// Core.hlsl defines _MAIN_LIGHT_DIRECTIONAL and _MAIN_LIGHT_SPOT (point lights can't be main light)
// Shadow.hlsl defines _SHADOWS_ENABLED, _SHADOWS_SOFT, _SHADOWS_CASCADE, _SHADOWS_PERSPECTIVE
string[] mainLightKeywords =
{
"_MAIN_LIGHT_DIRECTIONAL_SHADOW",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_SOFT",
"_MAIN_LIGHT_DIRECTIONAL_SHADOW_CASCADE_SOFT",
"_MAIN_LIGHT_SPOT_SHADOW",
"_MAIN_LIGHT_SPOT_SHADOW_SOFT"
};
for (int i = 0; i < mainLightKeywords.Length; ++i)
cmd.DisableShaderKeyword(mainLightKeywords[i]);
for (int i = 0; i < kMainLightKeywords.Length; ++i)
cmd.DisableShaderKeyword(kMainLightKeywords[i]);
StringBuilder keywordString = new StringBuilder("_MAIN_LIGHT");
m_MainLightKeywordString.Length = 0;
m_MainLightKeywordString.Append("_MAIN_LIGHT");
keywordString.Append("_DIRECTIONAL_SHADOW");
m_MainLightKeywordString.Append("_DIRECTIONAL_SHADOW");
keywordString.Append("_CASCADE");
m_MainLightKeywordString.Append("_CASCADE");
keywordString.Append("_SPOT_SHADOW");
m_MainLightKeywordString.Append("_SPOT_SHADOW");
keywordString.Append("_SOFT");
string keyword = keywordString.ToString();
m_MainLightKeywordString.Append("_SOFT");
string keyword = m_MainLightKeywordString.ToString();
cmd.EnableShaderKeyword(keyword);
}

正在加载...
取消
保存