|
|
|
|
|
|
#pragma vertex vert |
|
|
|
#pragma fragment frag |
|
|
|
#pragma shader_feature _SPECGLOSSMAP |
|
|
|
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|
|
|
#pragma shader_feature _NORMALMAP |
|
|
|
|
|
|
|
#pragma multi_compile _ LIGHTMAP_ON |
|
|
|
|
|
|
#if defined(UNITY_REVERSED_Z) |
|
|
|
return step(depth, shadowCoordDepth); |
|
|
|
#else |
|
|
|
return step(shadowCoordDepth, depth); |
|
|
|
return step(shadowCoordDepth, depth); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
return attenuation * 0.25; |
|
|
|
} |
|
|
|
|
|
|
|
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half3 specularColor, half3 normal, float3 posWorld, half3 viewDir) |
|
|
|
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float3 posWorld, half3 viewDir) |
|
|
|
{ |
|
|
|
float3 posToLight = lightInput.pos.xyz; |
|
|
|
posToLight -= posWorld * lightInput.pos.w; |
|
|
|
|
|
|
|
|
|
|
half3 lightColor = lightInput.color.rgb * lightAtten; |
|
|
|
half3 diffuse = diffuseColor * lightColor * NdotL; |
|
|
|
half3 specular = specularColor * lightColor * pow(NdotH, 128.0f) * _Glossiness; |
|
|
|
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, 64.0f) * specularGloss.a; |
|
|
|
inline half3 EvaluateMainLight(LightInput lightInput, half3 diffuseColor, half3 specularColor, half3 normal, float4 posWorld, half3 viewDir) |
|
|
|
inline half3 EvaluateMainLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float4 posWorld, half3 viewDir) |
|
|
|
{ |
|
|
|
int cascadeIndex = ComputeCascadeIndex(posWorld.w); |
|
|
|
float4 shadowCoord = mul(_WorldToShadow[cascadeIndex], float4(posWorld.xyz, 1.0)); |
|
|
|
|
|
|
return cascadeColors[cascadeIndex] * diffuseColor * max(shadowAttenuation, 0.5); |
|
|
|
#endif |
|
|
|
|
|
|
|
half3 color = EvaluateOneLight(lightInput, diffuseColor, specularColor, normal, posWorld, viewDir); |
|
|
|
half3 color = EvaluateOneLight(lightInput, diffuseColor, specularGloss, normal, posWorld, viewDir); |
|
|
|
|
|
|
|
#ifdef SHADOWS_DEPTH |
|
|
|
return color * shadowAttenuation; |
|
|
|
|
|
|
o.normal = normal; |
|
|
|
#endif |
|
|
|
|
|
|
|
half3 diffuseAndSpecularColor = half3(1.0, 1.0, 1.0); |
|
|
|
half4 diffuseAndSpecular = half4(1.0, 1.0, 1.0, 1.0); |
|
|
|
o.fogCoord.yzw += EvaluateOneLight(lightInput, diffuseAndSpecularColor, diffuseAndSpecularColor, normal, o.posWS.xyz, o.viewDir.xyz); |
|
|
|
o.fogCoord.yzw += EvaluateOneLight(lightInput, diffuseAndSpecular.rgb, diffuseAndSpecular, normal, o.posWS.xyz, o.viewDir.xyz); |
|
|
|
} |
|
|
|
|
|
|
|
#ifndef LIGHTMAP_ON |
|
|
|
|
|
|
#else |
|
|
|
half3 normal = normalize(i.normal); |
|
|
|
#endif |
|
|
|
|
|
|
|
float3 posWorld = i.posWS.xyz; |
|
|
|
half3 viewDir = i.viewDir.xyz; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
half4 specGloss = SpecularGloss(i.uv01.xy); |
|
|
|
half3 specular = specGloss.rgb; |
|
|
|
half smoothness = specGloss.a; |
|
|
|
|
|
|
|
half oneMinusReflectivity; |
|
|
|
half4 specularGloss = SpecularGloss(i.uv01.xy); |
|
|
|
half3 specular = specularGloss.rgb; |
|
|
|
half oneMinusReflectivity; |
|
|
|
// Note: UnityStandardCoreForwardSimple is not energy conserving. The lightmodel from LDPipeline will appear |
|
|
|
// slither darker when comparing to Standard Simple due to this. |
|
|
|
diffuse = EnergyConservationBetweenDiffuseAndSpecular(diffuse, specular, /*out*/ oneMinusReflectivity); |
|
|
|
|
|
|
|
// Indirect Light Contribution |
|
|
|
|
|
|
#if DEBUG_CASCADES |
|
|
|
return half4(EvaluateMainLight(mainLight, diffuse, specular, normal, i.posWS, viewDir), 1.0); |
|
|
|
#endif |
|
|
|
half3 directColor = EvaluateMainLight(mainLight, diffuse, specular, normal, i.posWS, viewDir); |
|
|
|
half3 directColor = EvaluateMainLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir); |
|
|
|
|
|
|
|
// Compute direct contribution from additional lights. |
|
|
|
for (int lightIndex = 1; lightIndex < globalLightCount.x; ++lightIndex) |
|
|
|
|
|
|
directColor += EvaluateOneLight(additionalLight, diffuse, specular, normal, posWorld, viewDir); |
|
|
|
directColor += EvaluateOneLight(additionalLight, diffuse, specularGloss, normal, posWorld, viewDir); |
|
|
|
} |
|
|
|
|
|
|
|
half3 color = directColor + indirectDiffuse + _EmissionColor; |
|
|
|
|
|
|
#pragma vertex vert |
|
|
|
#pragma fragment frag |
|
|
|
|
|
|
|
float4 _ShadowBias; |
|
|
|
|
|
|
|
|
|
|
|
return UnityApplyLinearShadowBias(clipPos); |
|
|
|
#if defined(UNITY_REVERSED_Z) |
|
|
|
clipPos.z -= _ShadowBias.x; |
|
|
|
#else |
|
|
|
clipPos.z += _ShadowBias.x; |
|
|
|
#endif |
|
|
|
return clipPos; |
|
|
|
} |
|
|
|
|
|
|
|
half4 frag() : SV_TARGET |
|
|
|
|
|
|
ENDCG |
|
|
|
} |
|
|
|
} |
|
|
|
Fallback "RenderLoop/Error" |
|
|
|
CustomEditor "StandardShaderGUI" |
|
|
|
} |