Matrix math in JOGL

Hi.

I’ve asked a similar question in a reply to a different thread but I thought I’d simplify…

How do I go about doing this:

MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix;

in JOGL using float[16] instead of MATRIX4x4 as listed in the C example above?

Thanks in advance to anyone who can help!

Well JOGL is just a binding for the OpenGL API. In order to perform the operations you want you’ll need to use OpenGL’s matrix stack and operations… so it might be something like

gl.glLoadIdentity()
gl.glMultMatrixf(biasMatrix)

//or you could combine the first to operations into one
//gl.glLoadMatrixf(biasMatrix)

gl.glMultMatrixf(projMatrix)
gl.glMultMatrixf(viewMatrix)

Thanks for the reply.

So, how then do I access each row of the matrix used in the code that follows? It’s part of a shadow map… textureMatrix being the float[16] that I’m using.

gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_S, GL.GL_EYE_PLANE, textureMatrix, 0);
		gl.glEnable(GL.GL_TEXTURE_GEN_S);
	
		gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_T, GL.GL_EYE_PLANE, textureMatrix, 4);
		gl.glEnable(GL.GL_TEXTURE_GEN_T);
	
		gl.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_R, GL.GL_EYE_PLANE, textureMatrix, 8);
		gl.glEnable(GL.GL_TEXTURE_GEN_R);
	
		gl.glTexGeni(GL.GL_Q, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_Q, GL.GL_EYE_PLANE, textureMatrix, 12);
		gl.glEnable(GL.GL_TEXTURE_GEN_Q);

Ok, I figured it out myself through trial and error! Still got a lot of tidying up to do though in my code, I’ve pasted it below in case it helps anyone else. For some reason the shadow map has absolutely killed my framerate. I was getting >300fps with one light source and 350,000 polygons, now with shadows it’s dropped to 70fps 1/5th!!

Is this normal??? Anyway the code snippet is below…


{	int j=0,k=0;
			for(int i = 0; i < 16; i++) {
				bm.set(j,k,biasMatrix[i]);
				lpm.set(j,k,lightProjectionMatrix[i]); 
				lvm.set(j,k,lightViewMatrix[i]);
				j++; if(j>3) j=0;
				if(j==0) k++;
		}	}
		
		tm = bm.mul(lpm.mul(lvm));
		
		//tm.getColumnMajorData(textureMatrix);
		
		{	int j=0,k=0;
			for(int i = 0; i < 16; i++) {
				textureMatrix[i] = tm.get(k,j);
				j++; if(j>3) j=0;
				if(j==0) k++;
		}	}
		
		//Set up texture coordinate generation.
		gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_S, GL.GL_EYE_PLANE, textureMatrix, 0);
		gl.glEnable(GL.GL_TEXTURE_GEN_S);
	
		gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_T, GL.GL_EYE_PLANE, textureMatrix, 4);
		gl.glEnable(GL.GL_TEXTURE_GEN_T);
	
		gl.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_R, GL.GL_EYE_PLANE, textureMatrix, 8);
		gl.glEnable(GL.GL_TEXTURE_GEN_R);
	
		gl.glTexGeni(GL.GL_Q, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
		gl.glTexGenfv(GL.GL_Q, GL.GL_EYE_PLANE, textureMatrix, 12);
		gl.glEnable(GL.GL_TEXTURE_GEN_Q);

It can be, first of all if you are geometry limited you can see your performance drop by 1/2. The additional drop can come if you aren’t doing some sort of render-to-texture and instead having to copy the shadow buffer to a texture. Are you using frame buffer objects?

Hi. No I’m not… just following this tutorial: http://www.paulsprojects.net/tutorials/smt/smt.html

Do you know any good resources for learning about FBO’s and how to use with shadow maps, to boost performance? Are there any other shadowing techniques I should be looking at?

Cheers.

Matt

The extension specification…
http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt

Best quick tutorial I’ve found so far…

In a nut shell you’d call glBindRenderbufferEXT(FBO) before drawing from the light’s pov, bind back to glBindRenderbufferEXT(0) right after words, and if I remember correctly, if you constructed your FBO correctly you can then just bind the texture and avoid the glCopyTexSubImage2D() altogether.

There’s really not much more to it, the simplicity of the algorithm is part of what makes it so appealing. If you find that you still have an enormous performance hit, just consider that free fill-rate or shader cycles :).

Oh by the way, I’d always be interested in hearing what FBOs did for your performance if you got them working.