Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.debug.WireFrustum;
import com.jme3.texture.FrameBuffer;
Expand Down Expand Up @@ -396,6 +397,10 @@ public boolean isInitialized() {
protected void doDisplayFrustumDebug(int shadowMapIndex) {
}

protected Node getMainScene() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this to indicate the returned scene is for debugging purposes (maybe getSceneForDebug?)

return (Node) viewPort.getScenes().get(0);
}

@SuppressWarnings("fallthrough")
@Override
public void postQueue(RenderQueue rq) {
Expand All @@ -413,15 +418,16 @@ public void postQueue(RenderQueue rq) {
renderManager.setForcedTechnique("PreShadow");

for (int shadowMapIndex = 0; shadowMapIndex < nbShadowMaps; shadowMapIndex++) {

if (debugfrustums) {
doDisplayFrustumDebug(shadowMapIndex);
}
renderShadowMap(shadowMapIndex);

if (debugfrustums) {
doDisplayFrustumDebug(shadowMapIndex);
}
renderShadowMap(shadowMapIndex);
}

debugfrustums = false;
if (debugfrustums) {
debugfrustums = false;
getMainScene().updateGeometricState();
}

//restore setting for future rendering
r.setFrameBuffer(viewPort.getOutputFrameBuffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.jme3.renderer.Camera;
import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.util.clone.Cloner;

Expand Down Expand Up @@ -212,9 +211,9 @@ protected Camera getShadowCam(int shadowMapIndex) {

@Override
protected void doDisplayFrustumDebug(int shadowMapIndex) {
((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex));
getMainScene().attachChild(createFrustum(points, shadowMapIndex));
ShadowUtil.updateFrustumPoints2(shadowCam, points);
((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex));
getMainScene().attachChild(createFrustum(points, shadowMapIndex));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars;
import com.jme3.util.clone.Cloner;
Expand Down Expand Up @@ -166,7 +165,7 @@ protected void doDisplayFrustumDebug(int shadowMapIndex) {
}
Geometry geo = frustums[shadowMapIndex];
if (geo.getParent() == null) {
((Node) viewPort.getScenes().get(0)).attachChild(geo);
getMainScene().attachChild(geo);
}
}

Expand Down
21 changes: 13 additions & 8 deletions jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -438,13 +438,9 @@ public void postQueue(RenderQueue rq) {
renderManager.setCamera(shadowCam, false);

if (debugfrustums) {
// frustumFromBound(b.casterBB,ColorRGBA.Blue );
// frustumFromBound(b.receiverBB,ColorRGBA.Green );
// frustumFromBound(b.splitBB,ColorRGBA.Yellow );
((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, i));
getMainScene().attachChild(createFrustum(points, i));
ShadowUtil.updateFrustumPoints2(shadowCam, points);
((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, i));

getMainScene().attachChild(createFrustum(points, i));
}

r.setFrameBuffer(shadowFB[i]);
Expand All @@ -456,7 +452,11 @@ public void postQueue(RenderQueue rq) {
viewPort.getQueue().renderShadowQueue(splitOccluders, renderManager, shadowCam, true);
renderManager.setLightFilter(tmpLightFilter);
}
debugfrustums = false;

if (debugfrustums) {
debugfrustums = false;
getMainScene().updateGeometricState();
}

//restore setting for future rendering
r.setFrameBuffer(viewPort.getOutputFrameBuffer());
Expand All @@ -465,6 +465,11 @@ public void postQueue(RenderQueue rq) {
renderManager.setCamera(viewCam, false);

}

protected Node getMainScene() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as noted before.

return (Node) viewPort.getScenes().get(0);
}

boolean debugfrustums = false;

public void displayFrustum() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.jme3.renderer.Camera;
import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars;
import com.jme3.util.clone.Cloner;
Expand Down Expand Up @@ -89,7 +88,7 @@ public SpotLightShadowRenderer(AssetManager assetManager, int shadowMapSize) {
init(shadowMapSize);
}


private void init(int shadowMapSize) {
shadowCam = new Camera(shadowMapSize, shadowMapSize);
for (int i = 0; i < points.length; i++) {
Expand Down Expand Up @@ -175,9 +174,9 @@ protected Camera getShadowCam(int shadowMapIndex) {
protected void doDisplayFrustumDebug(int shadowMapIndex) {
Vector3f[] points2 = points.clone();

((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex));
getMainScene().attachChild(createFrustum(points, shadowMapIndex));
ShadowUtil.updateFrustumPoints2(shadowCam, points2);
((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points2, shadowMapIndex));
getMainScene().attachChild(createFrustum(points2, shadowMapIndex));
}

@Override
Expand Down
Loading