Shadow Problems With Multiple AWTPanels

I have a program that is using AWTPanels to display the world and each AWTPanel has its own viewport, I am attempting to add shadows to the world and when i make a new viewport i call this code on it.



[java] public void setUpPostProcessors(ViewPort viewPortToAddTo)

{

PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 5);

pssmRenderer.setDirection(new Vector3f(-1, -4, -1).normalizeLocal());

pssmRenderer.setLambda(0.55f);

pssmRenderer.setShadowIntensity(0.6f);

pssmRenderer.setCompareMode(CompareMode.Software);

pssmRenderer.setFilterMode(FilterMode.Dither);

pssmRenderer.setFlushQueues(true);



viewPortToAddTo.addProcessor(pssmRenderer);

}[/java]



This way each vewport has its own ShadowRenderer. the problem is it seams that only the first viewport that gets a shadowRenderer added to it works “properly”. the other viewport has weird shadow issues that seem like the shadows are being calculated based on the first viewport. The attached video shows the issue i am having, the shadowRenderer was added to the viewport on the left after the viewport on the right. Any ideas of what i may be doing wrong.



http://www.youtube.com/watch?v=VAcuObWJsQw&feature=youtu.be

also i have tried pssmRenderer.setFlushQueues(false);

mhhh that’s strange…

could you wrap up a test case so I look into it?

this example is a bit messy, but shows the problem.

Thanks for looking into it.



[java]

public class ShadowProblemTest extends SimpleApplication

{

private static ShadowProblemTest app;

private static AwtPanel panel1, panel2;

private static int panelsClosed = 0;

private Spatial sceneModel;



public static void main(String[] args)

{

Logger.getLogger("com.jme3").setLevel(Level.WARNING);



app = new ShadowProblemTest();

app.setShowSettings(false);

AppSettings settings = new AppSettings(true);

settings.setCustomRenderer(AwtPanelsContext.class);

app.setSettings(settings);

app.start();



SwingUtilities.invokeLater(new Runnable()

{

public void run()

{

final AwtPanelsContext ctx = (AwtPanelsContext) app.getContext();

panel1 = ctx.createPanel(PaintMode.Accelerated);

panel1.setPreferredSize(new Dimension(400, 300));

ctx.setInputSource(panel1);



panel2 = ctx.createPanel(PaintMode.Accelerated);

panel2.setPreferredSize(new Dimension(400, 300));



createWindowForPanel(panel1, 300, "FlyCam");

createWindowForPanel(panel2, 700, "Stationary Cam");

}

});

}



public void simpleInitApp()

{

/** Set up Physics */

flyCam.setDragToRotate(true);



flyCam.setMoveSpeed(100);

setUpLight();

assetManager.registerLocator("town.zip", ZipLocator.class);

sceneModel = assetManager.loadModel("main.scene");

sceneModel.setLocalScale(2f);



sceneModel.setShadowMode(ShadowMode.CastAndReceive);



Spatial tree = getAssetManager().loadModel("Models/Tree/Tree.mesh.j3o");

tree.setQueueBucket(Bucket.Transparent);



tree.setShadowMode(ShadowMode.CastAndReceive);



tree.scale(10.0f);

rootNode.attachChild(tree);



rootNode.attachChild(sceneModel);

cam.setLocation(new Vector3f(60.0f, 10.0f, 60f));

cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);



Camera cameraClone2 = getCamera().clone();

cameraClone2.setLocation(new Vector3f(60.0f, 10.0f, 60f));

cameraClone2.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);

ViewPort viewPort2 = getRenderManager().createMainView("cameraClone2", cameraClone2);

viewPort2.attachScene(rootNode);



viewPort2.setClearFlags(true, true, true);



setUpPostProcessors(viewPort);

setUpPostProcessors(viewPort2);



panel1.attachTo(false, viewPort);

panel2.attachTo(false, viewPort2);

}



public void setUpPostProcessors(ViewPort viewPortToAddTo)

{

PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 5);

pssmRenderer.setDirection(new Vector3f(-1.0f, -4.0f, -1.0f).normalizeLocal());

pssmRenderer.setLambda(0.55f);

pssmRenderer.setShadowIntensity(0.6f);

pssmRenderer.setCompareMode(CompareMode.Software);

pssmRenderer.setFilterMode(FilterMode.Dither);

viewPortToAddTo.addProcessor(pssmRenderer);

}



private void setUpLight()

{

AmbientLight al = new AmbientLight();

al.setColor(ColorRGBA.White.mult(1.3f));

rootNode.addLight(al);



DirectionalLight dl = new DirectionalLight();

dl.setColor(ColorRGBA.White);

dl.setDirection(new Vector3f(-1.0f, -4.0f, -1.0f).normalizeLocal());

rootNode.addLight(dl);

}



private static void createWindowForPanel(AwtPanel panel, int location, String name)

{

JFrame frame = new JFrame(name);

frame.getContentPane().setLayout(new BorderLayout());

frame.getContentPane().add(panel, BorderLayout.CENTER);

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

frame.addWindowListener(new WindowAdapter()

{

public void windowClosed(WindowEvent e)

{

if (++panelsClosed == 2)

{

app.stop();

}

}

});

frame.pack();

frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);

frame.setVisible(true);

}

}[/java]

1 Like

ok…that’s annoying, i don’t have the issue

http://i.imgur.com/l1TLB.jpg?1



On what OS/hardware are you?

Are your graphic drivers up to date?

I have the same problem as described by @jcarff



https://dl.dropbox.com/u/3279456/Screens/shadow%20jme.PNG



Running on Windows 8 64bits

NVidia GTX660M Driver 306.14 (upgrading now to 306.97)

I am on windows 7 64bit with an NVidia Quadro fx 880m with the most up to date drivers. I also have another coworker who on a new mac book pro and is having the same issues. Nehon, what are you running on?

windows 7 64 bit, ati radeon HD5970

also i tested with java 7



Edit also I’m running this against latest nightly but still use the PSSMRenderer.

I’m running on RC2, I don’t run nightly.

I have the same problem as the OP.

Win 7, java 7, gtx580 on a few weeks old svn jme.

Same problem windows 7 x64 on a A6 4ksomewhat ultrabook.

mhhh…one of you could try with the latest nightly?

@jcarff just came in to my office and told me to pop in here.



I’m running the latest nightly (checked out from the Google Code SVN trunk a few minutes ago), OS X 10.8.2, with an ATI card, and this issue is not reproducible on my machine. Shadows appear fine running the same code he used to create the above video.



Incidentally, the other guy in our lab with the new MBP would be running a Kepler card since it’s a rMBP. I wonder if this is related to Nvidia drivers?

No, the A6 i used is a amd system

@dljsjr said:
@jcarff just came in to my office and told me to pop in here.

I'm running the latest nightly (checked out from the Google Code SVN trunk a few minutes ago), OS X 10.8.2, with an ATI card, and this issue is *not* reproducible on my machine. Shadows appear fine running the same code he used to create the above video.

Incidentally, the other guy in our lab with the new MBP would be running a Kepler card since it's a rMBP. I wonder if this is related to Nvidia drivers?

or....that means the latest nightly fixes the issue....
This means i may have fixed an issue without being aware of it.....i'm getting better and better....
I'm gonna try to run this against the RC2 version and see if i have the issue.

I am now running on the latest nightly( with an nvidia card), and the issue appears to be fixed. Whatever you did, thanks :slight_smile: