ShadowHelper Code Never Completes

Started by AGP, August 18, 2012, 10:03:04 AM

Previous topic - Next topic

AGP

The following lines never complete (I put it in its own thread BECAUSE it was locking my program). The video hardware is NVidia GeForce GT 540M.


     public void run() {
Config.glDynamicBatchSize = 4000;
projector = new Projector();
projector.setFOV(1.5f);
projector.setYFOV(1.5f);
sh = new ShadowHelper(theWorld, buffer, projector, 512);
sh.setCullingMode(false);
sh.setAmbientLight(new Color(30, 30, 30));
sh.setLightMode(true);
sh.setBorder(1);
sh.addCaster(hero.get(0));
sh.addReceiver(ground);
sun = new Light(theWorld);
sun.setIntensity(250, 250, 250);
sun.setAttenuation(800);
theCamera.setFOV(1.5f);
System.out.println("\n\n\nFinished shadows.\n\n");
     }

EgonOlsen

I don't know in which context you call run() (some extra thread of yours?), but when using the AWTGLRenderer, you have to ensure that the paint()-method of the component can run, i.e. that the component is able to repaint itself while initializing the ShadowHelper. The ShadowHelper has to query the driver for information about the supported modes and this can only be done in the rendering thread, i.e. in the paint()-method. So the ShadowHelper has to wait for the next repaint of the component to happen to get this information. If, for whatever reason, this repaint never comes, the ShadowHelper never returns.

AGP

I said it was moved to a separate thread because it locks (hence, the run() method). I'm not overriding paint(Graphics), I use my own draw() for active rendering, but I did call glCanvas.repaint(), super.repaint(), and even super.paint(this.getGraphics()). None helped.

EgonOlsen

Under normal conditions, it works fine. So you are doing something that prevents the canvas from being repainted. What you are supposed to do:


  • enable the GLCanvasRenderer on the FrameBuffer
  • add the canvas to your frame/component
  • make your frame/component visible and active
  • setup your ShadowHelper

There shouldn't be any need to call repaint()/paint()/whatever() yourself nor do you have to spawn another thread because the rendering already takes place in the AWT event dispatch thread, which happens in parallel to your own code.

Just make sure that you aren't blocking the AWT event dispatch thread from executing at the time you are setting up the ShadowHelper and that the canvas is visible and can be repainted.

AGP

I don't know what I changed about it (it wasn't the order of the operations, but I did leave the repaint calls in), but it completes now. Problem now is that the screen gets stuck on black. The following is ShadowHelper's console output. The ShadowHelper is configured for a 512x512 map. Its initialization is no longer on a separate thread, as that's no longer needed.

Driver is: igdumd64/8.15.10.2253 on NVIDIA Corporation / GeForce GT 540M/PCIe/SS
E2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 16384*16384 in size!
Adding Lightsource: 0

AGP

OK, never mind that, it was an unrelated problem. Still, though ShadowHelper completes and though I do


SimpleVector offset = new SimpleVector(1, 0, -1).normalize();
offset.rotateY(0.007f);
projector.lookAt(ground.getTransformedCenter());
projector.setPosition(hero.get(0).getTransformedCenter());
projector.moveCamera(new SimpleVector(0, -1, 0), 200);
projector.moveCamera(offset, 215);
sun.setPosition(projector.getPosition());
sh.updateShadowMap();
sh.drawScene();


before calling buffer.update, I see no shadows being cast.

AGP

#6
By the way, I ran the AdvancedExample on this computer and it has no trouble casting shadows. I've compared both programs to death, and, for the life of me, can't tell the difference. I thought it might be Bones's fault, but I added a cube from the Primitives class and added it as a caster and I still get no shadows.

Also, I have since replaced the snork.md2 model on the AdvancedExample with my Bones model, using my initialization code, and it worked. But it won't work on my own program!

EgonOlsen

Any suspicious log output? I doubt it, but you never know so maybe you could post the log...

AGP

#8
Here you go:
...

IDle: 3 Walk: 2 RUNS: 9
Driver is: igdumd64/8.15.10.2253 on NVIDIA Corporation / GeForce GT 540M/PCIe/S
E2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 16384*16384 in size!
Adding Lightsource: 0



Finished shadows. Initialized properly? true


