From ad79981dfddd3f787011334490d137e0a9a0ffb8 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 27 May 2024 23:08:18 -0700 Subject: Add controls for shadow strength & mipmap selection --- pbr.cginc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'pbr.cginc') diff --git a/pbr.cginc b/pbr.cginc index 0ff3bd1..801f87a 100644 --- a/pbr.cginc +++ b/pbr.cginc @@ -12,7 +12,37 @@ UNITY_DECLARE_TEXCUBE(_Cubemap); UnityLight CreateDirectLight(float3 normal, float ao, v2f i) { +#if 1 + // This whole block is yoinked from AutoLight.cginc. I needed a way to + // control shadow strength so I had to duplicate the code. +#if defined(DIRECTIONAL_COOKIE) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTexture0, lightCoord).w; +#elif defined(POINT_COOKIE) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTextureB0, dot(lightCoord, lightCoord).rr).r * + texCUBE(_LightTexture0, lightCoord).w; +#elif defined(DIRECTIONAL) + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = 1; +#elif defined(SPOT) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = (lightCoord.z > 0) * UnitySpotCookie(lightCoord) * UnitySpotAttenuate(lightCoord.xyz); +#elif defined(POINT) + unityShadowCoord3 lightCoord = mul(unity_WorldToLight, unityShadowCoord4(i.worldPos, 1)).xyz; + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r; +#else + float shadow = 1; + float attenuation = 1; +#endif + attenuation *= lerp(1, shadow, _Shadow_Strength); +#else UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos); +#endif UnityLight light; light.color = _LightColor0.rgb * attenuation * ao; @@ -22,7 +52,6 @@ UnityLight CreateDirectLight(float3 normal, float ao, v2f i) light.dir = _WorldSpaceLightPos0; #endif - if (round(_Confabulate_Normals)) { light.dir = normal; } -- cgit v1.2.3