|
Hui, hui wrote: The current ShadowMap is buggy and only works with default values for the texture units when the default shaders are used. The defaults are for texture unit 0 to be any texture you have already applied to the scene and for texture unit 1 to be the shadow map texture used internally by ShadowMap. The only other configuration that works is for you to call ShadowMap::setTextureUnit(0) in which case texture unit 0 will be used for the internal shadow map texture unit and no other texturing will be applied to the scene.Hi, I work on project need shadow between avatar and model, and I add shadowmap as the example code but it doesn't work. I read the shadow example and seems that the glsl shader only has two texture unit, one for shadowbase and one for shadowTexture. Do I need to assign my own texture unit for the shadow receiver? Another question, do I need to create a vertext shader to calculate the matrix transformation between two camera(one light, one main cam)?Thanks a lot. Hui Here is some code you can use to set a different internal texture unit to ShadowMap std::string MyFragmentShaderSource( "uniform sampler2D osgShadow_baseTexture; \n" "uniform sampler2DShadow osgShadow_shadowTexture; \n" "uniform vec2 osgShadow_ambientBias; \n" "\n" "void main(void) \n" "{ \n" " vec4 color = gl_Color * texture2D( osgShadow_baseTexture, gl_TexCoord[0].xy ); \n" " gl_FragColor = color * (osgShadow_ambientBias.x + shadow2DProj( osgShadow_shadowTexture, gl_TexCoord[XXXX] ) * osgShadow_ambientBias.y); \n" "}\n"); m_pShadowedScene = new osgShadow::ShadowedScene; osg::ref_ptr<osgShadow::ShadowMap> pShadowMap = new osgShadow::ShadowMap; m_pShadowedScene->setShadowTechnique(pShadowMap.get()); std::string::size_type Offset = MyFragmentShaderSource.find("XXXX"); MyFragmentShaderSource.erase(Offset, 4); char TempBuff[5]; _itoa(m_ShadowTextureUnit, TempBuff, 10); MyFragmentShaderSource.insert(Offset, TempBuff); pShadowMap->addShader(new osg::Shader(osg::Shader::FRAGMENT, MyFragmentShaderSource)); pShadowMap->setTextureUnit(m_ShadowTextureUnit); //pShadowMap->init(); // Need to call this if the OSG update visitor not being used or ShadowMap::setDebugHUD is not called Roger |
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

