|
|
|
|
|
|
float GetShiftedNdotV(inout float3 N, float3 V, bool twoSided) |
|
|
|
{ |
|
|
|
float NdotV = dot(N, V); |
|
|
|
|
|
|
|
if (!twoSided && NdotV < 0.0) |
|
|
|
float limit = 1e-6; |
|
|
|
|
|
|
|
if (!twoSided && NdotV < limit) |
|
|
|
const float magic = 1e-5f; |
|
|
|
// We do not renormalize the normal because { abs(length(N) - 1.0) < magic }. |
|
|
|
N += (-NdotV + magic) * V; |
|
|
|
NdotV = magic; |
|
|
|
// We do not renormalize the normal because { abs(length(N) - 1.0) < limit }. |
|
|
|
N += (-NdotV + limit) * V; |
|
|
|
NdotV = limit; |
|
|
|
} |
|
|
|
|
|
|
|
return NdotV; |
|
|
|