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