|
4 | 4 | { |
5 | 5 | _Color ("Color", Color) = (1,1,1,1) |
6 | 6 | baseColorTexture ("Base Color Texture", 2D) = "white" {} |
| 7 | + _ShadowStrength ("Shadow Strength", Range(0, 1)) = 0.5 |
7 | 8 | } |
8 | 9 | SubShader |
9 | 10 | { |
|
56 | 57 |
|
57 | 58 | sampler2D baseColorTexture; |
58 | 59 | float4 _Color; |
| 60 | + float _ShadowStrength; |
59 | 61 |
|
60 | 62 | v2f vert (appdata v) |
61 | 63 | { |
|
81 | 83 | { |
82 | 84 | float4 texColor = tex2D(baseColorTexture, i.uv); |
83 | 85 | float4 color = texColor * _Color; |
84 | | - |
85 | 86 | Light mainLight = GetMainLight(i.shadowCoord); //get dir light |
86 | | - float3 lightCol = Lambert(mainLight.color * mainLight.shadowAttenuation, mainLight.direction, float3(0,1,0)); //lets keep up normal always |
| 87 | + float shadowAtten = lerp(1.0, mainLight.shadowAttenuation, _ShadowStrength); |
| 88 | + float3 lightCol = Lambert(mainLight.color * shadowAtten, mainLight.direction, float3(0,1,0)); |
| 89 | + //color.rgb *= lightCol + 1; |
| 90 | + color.rgb *= lerp(0, lightCol + 1, shadowAtten); |
87 | 91 |
|
88 | | - color.rgb *= lightCol + 1; |
89 | 92 | return color; |
90 | 93 | } |
91 | 94 | ENDHLSL |
|
119 | 122 | UNITY_VERTEX_OUTPUT_STEREO |
120 | 123 | }; |
121 | 124 |
|
| 125 | + float _ShadowStrength; |
| 126 | + |
122 | 127 | Varyings vert(Attributes input) |
123 | 128 | { |
124 | 129 | Varyings output; |
|
128 | 133 | float3 worldPos = TransformObjectToWorld(input.vertex.xyz); |
129 | 134 | float3 worldNormal = TransformObjectToWorldNormal(input.normal); |
130 | 135 |
|
131 | | - worldPos += worldNormal * 0.001; //prevent zfighting spots |
| 136 | + worldPos += worldNormal * (0.001 * _ShadowStrength); //prevent zfighting spots |
132 | 137 |
|
133 | 138 | output.positionCS = TransformWorldToHClip(worldPos); |
134 | 139 | return output; |
|
0 commit comments