浏览代码

Changed lightweight asset to define total amount of pixel lights instead of additional pixel lights. That was confusing for most people. Also limited vertex light to 4.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
2afc78cf
共有 4 个文件被更改,包括 42 次插入38 次删除
  1. 14
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetEditor.cs
  2. 57
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  3. 7
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.cs
  4. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc

14
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetEditor.cs


public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Allows game to render at a resolution different than native resolution. UI is always rendered at native resolution.");
public static GUIContent maxAdditionalPixelLightsLabel = new GUIContent("Max Additional Pixel Lights",
"Controls the additional per-pixel lights that run in fragment light loop.");
public static GUIContent maxPixelLightsLabel = new GUIContent("Max Pixel Lights",
"Controls the amount of pixel lights that run in fragment light loop. Lights are sorted and culled per-object.");
public static GUIContent enableVertexLightLabel = new GUIContent("Enable Vertex Light",
"If enabled, shades additional lights exceeding maxAdditionalPixelLights per-vertex up to the maximum of 8 lights.");

public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing applied to all cameras.");
}
private int kMaxSupportedAdditionalPixelLights = 8;
private int kMaxSupportedPixelLights = 8;
private SerializedProperty m_MaxAdditionalPixelLights;
private SerializedProperty m_MaxPixelLights;
private SerializedProperty m_SupportsVertexLightProp;
private SerializedProperty m_SupportSoftParticlesProp;
private SerializedProperty m_ShadowTypeProp;

void OnEnable()
{
m_RenderScale = serializedObject.FindProperty("m_RenderScale");
m_MaxAdditionalPixelLights = serializedObject.FindProperty("m_MaxAdditionalPixelLights");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");
m_SupportSoftParticlesProp = serializedObject.FindProperty("m_SupportSoftParticles");
m_ShadowTypeProp = serializedObject.FindProperty("m_ShadowType");

m_RenderScale.floatValue = EditorGUILayout.Slider(m_RenderScale.floatValue, 0.1f, 1.0f);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.maxAdditionalPixelLightsLabel);
m_MaxAdditionalPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxAdditionalPixelLights.intValue, 0, kMaxSupportedAdditionalPixelLights);
EditorGUILayout.LabelField(Styles.maxPixelLightsLabel);
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxPixelLights.intValue, 0, kMaxSupportedPixelLights);
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(m_SupportsVertexLightProp, Styles.enableVertexLightLabel);
EditorGUILayout.PropertyField(m_SupportSoftParticlesProp, Styles.enableSoftParticles);

57
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


// Maximum amount of visible lights the shader can process. This controls the constant global light buffer size.
// It must match the MAX_VISIBLE_LIGHTS in LightweightInput.cginc
private static readonly int kMaxVisibleAdditionalLights = 16;
private static readonly int kMaxVisibleLights = 16;
// Lights are culled per-object. This holds the maximum amount of additional lights that can shade each object.
// Lights are culled per-object. This holds the maximum amount of lights that can be shaded per-object.
private static readonly int kMaxPerObjectAdditionalLights = 8;
private static readonly int kMaxPerObjectLights = 8;
private static readonly int kMaxVertexLights = 4;
private Vector4[] m_LightPositions = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightColors = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightDistanceAttenuations = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightSpotDirections = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightSpotAttenuations = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightPositions = new Vector4[kMaxVisibleLights];
private Vector4[] m_LightColors = new Vector4[kMaxVisibleLights];
private Vector4[] m_LightDistanceAttenuations = new Vector4[kMaxVisibleLights];
private Vector4[] m_LightSpotDirections = new Vector4[kMaxVisibleLights];
private Vector4[] m_LightSpotAttenuations = new Vector4[kMaxVisibleLights];
private Camera m_CurrCamera;

private void InitializeLightData(VisibleLight[] visibleLights, out LightData lightData)
{
int visibleLightsCount = visibleLights.Length;
int visibleLightsCount = Math.Min(visibleLights.Length, m_Asset.MaxPixelLights);
m_SortedLightIndexMap.Clear();
lightData.shadowsRendered = false;

lightData.mainLightIndex = SortLights(visibleLights);
// If we have a main light we don't shade it in the per-object light loop. We also remove it from the per-object cull list
int additionalLightsCount = (lightData.mainLightIndex >= 0) ? visibleLightsCount - 1 : visibleLightsCount;
additionalLightsCount = Math.Min(additionalLightsCount, kMaxPerObjectAdditionalLights);
int mainLightPresent = (lightData.mainLightIndex >= 0) ? 1 : 0;
int additionalPixelLightsCount = visibleLightsCount - mainLightPresent;
int vertexLightCount = (m_Asset.SupportsVertexLight) ? Math.Min(visibleLights.Length, kMaxPerObjectLights) - additionalPixelLightsCount : 0;
vertexLightCount = Math.Min(vertexLightCount, kMaxVertexLights);
int pixelLightsCount = Math.Min(additionalLightsCount, m_Asset.MaxAdditionalPixelLights);
int vertexLightCount = (m_Asset.SupportsVertexLight) ? additionalLightsCount - pixelLightsCount : 0;
lightData.pixelAdditionalLightsCount = pixelLightsCount;
lightData.totalAdditionalLightsCount = pixelLightsCount + vertexLightCount;
lightData.pixelAdditionalLightsCount = additionalPixelLightsCount;
lightData.totalAdditionalLightsCount = additionalPixelLightsCount + vertexLightCount;
m_MixedLightingSetup = MixedLightingSetup.None;
}

