Jump to content
  • Advertisement
Sign in to follow this  
uto314

sampler2DShadow - glsl

This topic is 5320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, do someone ever use (or heard about) the sampler2DShadow glsl texture sampler, because I am looking for some documentation or tutorials about it (I would like to use this for shadow mapping or at least knows the advantage of that sampler for depth map texture). Thanks, -uto-

Share this post


Link to post
Share on other sites
Advertisement
Hello..
I just did that, using sampler2DShadow.

Here's the code (doing diffuse-lighting as well):

Vertex program:

varying float Diffuse;
varying vec2 TexCoord;
varying vec4 ProjShadow;
uniform vec3 LightDirection;

void main(void)
{
vec3 realNorm = gl_NormalMatrix * gl_Normal;
Diffuse = max(dot(-LightDirection, realNorm), 0.0);
TexCoord = gl_MultiTexCoord0;
ProjShadow = gl_TextureMatrix[1] * gl_Vertex;
gl_Position = ftransform();
}



Fragment program:

uniform sampler2D Checker;
uniform sampler2DShadow ShadowMap;

varying vec4 ProjShadow;
varying float Diffuse;
varying vec2 TexCoord;

void main (void)
{
vec3 color = texture2D(Checker, TexCoord).stp;
color *= shadow2DProj(ShadowMap, ProjShadow).r;
color *= Diffuse;
gl_FragColor = vec4(color, 1);
}



There you go. :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is very helpfull, moreover this is a good way to deal with shadow map,
thanks,
-uto-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!