Hello.
I try to implement shadowmapping for my scenes but i cant get shadow2D to work.
Here are the parts of code for shadowmapping using texture2D:
Vertex shader
--------------------
shadow_coords = light_projection * light_view * vertex;
shadow_coords.xy = shadow_coords.xy / 2.0 + 0.5 * shadow_coords.w;
shadow_coords = shadow_coords / shadow_coords.w;
//linear z clamped in [0,1], same function is used in Depth pass to
write the Z in depth buffer
shadow_coords.z = getLinearDepth(light_view, vertex, light_near, light_far);
Fragment shader
------------------------
vec4 shadowmap_color = texture2D(light_depth_texture, shadow_coords.xy);
float shadowmap_depth = shadowmap_color.r;
if ( shadow_coords.z - 0.005 > shadowmap_depth) {
//shadowed
}
First of all everything works.
But when i change sampler2D to sampler2DShadow and texture2D to
shadow2D it doesnt work.
Here is where i create the depth buffer (shadow comparison is enabled
for shadow2D):
Texture2D* createDepthTexture(int width, int height){
Texture2D* texture2d = new osg::Texture2D;
texture2d->setTextureSize(width,height);
texture2d->setInternalFormat(GL_DEPTH_COMPONENT24);
texture2d->setSourceFormat(GL_DEPTH_COMPONENT);
texture2d->setSourceType(GL_UNSIGNED_BYTE);
texture2d->setShadowComparison(true);
texture2d->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
texture2d->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
texture2d->setBorderColor(osg::Vec4(1,0,0,1));
texture2d->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
texture2d->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
return texture2d;
}
In texture sampling, shadow2D returns always 0:
float shadowmap_dif = shadow2D(light_depth_texture,
vec3(shadow_coords.xy, shadow_coords.z - 0.005));
Is there anything else i have to change to make it work ?
Thank you for your time.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org