int totalVisibleLights = visibleLights.Length;
bool shadowsEnabled = m_Asset.AreShadowsEnabled();
if (totalVisibleLights == 0)
if (totalVisibleLights == 0 || m_Asset.MaxPixelLights == 0)
return -1;
int brighestDirectionalIndex = -1;

for (int i = 0; i < lights.Length; ++i)
perObjectLightIndexMap[i] = -1;
for (int i = 0; i < lights.Length && additionalLightIndex < kMaxVisibleAdditionalLights; ++i)
for (int i = 0; i < lights.Length && additionalLightIndex < kMaxVisibleLights; ++i)
{
if (i != lightData.mainLightIndex)
{

}
m_CullResults.SetLightIndexMap(perObjectLightIndexMap);
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4 (lightData.pixelAdditionalLightsCount,
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount,
cmd.SetGlobalVectorArray (PerCameraBuffer._AdditionalLightPosition, m_LightPositions);
cmd.SetGlobalVectorArray (PerCameraBuffer._AdditionalLightColor, m_LightColors);
cmd.SetGlobalVectorArray (PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations);
cmd.SetGlobalVectorArray (PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections);
cmd.SetGlobalVectorArray (PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations);
}
private void SetupShadowShaderConstants(CommandBuffer cmd, ref VisibleLight shadowLight, int cascadeCount)

// Currently only directional light cookie is supported
CoreUtils.SetKeyword(cmd, "_MAIN_LIGHT_COOKIE", mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
CoreUtils.SetKeyword (cmd, "_MAIN_DIRECTIONAL_LIGHT", mainLightIndex == -1 || visibleLights[mainLightIndex].lightType == LightType.Directional);
CoreUtils.SetKeyword (cmd, "_MAIN_SPOT_LIGHT", mainLightIndex != -1 && visibleLights[mainLightIndex].lightType == LightType.Spot);
CoreUtils.SetKeyword(cmd, "_MAIN_DIRECTIONAL_LIGHT", mainLightIndex == -1 || visibleLights[mainLightIndex].lightType == LightType.Directional);
CoreUtils.SetKeyword(cmd, "_MAIN_SPOT_LIGHT", mainLightIndex != -1 && visibleLights[mainLightIndex].lightType == LightType.Spot);
CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SHADOWMASK", m_MixedLightingSetup == MixedLightingSetup.ShadowMask);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive);

clearFlag |= ClearFlag.Color;
}
SetRenderTarget (cmd, colorRT, depthRT, clearFlag);
SetRenderTarget(cmd, colorRT, depthRT, clearFlag);
}
context.ExecuteCommandBuffer(cmd);

{
if (depthRT == BuiltinRenderTextureType.None)
{
SetRenderTarget (cmd, colorRT, clearFlag);
SetRenderTarget(cmd, colorRT, clearFlag);
return;
}

7
ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.cs


public static readonly string m_SimpleLightShaderPath = "LightweightPipeline/Standard (Simple Lighting)";
public static readonly string m_StandardShaderPath = "LightweightPipeline/Standard (Physically Based)";
[SerializeField] private int m_MaxAdditionalPixelLights = 4;
// Default values set when a new LightweightPipeline asset is created
[SerializeField] private int m_MaxPixelLights = 4;
[SerializeField] private bool m_SupportsVertexLight = false;
[SerializeField] private bool m_SupportSoftParticles = false;
[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;

return ShadowSetting != ShadowType.NO_SHADOW;
}
public int MaxAdditionalPixelLights
public int MaxPixelLights
get { return m_MaxAdditionalPixelLights; }
get { return m_MaxPixelLights; }
}
public bool SupportsVertexLight

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


{
float4 uv01 : TEXCOORD0; // xy: main UV, zw: lightmap UV (directional / non-directional)
float3 posWS : TEXCOORD1;
#if _NORMALMAP
half3 tangent : TEXCOORD2;
half3 binormal : TEXCOORD3;

#endif
half3 viewDir : TEXCOORD5;
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light

正在加载...
取消
保存