Hello all,
I worked on the problem and now I get the objects which will cast a shadow 
in black. Does anyone have an idea about the reason of this or an idea how 
to obtain shadows from shaders with another approach? I have attached an 
example to this e-mail.

Thank you in advance.

Sincerely,
Diclehan Ulucan
Diclehan Ulucan schrieb am Dienstag, 26. Oktober 2021 um 19:02:08 UTC+2:

> 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/16adfecd-7be6-4de5-a608-0e2c3e4115cbn%40googlegroups.com.

Reply via email to