Show
Ignore:
Timestamp:
12/15/07 16:17:51 (7 years ago)
Author:
robert
Message:

Tweaked the abmient lighting contribution so that the OpenGL vertex lighting has
the ambient light source switched off, and use the fragment shader to add this
contribution back in.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgShadow/ShadowMap.cpp

    r7648 r7690  
    8282    _baseTextureUnit(0), 
    8383        _shadowTextureUnit(1), 
    84         _ambientBias(0.3f,1.2f), 
     84        _ambientBias(0.5f,0.5f), 
    8585        _textureSize(1024,1024) 
    8686    { 
     
    134134        _uniformList.push_back(shadowTextureSampler); 
    135135 
    136         osg::Uniform* ambientBias = new osg::Uniform("osgShadow_ambientBias",_ambientBias); 
    137         _uniformList.push_back(ambientBias); 
     136        _ambientBiasUniform = new osg::Uniform("osgShadow_ambientBias",_ambientBias); 
     137        _uniformList.push_back(_ambientBiasUniform.get()); 
    138138 
    139139    } 
     
    202202            osg::StateSet* stateset = _camera->getOrCreateStateSet(); 
    203203 
    204             float factor = 0.0f; 
    205             float units = 1.0f; 
     204 
     205#if 1 
     206            // cull front faces so that only backfaces contribute to depth map 
     207 
     208            osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace; 
     209            cull_face->setMode(osg::CullFace::FRONT); 
     210            stateset->setAttribute(cull_face.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
     211            stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
     212 
     213            // negative polygonoffset - move the backface nearer to the eye point so that backfaces 
     214            // shadow themselves 
     215            float factor = -1.0f; 
     216            float units = -1.0f; 
    206217 
    207218            osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset; 
     
    210221            stateset->setAttribute(polygon_offset.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
    211222            stateset->setMode(GL_POLYGON_OFFSET_FILL, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
    212  
    213             osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace; 
    214             cull_face->setMode(osg::CullFace::FRONT); 
    215             stateset->setAttribute(cull_face.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
    216             stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
    217  
     223#else 
     224            // disabling cull faces so that only front and backfaces contribute to depth map 
     225            stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); 
     226 
     227            // negative polygonoffset - move the backface nearer to the eye point 
     228            // so that front faces do not shadow themselves. 
     229            float factor = 1.0f; 
     230            float units = 1.0f; 
     231 
     232            osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset; 
     233            polygon_offset->setFactor(factor); 
     234            polygon_offset->setUnits(units); 
     235            stateset->setAttribute(polygon_offset.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
     236            stateset->setMode(GL_POLYGON_OFFSET_FILL, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
     237#endif 
    218238        } 
    219239 
     
    353373            } 
    354374        } 
    355  
     375         
    356376        osg::Matrix eyeToWorld; 
    357377        eyeToWorld.invert(*cv.getModelViewMatrix()); 
     
    364384        if (selectLight) 
    365385        { 
     386 
     387            // set to ambient on light to black so that the ambient bias uniform can take it's affect 
     388            const_cast<osg::Light*>(selectLight)->setAmbient(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 
    366389 
    367390            //std::cout<<"----- VxOSG::ShadowMap selectLight spot cutoff "<<selectLight->getSpotCutoff()<<std::endl;