shadow mapping

I’m trying to add shadow mapping to my Xith3D-poject. The JOGL version of NVIDIA’s HWShadowmapsSimple is my starting point.

After playing with HWShadowmapsSimple and many looks in the Xith3d source code, I think I have to implement the following parts:

  1. Create an empty texture (should be a depth texture later; GL_ARB_depth_texture) as shadow map (if possible without big changes to Texture2D and TextureShaderPeer):

By now:

int texSize = 512;
byte buffer[] = new byte[texSize*texSize*3];

texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, texSize, texSize);
ImageComponent2D im = new ImageComponent2D(ImageComponent.FORMAT_RGB, texSize, texSize, false, false);
BufferedImage bi = DirectBufferedImage.getDirectImageRGB(texSize, texSize, buffer);

im.set(bi);
texture.setImage(0, im);

Is there a better way to do this?

  1. Create a pbuffer in the same GL-Context as the instance of CanvasPeerImpl of the camera’s view:

I override CanvasPeerImpl and create the pbuffer during the initialization.

public class CanvasPeerMyImpl extends CanvasPeerImpl {
 PBuffer pbuffer;

  public void init(GLDrawable drawable) {
   super.init(drawable);
   pbuffer = drawable.createOffscreenDrawable(caps, width, height)
  }
}
  1. Use an instance of View.java to render the scene from the light’s point of view to the pbuffer (flat shading, depth texture …):

I don’t want to change the View class. Maybe I could implement something like PbufferPeerImpl (implements CanvasPeer)
and add it instead of CanvasPeerImpl to the Canvas3D attached to the view at the light’s point of view?
Something like:

View lightView = new View();

PbufferPeerImpl pbufferPeer = PbufferPeerImpl(...);
Canvas3D shadowCanvas = new Canvas3D();
canvas.set3DPeer(pbufferPeer);

lightView.addCanvas3D(shadowCanvas);

...

lightView.renderOnce();
cameraView.renderOnce();

The PbufferPeerImpl’s Pbuffer should be created as described under 2.

  1. Copy the pbuffer to the texture:

By now, I’m able to copy the Back Buffer to a texture with these lines:

public class CanvasPeerMyImpl extends CanvasPeerImpl {
 public void display(GLDrawable drawable) {
  super.display(drawable);
  gl.glBindTexture(GL.GL_TEXTURE_2D, 1);
  gl.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0,   100, 100,   0, 0,  400, 300);
  gl.glFlush();
 }
}

First the PBuffer should be rendered and copied to the texture, second the camera’s view should be rendered (using the depth texture).


Please be honest, if this approach is completely stupid or won’t work for any reason. This is my plan after studying the overview of the xith3d rendering pipeline and the jogl-example.

I’m grateful for any hint.

I think it won’t work :frowning:

I would have to change many lines at least in the following classes:

View.java
CanvasPeerImpl.java
maybe all ShaderPeers (because of cast from CanvasPeer to CanvasPeerImpl)

plus extending CanvasPeerImpl to an own Impl and so on.

Another possibility would be rendering the shadow map completely
new without using the xith3d rendering pipeline (not very nice).

Ok, my project doesn’t have many objects so i’ll implement everything
directly in JOGL.