Skip to content

Commit 276dfdf

Browse files
committed
(experiment 7) refactor: shader codes cleaned
1 parent 4aac81a commit 276dfdf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Assets/Experiments/Experiment7_Lighting/Code/Shaders/Lambertian.shader

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Shader "Unlit/Lambertian"
77
SubShader
88
{
99
Tags { "RenderType"="Opaque"
10-
"LightMode" = "ForwardBase"}
10+
"LightMode" = "ForwardBase"
11+
12+
}
1113

1214

1315
Pass

Assets/Experiments/Experiment7_Lighting/Code/Shaders/LambertianPhong.shader

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Shader "Unlit/LambertianPhong"
77
}
88
SubShader
99
{
10-
Tags { "RenderType"="Opaque" }
10+
Tags { "RenderType"="Opaque"
11+
"LightMode" = "ForwardBase"
12+
}
1113

1214
Pass
1315
{
@@ -50,19 +52,21 @@ Shader "Unlit/LambertianPhong"
5052
fixed4 frag (v2f i) : SV_Target
5153
{
5254
fixed4 col = tex2D(_MainTex, i.uv);
55+
5356

54-
float3 normalDir = normalize(i.normal);
57+
float3 normalDir = normalize(i.normal); // (!) We normalize the normals since interpolator will change their length and cause wierd effect
5558
float3 lightDir = _WorldSpaceLightPos0.xyz;
5659
float3 cameraDir = normalize(_WorldSpaceCameraPos - i.worldPos);
5760

58-
61+
// PHONG
5962
float3 reflected = reflect(-lightDir, normalDir);
6063
float3 phongSpecular = saturate(dot(reflected, cameraDir));
64+
phongSpecular = pow(phongSpecular, _Gloss); // (!) We adjust the sharpness of the specular based on the gloss
6165

66+
// LAMBERTIAN
6267
float3 lambertian = saturate(dot(normalDir, lightDir));
6368

64-
phongSpecular = pow(phongSpecular, _Gloss);
65-
69+
// PHONG + LAMBERTIAN
6670
return float4(lambertian * _LightColor0 * col + phongSpecular.xxx, 1.0);
6771

6872
return col;

0 commit comments

Comments
 (0)