hi folks!!

I have a problem with resolution of my depth shadow, in the classic osg
example, we have the function, createShadowedScene, and whithin it there are
two variables  unsigned int tex_width = 1024;   unsigned int tex_height =
1024;

theses variables are used to setting up the

osg::Texture2D* texture = new osg::Texture2D;
texture->setTextureSize(tex_width, tex_height);

 osg::CameraNode* camera = new osg::CameraNode;
 camera->setViewport(0,0,tex_width,tex_height);


I found a solution for increase my shadow resolution, just change the values
to 4096, and the shadow resolution getting better so much!

however, when I do it, the projection on the floor of my light is so tight,
covering just a little part of floor,

whats the possible problem?

thanks guys!

Rafael


-----


osg::Group* createShadowedScene(osg::Node* shadowed,osg::MatrixTransform*
light_transform, unsigned int unit)
{
   osg::Group* group = new osg::Group;

   unsigned int tex_width = 4096;
   unsigned int tex_height = 4096;

   osg::Texture2D* texture = new osg::Texture2D;
   texture->setTextureSize(tex_width, tex_height);

   texture->setInternalFormat(GL_DEPTH_COMPONENT);
   texture->setShadowComparison(true);
   texture->setShadowTextureMode(Texture::LUMINANCE);
   texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
   texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);


   // set up the render to texture camera.
   {

       // create the camera
       osg::CameraNode* camera = new osg::CameraNode;

       camera->setClearMask(GL_DEPTH_BUFFER_BIT);
       camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

camera->setComputeNearFarMode(osg::CameraNode::DO_NOT_COMPUTE_NEAR_FAR);

       // set viewport
       camera->setViewport(0,0,tex_width,tex_height);

       osg::StateSet*  _local_stateset = camera->getOrCreateStateSet();

       _local_stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);


       float factor = 0.0f;
       float units = 1.0f;

       ref_ptr<PolygonOffset> polygon_offset = new PolygonOffset;
       polygon_offset->setFactor(factor);
       polygon_offset->setUnits(units);
       _local_stateset->setAttribute(polygon_offset.get(),
StateAttribute::ON | StateAttribute::OVERRIDE);
       _local_stateset->setMode(GL_POLYGON_OFFSET_FILL, StateAttribute::ON
| StateAttribute::OVERRIDE);


       ref_ptr<CullFace> cull_face = new CullFace;
       cull_face->setMode(CullFace::FRONT);
       _local_stateset->setAttribute(cull_face.get(), StateAttribute::ON |
StateAttribute::OVERRIDE);
       _local_stateset->setMode(GL_CULL_FACE, StateAttribute::ON |
StateAttribute::OVERRIDE);


       // set the camera to render before the main camera.
       camera->setRenderOrder(osg::CameraNode::PRE_RENDER);

       // tell the camera to use OpenGL frame buffer object where
supported.

camera->setRenderTargetImplementation(osg::CameraNode::FRAME_BUFFER);

       // attach the texture and use it as the color buffer.
       camera->attach(osg::CameraNode::DEPTH_BUFFER, texture);

       // add subgraph to render
       camera->addChild(shadowed);

       group->addChild(camera);

       // create the texgen node to project the tex coords onto the
subgraph
       osg::TexGenNode* texgenNode = new osg::TexGenNode;


       texgenNode->setTextureUnit(unit);
       group->addChild(texgenNode);

       // set an update callback to keep moving the camera and tex gen in
the right direction.
       group->setUpdateCallback(new
UpdateCameraAndTexGenCallback(light_transform, camera, texgenNode));
   }


   // set the shadowed subgraph so that it uses the texture and tex gen
settings.
   {
       osg::Group* shadowedGroup = new osg::Group;
       shadowedGroup->addChild(shadowed);
       group->addChild(shadowedGroup);

       osg::StateSet* stateset = shadowedGroup->getOrCreateStateSet();

stateset->setTextureAttributeAndModes(unit,texture,osg::StateAttribute::ON);

stateset->setTextureMode(unit,GL_TEXTURE_GEN_S,osg::StateAttribute::ON);

stateset->setTextureMode(unit,GL_TEXTURE_GEN_T,osg::StateAttribute::ON);

stateset->setTextureMode(unit,GL_TEXTURE_GEN_R,osg::StateAttribute::ON);


stateset->setTextureMode(unit,GL_TEXTURE_GEN_Q,osg::StateAttribute::ON);

       osg::Program* program = new osg::Program;
       stateset->setAttribute(program);

       if (unit==0)
       {
           osg::Shader* fragment_shader = new
osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource_noBaseTexture);
           program->addShader(fragment_shader);

           osg::Uniform* shadowTextureSampler = new
osg::Uniform("shadowTexture",(int)unit);
           stateset->addUniform(shadowTextureSampler);
       }
       else
       {
           osg::Shader* fragment_shader = new
osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource_withBaseTexture);
            program->addShader(fragment_shader);


        //   osg::Uniform* baseTextureSampler = new
osg::Uniform("baseTexture",1);
        //   stateset->addUniform(baseTextureSampler);

           osg::Uniform* shadowTextureSampler = new
osg::Uniform("shadowTexture",(int)unit);
           stateset->addUniform(shadowTextureSampler);
       }

     osg::Uniform* ambientBias = new osg::Uniform("ambientBias",osg::Vec2(
0.3f,1.2f));
    //   osg::Uniform* ambientBias = new
osg::Uniform("ambientBias",osg::Vec2(0.02f,0.03f));
       stateset->addUniform(ambientBias);

   }

   // add the shadower and shadowed.
   group->addChild(light_transform);

   return group;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to