File tree 2 files changed +12
-6
lines changed
Assets/Experiments/Experiment7_Lighting/Code/Shaders
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ Shader "Unlit/Lambertian"
7
7
SubShader
8
8
{
9
9
Tags { "RenderType" ="Opaque"
10
- "LightMode" = "ForwardBase" }
10
+ "LightMode" = "ForwardBase"
11
+
12
+ }
11
13
12
14
13
15
Pass
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ Shader "Unlit/LambertianPhong"
7
7
}
8
8
SubShader
9
9
{
10
- Tags { "RenderType" ="Opaque" }
10
+ Tags { "RenderType" ="Opaque"
11
+ "LightMode" = "ForwardBase"
12
+ }
11
13
12
14
Pass
13
15
{
@@ -50,19 +52,21 @@ Shader "Unlit/LambertianPhong"
50
52
fixed4 frag (v2f i) : SV_Target
51
53
{
52
54
fixed4 col = tex2D (_MainTex, i.uv);
55
+
53
56
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
55
58
float3 lightDir = _WorldSpaceLightPos0 .xyz;
56
59
float3 cameraDir = normalize (_WorldSpaceCameraPos - i.worldPos);
57
60
58
-
61
+ // PHONG
59
62
float3 reflected = reflect (-lightDir, normalDir);
60
63
float3 phongSpecular = saturate (dot (reflected, cameraDir));
64
+ phongSpecular = pow (phongSpecular, _Gloss); // (!) We adjust the sharpness of the specular based on the gloss
61
65
66
+ // LAMBERTIAN
62
67
float3 lambertian = saturate (dot (normalDir, lightDir));
63
68
64
- phongSpecular = pow (phongSpecular, _Gloss);
65
-
69
+ // PHONG + LAMBERTIAN
66
70
return float4 (lambertian * _LightColor0 * col + phongSpecular.xxx, 1.0 );
67
71
68
72
return col;
You can’t perform that action at this time.
0 commit comments