From 81dab87154ec55982d0ed183b5af55e8301a3f74 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 6 Aug 2005 04:33:56 +0000 Subject: [PATCH] Added blend shadow fragment shader --- examples/osgdepthshadow/osgdepthshadow.cpp | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/examples/osgdepthshadow/osgdepthshadow.cpp b/examples/osgdepthshadow/osgdepthshadow.cpp index 8c6d8cc90..a45c9b39a 100644 --- a/examples/osgdepthshadow/osgdepthshadow.cpp +++ b/examples/osgdepthshadow/osgdepthshadow.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include @@ -226,6 +228,10 @@ class UpdateCameraAndTexGenCallback : public osg::NodeCallback float zNearRatio = 0.001f; if (znearsetMode(GL_LIGHTING, osg::StateAttribute::OFF); + + float factor = 0.0f; + float units = 0.0f; + ref_ptr polygon_offset = new PolygonOffset; - polygon_offset->setFactor(1.1f); - polygon_offset->setUnits(4.0f); + 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); @@ -336,7 +358,21 @@ osg::Group* createShadowedScene(osg::Node* shadowed,osg::MatrixTransform* light_ 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); + + osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource); + program->addShader(fragment_shader); + + osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); + stateset->addUniform(baseTextureSampler); + + osg::Uniform* ambientBias = new osg::Uniform("ambientBias",osg::Vec2(0.2f,0.8f)); + stateset->addUniform(ambientBias); + } // add the shadower and shadowed.