| 1 |
//------------------------------------------------------------------------------ |
| 2 |
// Shadowing |
| 3 |
//------------------------------------------------------------------------------ |
| 4 |
|
| 5 |
#if defined(HAS_SHADOWING) |
| 6 |
/** |
| 7 |
* Computes the light space position of the specified world space point. |
| 8 |
* The returned point may contain a bias to attempt to eliminate common |
| 9 |
* shadowing artifacts such as "acne". To achieve this, the world space |
| 10 |
* normal at the point must also be passed to this function. |
| 11 |
*/ |
| 12 |
vec4 computeLightSpacePosition(const vec3 p, const vec3 n, const vec3 l, |
| 13 |
const float b, const mat4 lightFromWorldMatrix) { |
| 14 |
float NoL = saturate(dot(n, l)); |
| 15 |
float sinTheta = sqrt(1.0 - NoL * NoL); |
| 16 |
vec3 offsetPosition = p + n * (sinTheta * b); |
| 17 |
vec4 lightSpacePosition = (lightFromWorldMatrix * vec4(offsetPosition, 1.0)); |
| 18 |
return lightSpacePosition; |
| 19 |
} |
| 20 |
#endif |