Skip to content

Commit

Permalink
Can fully override cascade shadow mapping culling.
Browse files Browse the repository at this point in the history
  • Loading branch information
clementlandrin committed Jan 29, 2025
1 parent 7c90f81 commit 68ecf41
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions h3d/pass/CascadeShadowMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,18 @@ class CascadeShadowMap extends DirShadowMap {
return getCascadeProj(currentCascadeIndex);
}

inline function cullPassesSize( passes : h3d.pass.PassList, frustum : h3d.col.Frustum, minSize : Float ) {
passes.filter(function(p) {
var mb = Std.downcast(p.obj, h3d.scene.MeshBatch);
var col = p.obj.cullingCollider;
return if( mb != null && @:privateAccess mb.instanced.primitive.getBounds().dimension() < minSize ) false;
else if( col == null ) true;
else if ( col.dimension() < minSize ) false;
else col.inFrustum(frustum);
});
public dynamic function customCullPasses(passes : h3d.pass.PassList, frustum : h3d.col.Frustum, i : Int, minSize : Float) {
if ( minSize > 0.0 && i > 0 ) {
passes.filter(function(p) {
var mb = Std.downcast(p.obj, h3d.scene.MeshBatch);
var col = p.obj.cullingCollider;
return if( mb != null && @:privateAccess mb.instanced.primitive.getBounds().dimension() < minSize ) false;
else if( col == null ) true;
else if ( col.dimension() < minSize ) false;
else col.inFrustum(frustum);
});
} else
cullPasses(passes, function(col) return col.inFrustum(lightCamera.frustum));
}

override function draw( passes, ?sort ) {
Expand Down Expand Up @@ -312,15 +315,9 @@ class CascadeShadowMap extends DirShadowMap {
var lc = lightCameras[i];
var dimension = Math.max(lc.orthoBounds.xMax - lc.orthoBounds.xMin, lc.orthoBounds.yMax - lc.orthoBounds.yMin);
dimension = ( dimension * hxd.Math.clamp(minPixelSize, 0, size) ) / size;
// first cascade draw all objects
if ( i == 0 )
dimension = 0.0;
lightCamera.orthoBounds = lc.orthoBounds;
lightCamera.update();
if ( dimension > 0.0 )
cullPassesSize(passes, lightCamera.frustum, dimension);
else
cullPasses(passes, function(col) return col.inFrustum(lightCamera.frustum));
customCullPasses(passes, lightCamera.frustum, i, dimension);
textures[i] = processShadowMap( passes, texture, sort);
passes.load(p);
}
Expand Down

0 comments on commit 68ecf41

Please sign in to comment.