浏览代码

Added support to 9 lights to lightweight. 1 main light + 8 per-object.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
06348311
共有 5 个文件被更改,包括 19 次插入22 次删除
  1. 4
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetInspector.cs
  2. 4
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  3. 14
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc
  4. 15
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  5. 4
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc

4
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetInspector.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 maxPixelLights = new GUIContent("Per-Object Pixel Lights",
"Max amount of dynamic per-object pixel lights.");
"Max amount of pixel lights.");
public static GUIContent enableVertexLightLabel = new GUIContent("Enable Vertex Light",
"Lightweight pipeline support at most 4 vertex lights.");

public static GUIContent attenuationTextureLabel = new GUIContent("Attenuation Texture", "Light attenuation falloff texture");
}
private int kMaxSupportedPixelLights = 5;
private int kMaxSupportedPixelLights = 9;
private SerializedProperty m_LinearRenderingProperty;
private SerializedProperty m_RenderScale;
private SerializedProperty m_MaxPixelLights;

4
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


// Max amount of visible lights. This controls the lights constant buffers in shader but not the max shaded lights.
// Lights are set per-object and the max shaded lights for each object are controlled by the max pixel lights in pipeline asset and kMaxVertexLights.
private static readonly int kMaxVisibleAdditionalLights = 16;
private static readonly int kMaxPerObjectLights = 4;
private static readonly int kMaxPerObjectLights = 8;
private Vector4[] m_LightPositions = new Vector4[kMaxVisibleAdditionalLights];
private Vector4[] m_LightColors = new Vector4[kMaxVisibleAdditionalLights];

lightData.additionalPixelLightsCount = maxPixelLights - 1;
}
lightData.vertexLightsCount = (m_Asset.SupportsVertexLight) ? Math.Min(visibleLightsCount - maxPixelLights, kMaxPerObjectLights) : 0;
lightData.vertexLightsCount = (m_Asset.SupportsVertexLight) ? Math.Min(4, Math.Min(visibleLightsCount - maxPixelLights, kMaxPerObjectLights)) : 0;
lightData.hasAdditionalLights = (lightData.additionalPixelLightsCount + lightData.vertexLightsCount) > 0;
lightData.shadowsRendered = false;
}

14
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc


light.spotDir = _MainLightSpotDir;
// Indexing might have a performance hit for old mobile hardware
#define INITIALIZE_LIGHT(light, lightIndex) \
light.pos = _AdditionalLightPosition[lightIndex]; \
light.color = _AdditionalLightColor[lightIndex]; \
light.atten = _AdditionalLightAttenuationParams[lightIndex]; \
light.spotDir = _AdditionalLightSpotDir[lightIndex]
#define INITIALIZE_LIGHT(light, i) \
half4 indices = (i < 4) ? unity_4LightIndices0 : unity_4LightIndices1; \
int index = (i < 4) ? i : i - 4; \
int lightIndex = indices[index]; \
light.pos = _AdditionalLightPosition[lightIndex]; \
light.color = _AdditionalLightColor[lightIndex]; \
light.atten = _AdditionalLightAttenuationParams[lightIndex]; \
light.spotDir = _AdditionalLightSpotDir[lightIndex]
#if (defined(_MAIN_DIRECTIONAL_LIGHT) || defined(_MAIN_SPOT_LIGHT) || defined(_MAIN_POINT_LIGHT))
#define _MAIN_LIGHT

CBUFFER_START(_PerObject)
half4 unity_LightIndicesOffsetAndCount;
half4 unity_4LightIndices0;
half4 unity_4LightIndices1;
half _Shininess;
CBUFFER_END

15
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


LightInput light;
INITIALIZE_MAIN_LIGHT(light);
half lightAtten = ComputeMainLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
lightAtten *= LIGHTWEIGHT_SHADOW_ATTENUATION(i, _ShadowLightDirection.xyz);
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);

for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput light;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(light, lightIndex);
INITIALIZE_LIGHT(light, lightIter);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
half NdotL = saturate(dot(normal, lightDirection));

LightInput lightInput;
INITIALIZE_MAIN_LIGHT(lightInput);
half lightAtten = ComputeMainLightAttenuation(lightInput, normal, worldPos, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
lightAtten *= LIGHTWEIGHT_SHADOW_ATTENUATION(i, _ShadowLightDirection.xyz);
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color;

for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput lightData;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(lightData, lightIndex);
INITIALIZE_LIGHT(lightData, lightIter);
half lightAtten = ComputeLightAttenuation(lightData, normal, worldPos, lightDirection);
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS

4
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc


#endif
#ifdef _SHADOWS
#define SHADOW_ATTENUATION(vertexOutput, shadowDir) ComputeShadowAttenuation(vertexOutput, shadowDir)
#define LIGHTWEIGHT_SHADOW_ATTENUATION(vertexOutput, shadowDir) ComputeShadowAttenuation(vertexOutput, shadowDir)
#define SHADOW_ATTENUATION(vertexOutput, shadowDir) 1.0h
#define LIGHTWEIGHT_SHADOW_ATTENUATION(vertexOutput, shadowDir) 1.0h
#endif
sampler2D_float _ShadowMap;

正在加载...
取消
保存