mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Improve shadow rendering with non-default camera FOV (#11385)
* Adjust minimum filter radius for perspective * Expand shadow frustum when camera FOV changes, reuse FOV distance adjustment from numeric.cpp * Read shadow_soft_radius setting as float * Use adaptive filter radius to accomodate for PSM distortion * Adjust filter radius for texture resolution
This commit is contained in:
parent
1d25d1f7ad
commit
f5706d444b
4 changed files with 37 additions and 23 deletions
|
@ -33,29 +33,34 @@ void DirectionalLight::createSplitMatrices(const Camera *cam)
|
|||
v3f newCenter;
|
||||
v3f look = cam->getDirection();
|
||||
|
||||
// camera view tangents
|
||||
float tanFovY = tanf(cam->getFovY() * 0.5f);
|
||||
float tanFovX = tanf(cam->getFovX() * 0.5f);
|
||||
|
||||
// adjusted frustum boundaries
|
||||
float sfNear = shadow_frustum.zNear;
|
||||
float sfFar = adjustDist(shadow_frustum.zFar, cam->getFovY());
|
||||
|
||||
// adjusted camera positions
|
||||
v3f camPos2 = cam->getPosition();
|
||||
v3f camPos = v3f(camPos2.X - cam->getOffset().X * BS,
|
||||
camPos2.Y - cam->getOffset().Y * BS,
|
||||
camPos2.Z - cam->getOffset().Z * BS);
|
||||
camPos += look * shadow_frustum.zNear;
|
||||
camPos2 += look * shadow_frustum.zNear;
|
||||
float end = shadow_frustum.zNear + shadow_frustum.zFar;
|
||||
newCenter = camPos + look * (shadow_frustum.zNear + 0.05f * end);
|
||||
v3f world_center = camPos2 + look * (shadow_frustum.zNear + 0.05f * end);
|
||||
camPos += look * sfNear;
|
||||
camPos2 += look * sfNear;
|
||||
|
||||
// center point of light frustum
|
||||
float end = sfNear + sfFar;
|
||||
newCenter = camPos + look * (sfNear + 0.05f * end);
|
||||
v3f world_center = camPos2 + look * (sfNear + 0.05f * end);
|
||||
|
||||
// Create a vector to the frustum far corner
|
||||
// @Liso: move all vars we can outside the loop.
|
||||
float tanFovY = tanf(cam->getFovY() * 0.5f);
|
||||
float tanFovX = tanf(cam->getFovX() * 0.5f);
|
||||
|
||||
const v3f &viewUp = cam->getCameraNode()->getUpVector();
|
||||
// viewUp.normalize();
|
||||
|
||||
v3f viewRight = look.crossProduct(viewUp);
|
||||
// viewRight.normalize();
|
||||
|
||||
v3f farCorner = look + viewRight * tanFovX + viewUp * tanFovY;
|
||||
// Compute the frustumBoundingSphere radius
|
||||
v3f boundVec = (camPos + farCorner * shadow_frustum.zFar) - newCenter;
|
||||
v3f boundVec = (camPos + farCorner * sfFar) - newCenter;
|
||||
radius = boundVec.getLength() * 2.0f;
|
||||
// boundVec.getLength();
|
||||
float vvolume = radius * 2.0f;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue