Error using ShadowHelper.

Started by roninjnj, August 26, 2008, 06:09:09 PM

Previous topic - Next topic

roninjnj

Hi!! I have a new question ;-).

Now I´m learning how to do shadow mapping with ShadowHelper.

I was reading "SimpleShadow.java" sample in forum. I got it and I modify it to test in a Canvas. Result was nice!!

Now, I´m using ShadowHelper in my application and i got this message error:

ERROR: Can´t render into a texture larger than the current framebuffer.

I can use sh = new ShadowHelper(world, fb, projector, 500) or sh = new ShadowHelper(world, fb, projector, 1000);

But i can´t use sh = new ShadowHelper(world, fb, projector, 512); or sh = new ShadowHelper(world, fb, projector, 1024);

My question is: Why i can´t use 500 or 1000 size of the shadow map but i got a ERROR using 512 o 1024??

In SimpleShadow.java sample i was using "sh = new ShadowHelper(world, fb, projector, 512);" whitout error..... why?


Thanks very much!!!! ;-)

EgonOlsen

Shadow maps' size should be a power of two. If it isn't, the ShadowHelper silently adjusts the size to 256*256, which is quite low (i'll add a warning for this case in the next version). You hardware/driver doesn't seem to support frame buffer objects (Intel onboard chip?), so the ShadowHelper has to revert to the frame buffer to render the shadow map into (which is not as nice...). This is why the shadow map can't be larger than your current frame buffer is, That's why the message comes up, but actually, you should never see it, because the helper should adjust the size according to the size of the frame buffer. This doesn't seem to happen, which is very strange. Which version are you using? Maybe this wasn't implemented in an earlier version...i'm not sure about this.
What's your frame buffer's size?

roninjnj

I have a Windows XP O.S. My graphics car is a ATI Mobility Redeon X700  256 Mgs.

I´m working with JPCT since one month about. I suposse that is the lastes version.

BOPSSSSSS I find something now.

If i put a 800*600 size in frame buffer, it go fine, like "SimpleShadow.java sample."

But if i put 640*480 size in frame buffer, CRASH, same ERROR.

800*600 resolution is too big to my application (Its render into a canvas y put this canvas into a JFrame).

Some idea?

Thanks


EgonOlsen

Makes not much sense. The code in ShadowHelper should adjust the size to 256 in that case. Please try the newer jar here: http://www.jpct.net/download/beta/ to see if this is a problem with an older ShadowHelper. BTW: The ATI x700 should support frame buffer object with recent drivers. Maybe you can make a driver update? That will improve sahdow quality and speed.

roninjnj

The newer version that you send me don´t solve the problem.

Buffer size   640*480     with    ShadowHelper(world, buffer, proyector, 512)   --> ERROR
Buffer size   800*600     with    ShadowHelper(world, buffer, proyector, 512)   --> FINE
Buffer size   1024*768     with    ShadowHelper(world, buffer, proyector, 512)   --> FINE

Buffer size   640*480     with    ShadowHelper(world, buffer, proyector, 1024)   --> ERROR
Buffer size   800*600     with    ShadowHelper(world, buffer, proyector, 1024)   --> ERROR
Buffer size   1024*768     with    ShadowHelper(world, buffer, proyector, 1024)   --> ERROR

I recive always a warning in ejecution window:

WARNING: this graphics hardware may have performance problems with shadow mapping /depth textures without using FBOs!

It is like my graphic hardware don´t support FBO (it is set to true, but i recive this message).

there is relation between this two messages?

I´m downloading latest drivers for my graphic card.

EgonOlsen

No, the messages are unrelated. X00 ATIs had some problems with older drivers and FBO, hence the message. You can ignore it for now.
The error makes absolutely no sense to me...the helper should handle this. I'll write myself a test case and see if i can reproduce this...

EgonOlsen

I can't reproduce this with the current version of the helper. I've updated the beta-jar in the link above with the latest version. Please try that one and let me know what happens.

roninjnj

I got same error. Its most probably that error is in my code, not in JPCT.

I modified "SimpleShadow.java" sample to put it in a canvas and render it at 640 * 480.

I got same error:.

The modified "SimpleShadow.java" code is this:


import java.awt.*;
import javax.swing.JFrame;
import java.awt.Canvas;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class SimpleShadows extends JFrame{


private Canvas canvas = null;
private boolean fin = false;

private FrameBuffer fb = null;
private World world = null;
private Object3D plane = null;
private Object3D cube = null;
private Object3D sphere = null;
private Projector projector=null;
private ShadowHelper sh = null;
private Light sun=null;

public SimpleShadows() {

super("TEST JNJ");
Config.glColorDepth = 24;
Config.glFullscreen = false;
Config.farPlane = 1000;
Config.glShadowZBias = 0.8f;
Config.glTrilinear=true;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private void initStuff() throws Exception {

fb = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_NORMAL);    
                fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);      
 
world = new World();

plane = Primitives.getPlane(20, 30);
plane.rotateX((float) Math.PI / 2f);

cube=Primitives.getCube(15);
cube.setAdditionalColor(Color.RED);
cube.translate(0, -30, -10);

sphere=Primitives.getSphere(12);
sphere.translate(0, 0, -50);
sphere.setAdditionalColor(new Color(0,0,50));

world.addObject(sphere);
world.addObject(plane);
world.addObject(cube);

TextureManager tm = TextureManager.getInstance();

projector = new Projector();
sh = new ShadowHelper(world, fb, projector, 512);

sh.addCaster(cube);
sh.addReceiver(plane);
sh.addReceiver(sphere);
sh.setAmbientLight(new Color(30,30,30));
sh.setFiltering(true);

world.setAmbientLight(90,90,90);
world.buildAllObjects();

sun=new Light(world);
sun.setIntensity(50, 50, 50);

      canvas = fb.enableGLCanvasRenderer();
        System.out.println("listo canvas");

System.out.println("Poniendo canvas");
this.getContentPane().add(canvas);
}

private void doIt() throws Exception {
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.lookAt(plane.getTransformedCenter());

projector.setFOV(0.5f);
projector.setYFOV(0.5f);


SimpleVector pos=cube.getTransformedCenter();

projector.setPosition(pos);
projector.moveCamera(Camera.CAMERA_MOVEUP, 200);
projector.lookAt(pos);
SimpleVector offset=new SimpleVector(1,0,-1).normalize();
projector.moveCamera(offset, 215);

while (!fin) {

projector.lookAt(cube.getTransformedCenter());
offset.rotateY(0.007f);
projector.setPosition(pos);
projector.moveCamera(new SimpleVector(0,-1,0), 200);
projector.moveCamera(offset, 215);
sun.setPosition(projector.getPosition());

sh.updateShadowMap();

fb.clear();
sh.drawScene();

fb.update();
fb.displayGLOnly();

canvas.repaint();     

Thread.sleep(10);
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}

public static void main(String[] args) throws Exception {
SimpleShadows cd = new SimpleShadows();
cd.initStuff();
cd.setVisible(true);
cd.pack();
cd.setBounds(new Rectangle(640,480));
cd.doIt();
}
}


Thanks very much.

EgonOlsen

You code works fine for me even when disabling FBOs. Can you please post the complete log that your code prints out on your machine? And double check if you are really using the correct jar to run this.

roninjnj

I have finished download and install lastes drivers for my ATI mobility redeon X700.

Its works fine, FBOs warning has gone, now said FBO is supported and used.

All samples works fine and mi application works fine :-(

I apologize for wasting your time :-(

Thanks very much yet.

EgonOlsen

I'm glad that it works now, but it should have worked without FBOs too... ???