Skip to content

Commit

Permalink
CascadeShadowMap : Fix far being too small
Browse files Browse the repository at this point in the history
  • Loading branch information
TothBenoit committed Oct 29, 2024
1 parent abbb7ff commit 869062c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions h3d/pass/CascadeShadowMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CascadeShadowMap extends DirShadowMap {

function computeNearFar( i : Int, previousFar : Float ) {
var max = maxDist < 0.0 ? ctx.camera.zFar : maxDist;
var step = (max - firstCascadeSize) / (cascade - 1);
var step = max - firstCascadeSize;
var near = ( i == 0 ) ? 0.0 : previousFar - previousFar * transitionFraction;
var far = ( i == 0 ) ? firstCascadeSize : firstCascadeSize + hxd.Math.pow(i / (cascade - 1), pow) * step;

Expand Down Expand Up @@ -287,12 +287,13 @@ class CascadeShadowMap extends DirShadowMap {
lightCamera.update();
}

cullPasses(passes,function(col) return col.inFrustum(lightCamera.frustum));
cullPasses(passes, function(col) return col.inFrustum(lightCamera.frustum));

calcCascadeMatrices();

var textures = [];
for (i in 0...cascade) {
var i = cascade - 1 - i;
currentCascadeIndex = i;

var texture = ctx.textures.allocTarget("cascadeShadowMap_"+i, size, size, false, #if js Depth24Stencil8 #else highPrecision ? Depth32 : Depth16 #end );
Expand All @@ -310,15 +311,13 @@ class CascadeShadowMap extends DirShadowMap {
// first cascade draw all objects
if ( i == 0 )
dimension = 0.0;
var p = passes.save();
tmpFrustum.loadMatrix(lc.viewProj);
tmpFrustum.checkNearFar = false;
if ( dimension > 0.0 )
cullPassesSize(passes, tmpFrustum, dimension);
else
cullPasses(passes, function(col) return col.inFrustum(tmpFrustum));
textures[i] = processShadowMap( passes, texture, sort);
passes.load(p);
}
syncCascadeShader(textures);

Expand Down

0 comments on commit 869062c

Please sign in to comment.