PDA

View Full Version : how to write this in GLSL?



fazekaim
09-29-2005, 12:03 AM
Hello,

i implemented the LispSM shadows using the original paper, with "normal" OpenGL calls. How can i write a GLSL code with the same effect?


double x[] = {1.0, 0.0, 0.0, 0.0};
double y[] = {0.0, 1.0, 0.0, 0.0};
double z[] = {0.0, 0.0, 1.0, 0.0};
double w[] = {0.0, 0.0, 0.0, 1.0};
double bias[] = {0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0};

gl.glActiveTextureARB(GL.GL_TEXTURE0);

gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
gl.glEnable(GL.GL_TEXTURE_GEN_R);
gl.glEnable(GL.GL_TEXTURE_GEN_Q);

gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGeni(GL.GL_Q, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);

gl.glTexGendv(GL.GL_S, GL.GL_EYE_PLANE, x);
gl.glTexGendv(GL.GL_T, GL.GL_EYE_PLANE, y);
gl.glTexGendv(GL.GL_R, GL.GL_EYE_PLANE, z);
gl.glTexGendv(GL.GL_Q, GL.GL_EYE_PLANE, w);
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glLoadMatrixd(bias);
gl.glMultMatrixd( LispSM.lightProjection );
gl.glMultMatrixd( LispSM.lightView );
gl.glMatrixMode(GL.GL_MODELVIEW);

activateTexture( 0, shadowFBORenderBuffer[0], GL.GL_TEXTURE_2D );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE_ARB, GL.GL_COMPARE_R_TO_TEXTURE_ARB);

rendering...

deactivateTexture( 0, GL.GL_TEXTURE_2D );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE_ARB, GL.GL_NONE);

gl.glActiveTextureARB( GL.GL_TEXTURE0);
//Disable textures and texgen
gl.glMatrixMode( GL.GL_TEXTURE);
gl.glLoadIdentity();
gl.glMatrixMode( GL.GL_MODELVIEW);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE_ARB, GL.GL_NONE);
gl.glDisable( GL.GL_TEXTURE_2D);
gl.glDisable( GL.GL_TEXTURE_GEN_S);
gl.glDisable( GL.GL_TEXTURE_GEN_T);
gl.glDisable( GL.GL_TEXTURE_GEN_R);
gl.glDisable( GL.GL_TEXTURE_GEN_Q);
gl.glActiveTextureARB( GL.GL_TEXTURE0);



....
texture parameters in texture creation code:
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);

gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_FUNC_ARB, GL.GL_LEQUAL);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_DEPTH_TEXTURE_MODE_ARB, GL.GL_LUMINANCE);Thanks.

dorbie
09-29-2005, 09:05 AM
All you have here that a shader would implement is texgen, the matrix transforms (including texture) and the texenv (like the shadow compare). The first two in a vertex shader, the last in a fragment shader.

Other stuff like the coordinates and texture setup would remain the same.

You need to start by understanding the role a shader plays in an algorithm like this and you can start by distinguishing state and attribute setup, from vertex shader from fragment shader.