浏览代码

Initial refactor work on shader library to allow reuse passes/core for multiple shaders with minimal work.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
bd25fe30
共有 18 个文件被更改,包括 306 次插入330 次删除
  1. 159
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShaderPBS.shader
  2. 184
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader
  3. 6
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  4. 4
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc
  5. 245
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  6. 9
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc.meta
  7. 20
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassShadow.cginc
  8. 9
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassShadow.cginc.meta
  9. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBRDF.cginc
  10. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBRDF.cginc.meta
  11. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc.meta
  12. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc
  13. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc.meta
  14. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  15. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc.meta
  16. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc.meta
  17. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  18. 0
      /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc

159
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShaderPBS.shader


#pragma multi_compile_fog
#pragma multi_compile_instancing
#pragma vertex LightweightVertex
#pragma fragment LightweightFragment
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#include "LightweightPipelineCore.cginc"
#include "LightweightPipelineLighting.cginc"
#include "LightweightPipelineBRDF.cginc"
LightweightVertexOutput LightweightVertex(LightweightVertexInput v)
{
LightweightVertexOutput o = (LightweightVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;
half3 viewDir = normalize(_WorldSpaceCameraPos - worldPos);
o.viewDir.xyz = viewDir;
half3 normal = normalize(UnityObjectToWorldNormal(v.normal));
#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = UnityObjectToWorldDir(v.tangent);
half3 binormal = cross(normal, tangent) * sign;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
o.tangentToWorld0 = half3(tangent.x, binormal.x, normal.x);
o.tangentToWorld1 = half3(tangent.y, binormal.y, normal.y);
o.tangentToWorld2 = half3(tangent.z, binormal.z, normal.z);
#else
o.normal = normal;
#endif
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON)
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}
half4 LightweightFragment(LightweightVertexOutput i) : SV_Target
{
float2 uv = i.uv01.xy;
float2 lightmapUV = i.uv01.zw;
half4 albedoTex = tex2D(_MainTex, i.uv01.xy);
half3 albedo = LIGHTWEIGHT_GAMMA_TO_LINEAR(albedoTex.rgb) * _Color.rgb;
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
half alpha = _Color.a;
#else
half alpha = albedoTex.a * _Color.a;
#endif
#if defined(_ALPHATEST_ON)
clip(alpha - _Cutoff);
#endif
half3 specColor;
half smoothness;
half oneMinusReflectivity;
#ifdef _METALLIC_SETUP
half3 diffColor = MetallicSetup(uv, albedo, alpha, specColor, smoothness, oneMinusReflectivity);
#else
half3 diffColor = SpecularSetup(uv, albedo, alpha, specColor, smoothness, oneMinusReflectivity);
#endif
diffColor = PreMultiplyAlpha(diffColor, alpha, oneMinusReflectivity, /*out*/ alpha);
// Roughness is (1.0 - smoothness)²
half perceptualRoughness = 1.0h - smoothness;
half3 normal;
NormalMap(i, normal);
// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half occlusion = Occlusion(uv);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, reflectVec, occlusion, perceptualRoughness);
// PBS
// grazingTerm = F90
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS
LightInput light;
INITIALIZE_MAIN_LIGHT(light);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
#else
#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput light;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(light, lightIndex);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
#ifdef _SHADOWS
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
}
#endif
color += Emission(uv);
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
}
#include "LightweightPassLit.cginc"
ENDCG
}

CGPROGRAM
#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
float4 vert(float4 pos : POSITION) : SV_POSITION
{
float4 clipPos = UnityObjectToClipPos(pos);
#if defined(UNITY_REVERSED_Z)
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#endif
return clipPos;
}
half4 frag() : SV_TARGET
{
return 0;
}
#include "LightweightPassShadow.cginc"
ENDCG
}

184
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader


CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
#pragma shader_feature _ _SPECGLOSSMAP _SPECGLOSSMAP_BASE_ALPHA _SPECULAR_COLOR
#pragma shader_feature _NORMALMAP

