MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ShadowBias

Function ShadowBias

engine/Poseidon/Graphics/Shadow/ShadowMath.cpp:333–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333Bias ShadowBias(const Vec3& normal, const Vec3& lightDir, float texelWorldSize)
334{
335 Vec3 N = Normalize(normal);
336 Vec3 L = Normalize(lightDir * -1.0f); // toward the light
337 float c = Dot(N, L);
338 c = std::max(1e-4f, std::min(1.0f, c));
339 float sinT = std::sqrt(std::max(0.0f, 1.0f - c * c));
340 float tanT = sinT / c;
341
342 const float baseDepth = 0.0008f;
343 const float slopeScale = 0.0025f;
344 const float maxDepth = 0.01f;
345 float depthBias = std::min(maxDepth, baseDepth + slopeScale * tanT);
346
347 const float offsetScale = 2.0f;
348 float normalOffset = std::min(texelWorldSize * offsetScale, texelWorldSize * offsetScale * sinT);
349 return {depthBias, normalOffset};
350}
351
352ShadowUV WorldToShadowUV(const Mat4& lightVP, const Vec3& p)
353{

Callers 2

InspectShadowFunction · 0.85

Calls 4

NormalizeFunction · 0.85
DotFunction · 0.85
minFunction · 0.85
sqrtFunction · 0.85

Tested by 1

InspectShadowFunction · 0.68