Sign in to follow this  
Bruno

Blending two textures ( depth map with a alpha map )

Recommended Posts

Hey, This is the situation, I have a tree with a foliage texture, and i have the depth shadowmap of that tree. I want to do self shadowing with the tree itself, so i want to apply the shadowmap only where the alpha test passes in the foliage texture. I think this should be working, but it ins't, tex0 has the shadowmap, tex1 has the foliage alpha map texture This is my vertex shader : varying vec4 projCoord; void main() { vec4 realPos = gl_ModelViewMatrix * gl_Vertex; projCoord = gl_TextureMatrix[0] * realPos; gl_TexCoord[1] = gl_MultiTexCoord1; gl_Position = ftransform(); } This is my fragment shader : uniform sampler2DShadow shadowMap; uniform sampler2D textureMap; varying vec4 projCoord; void main () { const float kTransparency = 0.3; vec4 color = tex2D(textureMap, gl_TexCoord[1].xy); //alpha map vec3 shadowUV = projCoord.xyz / projCoord.q; float mapScale = 1.0 / 2048.0; vec4 shadowColor = shadow2D(shadowMap, shadowUV); if(shadowUV.x >= 0.0 && shadowUV.y >= 0.0 && shadowUV.x <= 1.0 && shadowUV.y <= 1.0 && color.w >= 0) { gl_FragColor = color * shadowColor; } else { discard; } } Both texture units are set. Am i doing anything wrong here ? thanks, Bruno

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this