You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once you have the world space position of each fragment, you can use pixel derivatives `ddx` and `ddy` to get an approximation of the normal vector of each fragment:
76
+
## A note on normals
77
+
The simplest way to calculate normals from depth is by taking the gradient of the reconstructed world space position using `ddx(...)` and `ddy(...)`. Like so:
78
78
```glsl
79
79
...
80
80
float3 wpos = homWorldPos.xyz / homWorldPos.w; // world space fragment position
@@ -83,6 +83,10 @@ float3 wposy = ddy(wpos);
83
83
float3 wnormal = normalize(cross(wposy,wposx)); // world space fragment normal
84
84
```
85
85
86
+
This works, but results in very jagged looking normals at the edges of objects. There are better, slightly more expensive ways of calculating normals, some of which are described here (praise bgolus):
For a shader to appear in the depth texture, a couple of properties must be satisfied:
88
92
- The shader/material must have `ZWrite On`.
@@ -142,11 +146,6 @@ if (!dot(unity_LightShadowBias, 1))
142
146
```
143
147
Thanks, Silent!
144
148
145
-
## A note on normals
146
-
The simplest way to calculate normals from depth is by taking the gradient of the reconstructed world space position using `ddx(...)` and `ddy(...)`. This works, but results in very jagged looking normals at the edges of objects. There are better, slightly more expensive ways of calculating normals, some of which are described here (praise bgolus):
0 commit comments