ShadowSettings 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-20 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_SHADOWSETTINGS
  14. #define OSGSHADOW_SHADOWSETTINGS 1
  15. #include <osg/Uniform>
  16. #include <osg/CullSettings>
  17. #include <osgShadow/Export>
  18. namespace osgShadow {
  19. /** ShadowSettings provides the parameters that the ShadowTechnique should use as a guide for setting up shadowing.*/
  20. class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
  21. {
  22. public:
  23. ShadowSettings();
  24. ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  25. META_Object(osgShadow, ShadowSettings);
  26. void setReceivesShadowTraversalMask(unsigned int mask) { _receivesShadowTraversalMask = mask; }
  27. unsigned int getReceivesShadowTraversalMask() const { return _receivesShadowTraversalMask; }
  28. void setCastsShadowTraversalMask(unsigned int mask) { _castsShadowTraversalMask = mask; }
  29. unsigned int getCastsShadowTraversalMask() const { return _castsShadowTraversalMask; }
  30. void setComputeNearFarModeOverride(osg::CullSettings::ComputeNearFarMode cnfn) { _computeNearFearModeOverride = cnfn; }
  31. osg::CullSettings::ComputeNearFarMode getComputeNearFarModeOverride() const { return _computeNearFearModeOverride; }
  32. /** Set the LightNum of the light in the scene to assign a shadow for.
  33. * Default value is -1, which signifies that shadow technique should automatically select an active light
  34. * to assign a shadow, typically this will be the first active light found. */
  35. void setLightNum(int lightNum) { _lightNum = lightNum; }
  36. int getLightNum() const { return _lightNum; }
  37. void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; }
  38. unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; }
  39. /** Set whether to use osg::StateAttribute::OVERRIDE for the shadow map texture.
  40. * Enabling override will force the shadow map texture to override any texture set on the shadow maps texture unit.*/
  41. void setUseOverrideForShadowMapTexture(bool useOverride) { _useShadowMapTextureOverride = useOverride; }
  42. /** Get whether to use osg::StateAttribute::OVERRIDE for the shadow map texture. */
  43. bool getUseOverrideForShadowMapTexture() const { return _useShadowMapTextureOverride; }
  44. /** Set the size of the shadow map textures.*/
  45. void setTextureSize(const osg::Vec2s& textureSize) { _textureSize = textureSize; }
  46. /** Get the size of the shadow map textures.*/
  47. const osg::Vec2s& getTextureSize() const { return _textureSize; }
  48. void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; }
  49. double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; }
  50. void setMaximumShadowMapDistance(double distance) { _maximumShadowMapDistance = distance; }
  51. double getMaximumShadowMapDistance() const { return _maximumShadowMapDistance; }
  52. enum ShadowMapProjectionHint
  53. {
  54. ORTHOGRAPHIC_SHADOW_MAP,
  55. PERSPECTIVE_SHADOW_MAP
  56. };
  57. void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; }
  58. ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; }
  59. /** Set the cut off angle, in degrees, between the light direction and the view direction
  60. * that determines whether perspective shadow mapping is appropriate, or thar orthographic shadow
  61. * map should be used instead. Default is 2 degrees so that for any angle greater than 2 degrees
  62. * perspective shadow map will be used, and any angle less than 2 degrees orthographic shadow map
  63. * will be used. Note, if ShadowMapProjectionHint is set to ORTHOGRAPHIC_SHADOW_MAP then an
  64. * orthographic shadow map will always be used.*/
  65. void setPerspectiveShadowMapCutOffAngle(double angle) { _perspectiveShadowMapCutOffAngle = angle; }
  66. double getPerspectiveShadowMapCutOffAngle() const { return _perspectiveShadowMapCutOffAngle; }
  67. void setNumShadowMapsPerLight(unsigned int numShadowMaps) { _numShadowMapsPerLight = numShadowMaps; }
  68. unsigned int getNumShadowMapsPerLight() const { return _numShadowMapsPerLight; }
  69. enum MultipleShadowMapHint
  70. {
  71. PARALLEL_SPLIT,
  72. CASCADED
  73. };
  74. void setMultipleShadowMapHint(MultipleShadowMapHint hint) { _multipleShadowMapHint = hint; }
  75. MultipleShadowMapHint getMultipleShadowMapHint() const { return _multipleShadowMapHint; }
  76. enum ShaderHint
  77. {
  78. NO_SHADERS,
  79. PROVIDE_FRAGMENT_SHADER,
  80. PROVIDE_VERTEX_AND_FRAGMENT_SHADER
  81. };
  82. void setShaderHint(ShaderHint shaderHint) { _shaderHint = shaderHint; }
  83. ShaderHint getShaderHint() const { return _shaderHint; }
  84. void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }
  85. bool getDebugDraw() const { return _debugDraw; }
  86. protected:
  87. virtual ~ShadowSettings();
  88. unsigned int _receivesShadowTraversalMask;
  89. unsigned int _castsShadowTraversalMask;
  90. osg::CullSettings::ComputeNearFarMode _computeNearFearModeOverride;
  91. int _lightNum;
  92. unsigned int _baseShadowTextureUnit;
  93. bool _useShadowMapTextureOverride;
  94. osg::Vec2s _textureSize;
  95. double _minimumShadowMapNearFarRatio;
  96. double _maximumShadowMapDistance;
  97. ShadowMapProjectionHint _shadowMapProjectionHint;
  98. double _perspectiveShadowMapCutOffAngle;
  99. unsigned int _numShadowMapsPerLight;
  100. MultipleShadowMapHint _multipleShadowMapHint;
  101. ShaderHint _shaderHint;
  102. bool _debugDraw;
  103. };
  104. }
  105. #endif