Hello all,
I am facing a problem with the ShadowMap. I would like to add shadows to a
scene which includes different textures for objects. When I add the shader
for ShadowMap I get an all black scene. As far as I know this happens due
to Ambient Bias, however setting it to some value in range [0,1] did not
help me. Has anyone else faced this kind of problem or has an idea that
might help? I would appreciate your help. My code is as follows:
osg::ref_ptr<osgShadow::ShadowedScene> scene = new osgShadow::ShadowedScene;
scene->addChild(Obj1.get());
osg::ref_ptr<osg::Shader> vertShader = new osg::Shader(osg::Shader::VERTEX);
osg::ref_ptr<osg::Shader> fragShader = new
osg::Shader(osg::Shader::FRAGMENT);
vertShader->loadShaderSourceFromFile("source.vert");
fragShader->loadShaderSourceFromFile("source.frag");
osg::ref_ptr<osg::Program> program = new osg::Program;
program->addShader(vertShader.get());
program->addShader(fragShader.get());
osg::Vec4 lightPos(0.0,75.0,75.0,1.0);
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
ls->getLight()->setPosition(lightPos);
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
sm->setLight(ls->getLight());
scene->setShadowTechnique(sm.get());
osg::ref_ptr<osg::StateSet> stateset= Obj1->getOrCreateStateSet();
stateset->setAttributeAndModes(program.get());
osg::ref_ptr<osg::Image> imagetex=osgDB::readImageFile("texture1.jpg");
osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D;
texture->setImage(imagetex.get());
stateset->setTextureAttributeAndModes(0,texture.get());
....
viewer.getCamera()->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
viewer.setSceneData(scene.get());
viewer.run();
//fragment shader
uniform sampler2D osgShadow_baseTexture;
uniform sampler2DShadow osgShadow_shadowTexture;
uniform vec2 osgShadow_ambientBias;
void main()
{
vec4 color = gl_Color * texture2D( osgShadow_baseTexture,
gl_TexCoord[0].xy );
gl_FragColor = color * (osgShadow_ambientBias.x+ shadow2DProj(
osgShadow_shadowTexture, gl_TexCoord[1] ) * osgShadow_ambientBias.y);
}
Best Regards,
Diclehan Ulucan
--
You received this message because you are subscribed to the Google Groups
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/osg-users/fe22aaa6-c47b-4fbf-a5a7-6d623eb1493cn%40googlegroups.com.