#pragma multi_compile_fog
#pragma multi_compile_instancing
#pragma vertex LitPassVertex
#pragma fragment LitPassFragmentSimple
#include "LightweightPipelineCore.cginc"
#include "LightweightPipelineLighting.cginc"
LightweightVertexOutput vert(LightweightVertexInput v)
{
LightweightVertexOutput o = (LightweightVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos);
half3 normal = normalize(UnityObjectToWorldNormal(v.normal));
#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = normalize(UnityObjectToWorldDir(v.tangent));
half3 binormal = cross(normal, tangent) * v.tangent.w;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
o.tangentToWorld0 = half3(tangent.x, binormal.x, normal.x);
o.tangentToWorld1 = half3(tangent.y, binormal.y, normal.y);
o.tangentToWorld2 = half3(tangent.z, binormal.z, normal.z);
#else
o.normal = normal;
#endif
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU
#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS)
half3 diffuse = half3(1.0, 1.0, 1.0);
// pixel lights shaded = min(pixelLights, perObjectLights)
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights)
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter)
{
int lightIndex = unity_4LightIndices0[lightIter];
LightInput lightInput;
INITIALIZE_LIGHT(lightInput, lightIndex);
half3 lightDirection;
half atten = ComputeLightAttenuationVertex(lightInput, normal, worldPos, lightDirection);
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten);
}
#endif
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON)
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}
half4 frag(LightweightVertexOutput i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff
// due overdraw performance impact.
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif
half3 normal;
NormalMap(i, normal);
half4 specularGloss;
SpecularGloss(i.uv01.xy, alpha, specularGloss);
half3 viewDir = i.viewDir.xyz;
float3 worldPos = i.posWS.xyz;
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS
LightInput lightInput;
INITIALIZE_MAIN_LIGHT(lightInput);
half lightAtten = ComputeLightAttenuation(lightInput, normal, worldPos, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
half3 color = LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color;
#else
half3 color = LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightInput.color;
#endif
#else
half3 color = half3(0, 0, 0);
#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput lightData;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(lightData, lightIndex);
half lightAtten = ComputeLightAttenuation(lightData, normal, worldPos, lightDirection);
#ifdef _SHADOWS
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color;
#else
color += LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightData.color;
#endif
}
#endif // _MULTIPLE_LIGHTS
#ifdef _EMISSION
color += LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, i.uv01.xy).rgb) * _EmissionColor;
#else
color += _EmissionColor;
#endif
#if defined(LIGHTMAP_ON)
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse;
#elif defined(_VERTEX_LIGHTS) || defined(_LIGHT_PROBES_ON)
color += i.fogCoord.yzw * diffuse;
#endif
#if _REFLECTION_CUBEMAP
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
color += texCUBE(_Cube, reflectVec).rgb * specularGloss.rgb;
#elif defined(_REFLECTION_PROBE)
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half4 reflectionProbe = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectVec);
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * specularGloss.rgb;
#endif
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
};
#include "LightweightPassLit.cginc"
Pass
Pass
Tags { "Lightmode" = "ShadowCaster" }
Tags{"Lightmode" = "ShadowCaster"}
#pragma vertex vert
#pragma fragment frag
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
float4 vert(float4 pos : POSITION) : SV_POSITION
{
float4 clipPos = UnityObjectToClipPos(pos);
#if defined(UNITY_REVERSED_Z)
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#endif
return clipPos;
}
half4 frag() : SV_TARGET
{
return 0;
}
#include "LightweightPassShadow.cginc"
ENDCG
}

#pragma shader_feature EDITOR_VISUALIZATION
#include "UnityStandardMeta.cginc"
#include "LightweightPipelineCore.cginc"
#include "LightweightCore.cginc"
fixed4 frag_meta_ld(v2f_meta i) : SV_Target
{

6
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc


#ifndef LIGHTWEIGHT_PIPELINE_CORE_INCLUDED
#define LIGHTWEIGHT_PIPELINE_CORE_INCLUDED
#include "LightweightPipelineInput.cginc"
#include "LightweightInput.cginc"
#include "LightweightLighting.cginc"
#include "LightweightBRDF.cginc"
#if defined(_HARD_SHADOWS) || defined(_SOFT_SHADOWS) || defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES)
#define _SHADOWS

#endif
#ifdef _SHADOWS
#include "LightweightPipelineShadows.cginc"
#include "LightweightShadows.cginc"
#endif
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)

4
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc


#ifndef LIGHTWEIGHT_SHADOWS_INCLUDED
#define LIGHTWEIGHT_SHADOWS_INCLUDED
#define MAX_SHADOW_CASCADES 4
sampler2D_float _ShadowMap;

return ShadowAttenuation(shadowCoord.xyz);
#endif
}
#endif

245
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


