Shadowmaps with fragment and vertex programs?

Started by
5 comments, last by _the_phantom_ 19 years, 6 months ago
I am wondering is it possible to make a shadowmap completely in a fragment and vertex program without using glTexGen at all? If so does anyone know of a good tutorial on such a topic? Most tutorials I see are for FFP coding with glTexGen. Also I am going to assume this method would be faster due to its computed by the GPU? Thanks
Advertisement
yes one possible way in glsl would be

--vertex shader--
projected_coord = gl_TextureMatrix[0] * gl_Vertex;


fragement shader--
uniform sampler2DShadow tex3;
vec4 shadow = shadow2DProj( tex3, projected_coord );


gl_TextureMatrix[0] is supplied with the stanadrad lightprojection matrix * lightmodelview matrix
Quote:Original post by zedzeek
yes one possible way in glsl would be

--vertex shader--
projected_coord = gl_TextureMatrix[0] * gl_Vertex;


fragement shader--
uniform sampler2DShadow tex3;
vec4 shadow = shadow2DProj( tex3, projected_coord );


gl_TextureMatrix[0] is supplied with the stanadrad lightprojection matrix * lightmodelview matrix


Thanks zedeek, but as of now I only have access to fragment program and vertex program. And I have a lot of my texturing and lighting done in a fragment program and dont' want to move it over to Glslang right now. I am assuming the shadow2DProj() is a built in function of GLSlang? Thanks again.

its just a function which performs a texture lookup allowing for projection, i'm sure that the fragment program interface has the same thing

btw, you have to scale/bias the texture matrix/lookup as well or it will go wonky (you need the vertex to be in the range 0 -> 1 however post transform by the matrix the vertex can be in the range -1 => 1) so you need to add 1 and multiply by 0.5.

You should be able to compress that all down into the texture matrix, however I never got around to doing that myself, i might go back and look at it again this weekend...
Quote:Original post by _the_phantom_
its just a function which performs a texture lookup allowing for projection, i'm sure that the fragment program interface has the same thing

btw, you have to scale/bias the texture matrix/lookup as well or it will go wonky (you need the vertex to be in the range 0 -> 1 however post transform by the matrix the vertex can be in the range -1 => 1) so you need to add 1 and multiply by 0.5.

You should be able to compress that all down into the texture matrix, however I never got around to doing that myself, i might go back and look at it again this weekend...


Hey Phantom if you would I would appreciate it a lot. I am looking at doing the shadowmap totally with vertex/fragment program and not using any FFP code...

If it would be ok I would like to email you?

Thanks
Also would I need to use two passes with a VP/FP like with FFP? As of now my FP uses seven texture units? so unless I can access more than eight I am thinking I will have to use two passes two add a shadowmap to my eight texture unit in my final FP? Thanks
yes, you will, because the first pass is still required to construct the shadow map for later useage.

I'll see if I can get around to sorting out the matrix stuff later today...

This topic is closed to new replies.

Advertisement