Hi Michael,

You are right. There can only be one shader program loaded which has to do all 
the work.
If you overload the default shader from osgShadow, it has to do that work 
together with your new stuff.

In my case I just created my own class Cl_SoftShadowMap, derived from 
osgSoftShadowmap. I reimplemented two methods:

// If our shader needs additional uniforms, they may be set here
void Cl_SoftShadowMap::createUniforms() {
    _uniformList.clear();
    SoftShadowMap::createUniforms();

    // This Variable will be set by any node using textures
    _uniformList.push_back(new osg::Uniform(USE_TEXTURE_UNIFORM, false));

    // Shadow creation can be switched on an off (we still need our shaders)
    useShadowUniform = new osg::Uniform(USE_SHADOW_MAP_UNIFORM, useShadow);
    _uniformList.push_back(useShadowUniform.get());

    // Toggle between soft and hard shadows
    useSoftShadowUniform = new osg::Uniform(USE_SOFT_SHADOW_UNIFORM, 
                                            useSoftShadow);
    _uniformList.push_back(useSoftShadowUniform.get());

    // Uniforms used for bump mapping
    _uniformList.push_back(new osg::Uniform(USE_BUMP_MAP_UNIFORM, false));
    _uniformList.push_back(new osg::Uniform("bumpMap", BUMP_TEXTURE_UNIT));
}

// We create our own shaders
void Cl_SoftShadowMap::createShaders(bool _enableShadow, 
                                     bool _enableBumpMapping, 
                                     bool _enableDisplacementMapping) {
    if( _shaderList.empty() ) {
        osg::ref_ptr<osg::Shader> vertexShader;
        vertexShader = Cl_ShaderGen::getShader(osg::Shader::VERTEX,
                                               _enableShadow,
                                               _enableBumpMapping, 
                                               _enableDisplacementMapping);
        _shaderList.push_back(vertexShader);
        osg::ref_ptr<osg::Shader> fragmentShader;
        fragmentShader = Cl_ShaderGen::getShader(osg::Shader::FRAGMENT, 
                                               _enableShadow,
                                               _enableBumpMapping,
                                               _enableDisplacementMapping);
        _shaderList.push_back(fragmentShader);
    }
}

By this way your own shaders get loaded an you can create any uniform youneed.
You can use it by calling shadowScene->setShadowTechnique(...);

I hope this helps.

- Werner -


On Tuesday 21 September 2010 15:25:23 Michael Irby II wrote:
> Hi,
> 
> So I have been experimenting with shadows in OSG using the ShadowMap shadow
> technique. With the default OSG implementation and every custom shader in
> my scene graph disabled the shadows work correctly. Once I turn my shaders
> on they stop working. This is understandable as he OSG shadow shader will
> be overridden. I then reimplemented the shadow projection code in my pixel
> shaders, but then still no shadows. I am not too familiar with the OpenGL
> fixed-function shadow pipeline. If you do not provide a vertex shader does
> OpenGL generate the proper texture coordinates by default. I saw that OSG
> was creating a TexGen attribute and applying that after shadow map
> creation. If I am implementing custom vertex shaders should I be
> overriding the ShadowMap and not allowing that TexGen to be created and
> then generate the proper texture coordinates in my vertex shader? At this
> point I think all that is missing is the proper texture coordinates for
> shadows to be working for me. Any help woul d be appreciated. Thanks in
> advance!
> 
> Cheers,
> Michael
> 
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=31896#31896
> 
> 
> 
> 
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-- 
TEXION Software Solutions

TEXION GmbH -  Rotter Bruch 26a  -  D 52068 Aachen - HRB 14999 Aachen
Fon: +49 241 475757-0, Fax: +49 241 475757-29, web: http://www.texion.eu

Geschäftsführer/Managing Director: Werner Modenbach
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to