OS Version: Windows 7
New WorldProcessor created using 1 thread(s) and granularity of 1!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 25/object27 compiled using 6 vertices in 0ms!
Object 25/object27 compiled to 6 subobjects in 6ms!
Creating new world processor buffer for thread main
New WorldProcessor created using 1 thread(s) and granularity of 1!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 23997 vertices
n 47ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 10119 vertices
n 15ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1176 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 12108 vertices
n 13ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1044 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 816 vertices in
2ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 13728 vertices
n 15ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 18054 vertices
n 21ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 6210 vertices i
9ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 3783 vertices i
4ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1368 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1404 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1467 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 9210 vertices i
14ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 23997 vertices
n 26ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 10506 vertices
n 12ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 2703 vertices i
5ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 558 vertices in
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 2424 vertices i
3ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 23997 vertices
n 28ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 24000 vertices
n 35ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 19323 vertices
n 26ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 23997 vertices
n 32ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 24000 vertices
n 28ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 24000 vertices
n 31ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 14058 vertices
n 16ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 20856 vertices
n 5ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 22512 vertices
n 6ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 1626 vertices i
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 768 vertices in
0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 279 vertices in
0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 6630 vertices i
2ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 2784 vertices i
2ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 372 vertices in
1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 5/Silmaria_PT1_PT2_006_jPCT5 compiled using 7920 vertices i
2ms!
Object 5/Silmaria_PT1_PT2_006_jPCT5 compiled to 35 subobjects in 1124ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 330 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 495 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 54 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 984 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 24 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 450 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 246 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 180 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 23997 vertices in 5ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 2883 vertices in 0ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 10386 vertices in 2ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 6/ground_jPCT6 compiled using 246 vertices in 0ms!
Object 6/ground_jPCT6 compiled to 12 subobjects in 77ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 7/leaves_jPCT7 compiled using 23997 vertices in 7ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 7/leaves_jPCT7 compiled using 651 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 7/leaves_jPCT7 compiled using 9018 vertices in 3ms!
Object 7/leaves_jPCT7 compiled to 3 subobjects in 57ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 8/leaves2_jPCT8 compiled using 6744 vertices in 1ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 8/leaves2_jPCT8 compiled using 2268 vertices in 1ms!
Object 8/leaves2_jPCT8 compiled to 2 subobjects in 23ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 9/Leaves3_jPCT9 compiled using 7776 vertices in 2ms!
Object 9/Leaves3_jPCT9 compiled to 1 subobjects in 13ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 10/Leaves4_jPCT10 compiled using 21492 vertices in 6ms!
Object 10/Leaves4_jPCT10 compiled to 1 subobjects in 28ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 11/a_jPCT11 compiled using 2910 vertices in 2ms!
Object 11/a_jPCT11 compiled to 1 subobjects in 6ms!
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 12/Leaves5_jPCT12 compiled using 5616 vertices in 2ms!
Object 12/Leaves5_jPCT12 compiled to 1 subobjects in 29ms!
Creating new world processor buffer for thread main
Checking for triangle strip...
Not a triangle strip at position 1!
Remapping 48 vertex indices!
Creating vertex cache (1152 bytes)!
Vertex indices will be mapped!
Subobject of object 26/object28 compiled using 48 vertices in 1ms!
Object 26/object28 compiled to 1 subobjects in 1ms!
Additional visibility list (2) created with size: 128000
Additional visibility list (3) created with size: 128000
Total FPS: 1, Polygons/second: 1
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'object27'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'leaves_jPCT7'
VBO created for object 'object27'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'object27'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'leaves2_jPCT8'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Leaves4_jPCT10'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'leaves_jPCT7'
VBO created for object 'leaves_jPCT7'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'object27'
VBO created for object 'Leaves3_jPCT9'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'object27'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Leaves5_jPCT12'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'object27'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'a_jPCT11'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'ground_jPCT6'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'Silmaria_PT1_PT2_006_jPCT5'
VBO created for object 'leaves2_jPCT8'
Compiled 62 VBO!
Total FPS: 2, Polygons/second: 3
Total FPS: 41, Polygons/second: 538
Total FPS: 90, Polygons/second: 2341

EgonOlsen

Looks fien at first glance. Could you post your render-"loop"?

AGP

No problem:


     private void draw() {
buffer.clear();
skyBox.render(theWorld, buffer);

if (!softwareMode) {
     if (!doShadows()) {
theWorld.renderScene(buffer);
theWorld.draw(buffer);
     }
     buffer.update();
     buffer.displayGLOnly();
     glCanvas.repaint();
}
else {
     theWorld.renderScene(buffer);
     if (wireframe)
theWorld.drawWireframe(buffer, Color.blue);
     else theWorld.draw(buffer);
     buffer.display(glCanvas.getGraphics());
}
     }
     private boolean doShadows() {
if (sh == null || storyMode)
     return false;
SimpleVector offset = new SimpleVector(1, 0, -1).normalize();
offset.rotateY(0.07f);
projector.lookAt(ground.getTransformedCenter());
SimpleVector position = hero.getRoot().getTransformedCenter();
position.y -= 30f;
position.z += 5f;
projector.setPosition(position);
//projector.setPosition(hero.getRoot().getTransformedCenter());//hero.getRoot().getTransformedCenter()
//projector.moveCamera(new SimpleVector(0, -1, 0), 200);
//projector.moveCamera(offset, 215);
sun.setPosition(projector.getPosition());
sh.updateShadowMap();
sh.drawScene();
return true;
     }

EgonOlsen

Looks ok...and the result is...everything is shadowed? No shadows at all? Are you sure that the objects that should be receivers actually are? Maybe you missed that part somehow or are working on copies the objects or something like that!?

AGP

#12
No shadows at all. And no, I called sh.addReceiver(ground) and there's only one ground on the entire model.

Any suggestions?

AGP

Is it possible that it's a ShadowHelper bug related to the use of AWTGLFrame? The only difference I see between the AdvancedExample and my program is that I'm using an AWT frame.

EgonOlsen

I don't of any bugs. I've multiple test cases for using shadows in an AWTGLCanvas and they all work fine. I suggest to take the advanced example and port it to use AWT instead. If that works, try to spot the difference between it and what you are doing.