SoftShadowMap 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGSHADOW_SOFTSHADOWMAP
  14. #define OSGSHADOW_SOFTSHADOWMAP 1
  15. #include <osg/Camera>
  16. #include <osg/Material>
  17. #include <osg/MatrixTransform>
  18. #include <osg/LightSource>
  19. #include <osgShadow/ShadowMap>
  20. namespace osgShadow {
  21. /** SoftShadowMap provides an implementation of soft shadows with shadow maps.*/
  22. class OSGSHADOW_EXPORT SoftShadowMap : public ShadowMap
  23. {
  24. public :
  25. SoftShadowMap();
  26. SoftShadowMap(const SoftShadowMap& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  27. META_Object(osgShadow, SoftShadowMap);
  28. /** Set the values for width of the soft penumbra the shader will use.
  29. * Zero is for hard shadow (no penumbra). 0.01 is already very soft penumbra.
  30. * Default is 0.005.*/
  31. void setSoftnessWidth(float softnessWidth);
  32. /** Get the value used for width of the soft penumbra in the shader.*/
  33. float getSoftnessWidth() const { return _softnessWidth; }
  34. /** Set the values for jittering scale the shader will use.
  35. * Zero is no jittering (i.e. see the banding in penumbra)
  36. * High values (>64) cause 'pixelization' of the penumbra.
  37. * Usually but not necessarily power of two number.
  38. * Default is 32. */
  39. void setJitteringScale(float jitteringScale);
  40. /** Get the value used for jittering scale in the shader.*/
  41. float getJitteringScale() const { return _jitteringScale; }
  42. /** Set the texture unit that the jitter texture will be applied on.*/
  43. void setJitterTextureUnit(unsigned int jitterTextureUnit);
  44. /** Get the texture unit that the jitter texture will be applied on.*/
  45. unsigned int getJitterTextureUnit() const { return _jitterTextureUnit; }
  46. /** Add a small bias to the z-value, this can reduce
  47. * shadow acne problem.
  48. * This is the same as calling setPolygonOffset(osg::Vec2(bias,0));
  49. * Suitable values are 0-0.005
  50. * Default is 0. */
  51. void setBias(float bias) { setPolygonOffset(osg::Vec2(bias,0)); }
  52. /** Return the bias value */
  53. float getBias() const { return getPolygonOffset().x(); }
  54. protected:
  55. virtual ~SoftShadowMap(void) {};
  56. /** Create the managed Uniforms */
  57. void createUniforms();
  58. void createShaders();
  59. void initJittering(osg::StateSet *ss);
  60. osg::ref_ptr<osg::Uniform> _softnessWidthUniform;
  61. osg::ref_ptr<osg::Uniform> _jitteringScaleUniform;
  62. float _softnessWidth;
  63. float _jitteringScale;
  64. unsigned int _jitterTextureUnit;
  65. };
  66. }
  67. #endif