Show
Ignore:
Timestamp:
12/09/07 17:06:14 (6 years ago)
Author:
robert
Message:

From Mihai Radu, "After someone asked for a fix for non-textured object appearing black
with the shader for textured objects. This works very well in cases
where there could be a mix of textured and non-textured objects in the
scene, and it makes the initialization more robust.
The idea is from PSSM, to add a 1pixel texture to the main rendering as
to provide white for any objects missing textures."

Files:
1 modified

Legend:

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

    r7545 r7635  
    7575        "{ \n" 
    7676        "   vec4 texResult = texture2D(osgShadow_shadowTexture, gl_TexCoord[0].st ); \n" 
    77         "   float value = texResult.g - 0.5; \n" 
     77        "   float value = texResult.r + 0.5; \n" 
    7878        "   gl_FragColor = vec4( value, value, value, 0.8 ); \n" 
    7979        "} \n"; 
     
    254254            } 
    255255 
     256            { 
     257                // fake texture for baseTexture, add a fake texture 
     258                // we support by default at least one texture layer 
     259                // without this fake texture we can not support 
     260                // textured and not textured scene 
     261 
     262                // TODO: at the moment the PSSM supports just one texture layer in the GLSL shader, multitexture are 
     263                //       not yet supported ! 
     264 
     265                osg::Image* image = new osg::Image; 
     266                // allocate the image data, noPixels x 1 x 1 with 4 rgba floats - equivilant to a Vec4! 
     267                int noPixels = 1; 
     268                image->allocateImage(noPixels,1,1,GL_RGBA,GL_FLOAT); 
     269                image->setInternalTextureFormat(GL_RGBA); 
     270                // fill in the image data. 
     271                osg::Vec4* dataPtr = (osg::Vec4*)image->data(); 
     272                osg::Vec4 color(1,1,1,1); 
     273                *dataPtr = color; 
     274                // make fake texture 
     275                osg::Texture2D* fakeTex = new osg::Texture2D; 
     276                fakeTex->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER); 
     277                fakeTex->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER); 
     278                fakeTex->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); 
     279                fakeTex->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); 
     280                fakeTex->setImage(image); 
     281                // add fake texture 
     282                _stateset->setTextureAttribute(_baseTextureUnit,fakeTex,osg::StateAttribute::ON); 
     283                _stateset->setTextureMode(_baseTextureUnit,GL_TEXTURE_1D,osg::StateAttribute::OFF); 
     284                _stateset->setTextureMode(_baseTextureUnit,GL_TEXTURE_2D,osg::StateAttribute::ON); 
     285                _stateset->setTextureMode(_baseTextureUnit,GL_TEXTURE_3D,osg::StateAttribute::OFF); 
     286            } 
    256287        } 
    257288