#ifndef LIGHTWEIGHT_PASS_LIT_INCLUDED
#define LIGHTWEIGHT_PASS_LIT_INCLUDED
#include "LightweightCore.cginc"
LightweightVertexOutput LitPassVertex(LightweightVertexInput v)
{
LightweightVertexOutput o = (LightweightVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;
half3 viewDir = normalize(_WorldSpaceCameraPos - worldPos);
o.viewDir.xyz = viewDir;
half3 normal = normalize(UnityObjectToWorldNormal(v.normal));
#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = UnityObjectToWorldDir(v.tangent);
half3 binormal = cross(normal, tangent) * sign;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
o.tangentToWorld0 = half3(tangent.x, binormal.x, normal.x);
o.tangentToWorld1 = half3(tangent.y, binormal.y, normal.y);
o.tangentToWorld2 = half3(tangent.z, binormal.z, normal.z);
#else
o.normal = normal;
#endif
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU
//#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS)
// half3 diffuse = half3(1.0, 1.0, 1.0);
// // pixel lights shaded = min(pixelLights, perObjectLights)
// // vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded
// // Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights)
// int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
// int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y);
// for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter)
// {
// int lightIndex = unity_4LightIndices0[lightIter];
// LightInput lightInput;
// INITIALIZE_LIGHT(lightInput, lightIndex);
//
// half3 lightDirection;
// half atten = ComputeLightAttenuationVertex(lightInput, normal, worldPos, lightDirection);
// o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten);
// }
//#endif
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON)
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}
half4 LitPassFragment(LightweightVertexOutput i) : SV_Target
{
float2 uv = i.uv01.xy;
float2 lightmapUV = i.uv01.zw;
half4 albedoTex = tex2D(_MainTex, i.uv01.xy);
half3 albedo = LIGHTWEIGHT_GAMMA_TO_LINEAR(albedoTex.rgb) * _Color.rgb;
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
half alpha = _Color.a;
#else
half alpha = albedoTex.a * _Color.a;
#endif
#if defined(_ALPHATEST_ON)
clip(alpha - _Cutoff);
#endif
half3 specColor;
half smoothness;
half oneMinusReflectivity;
#ifdef _METALLIC_SETUP
half3 diffColor = MetallicSetup(uv, albedo, alpha, specColor, smoothness, oneMinusReflectivity);
#else
half3 diffColor = SpecularSetup(uv, albedo, alpha, specColor, smoothness, oneMinusReflectivity);
#endif
diffColor = PreMultiplyAlpha(diffColor, alpha, oneMinusReflectivity, /*out*/ alpha);
// Roughness is (1.0 - smoothness)�
half perceptualRoughness = 1.0h - smoothness;
half3 normal;
NormalMap(i, normal);
// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half occlusion = Occlusion(uv);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, reflectVec, occlusion, perceptualRoughness);
// PBS
// grazingTerm = F90
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS
LightInput light;
INITIALIZE_MAIN_LIGHT(light);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
#else
#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput light;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(light, lightIndex);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
#ifdef _SHADOWS
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
}
#endif
color += Emission(uv);
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
}
half4 LitPassFragmentSimple(LightweightVertexOutput i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff
// due overdraw performance impact.
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif
half3 normal;
NormalMap(i, normal);
half4 specularGloss;
SpecularGloss(i.uv01.xy, alpha, specularGloss);
half3 viewDir = i.viewDir.xyz;
float3 worldPos = i.posWS.xyz;
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS
LightInput lightInput;
INITIALIZE_MAIN_LIGHT(lightInput);
half lightAtten = ComputeLightAttenuation(lightInput, normal, worldPos, lightDirection);
#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
half3 color = LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color;
#else
half3 color = LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightInput.color;
#endif
#else
half3 color = half3(0, 0, 0);
#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput lightData;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(lightData, lightIndex);
half lightAtten = ComputeLightAttenuation(lightData, normal, worldPos, lightDirection);
#ifdef _SHADOWS
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color;
#else
color += LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightData.color;
#endif
}
#endif // _MULTIPLE_LIGHTS
#ifdef _EMISSION
color += LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, i.uv01.xy).rgb) * _EmissionColor;
#else
color += _EmissionColor;
#endif
#if defined(LIGHTMAP_ON)
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse;
#elif defined(_VERTEX_LIGHTS) || defined(_LIGHT_PROBES_ON)
color += i.fogCoord.yzw * diffuse;
#endif
#if _REFLECTION_CUBEMAP
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
color += texCUBE(_Cube, reflectVec).rgb * specularGloss.rgb;
#elif defined(_REFLECTION_PROBE)
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half4 reflectionProbe = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectVec);
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * specularGloss.rgb;
#endif
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
};
#endif

9
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc.meta


fileFormatVersion: 2
guid: 116bd973269b9f741b7177c8523b9e50
timeCreated: 1488965025
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

20
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassShadow.cginc


#ifndef LIGHTWEIGHT_PASS_SHADOW_INCLUDED
#define LIGHTWEIGHT_PASS_SHADOW_INCLUDED
float4 ShadowPassVertex(float4 pos : POSITION) : SV_POSITION
{
float4 clipPos = UnityObjectToClipPos(pos);
#if defined(UNITY_REVERSED_Z)
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#endif
return clipPos;
}
half4 ShadowPassFragment() : SV_TARGET
{
return 0;
}
#endif

9
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassShadow.cginc.meta


fileFormatVersion: 2
guid: 9a48a2987a0e11645adf07fe4a8d5ec9
timeCreated: 1488965025
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBRDF.cginc

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc.meta → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBRDF.cginc.meta

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc.meta → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc.meta

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc.meta → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc.meta

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc.meta → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc.meta

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineShadows.cginc.meta → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc.meta

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc

/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineShadows.cginc → /ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc

正在加载...
取消
保存