Class SoShadowGroup
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.misc.SoBase
-
- com.openinventor.inventor.fields.SoFieldContainer
-
- com.openinventor.inventor.nodes.SoNode
-
- com.openinventor.inventor.nodes.SoGroup
-
- com.openinventor.inventor.nodes.SoShadowGroup
-
- All Implemented Interfaces:
SafeDisposable
public class SoShadowGroup extends SoGroup
Shadow casting group node. This group node performs real-time shadow casting. Because shadows depends on a lot of OpenInventor elements, it is recommended to put children of this group under aSoSeparator
in order to have a cache. Each shape within this group will be included in the shadow casting computation. A shape may cast a shadow on other shapes or on itself (self-shadowing), and/or may be shadowed by other shapes within the group. The current shadow style is used to determine if shapes cast a shadow and/or can be shadowed (seeSoShadowStyle
).This class defines a single shadowing method. The
method
field allows for future shadowing methods to be added.- VARIANCE_SHADOW_MAP : This mode allows to display soft shadows. The
smoothFactor
field can be used to increase or decrease the softness. Aliasing won't be displayed, but on large scenes shadows will progressively fade away. Increasingquality
will reduce this problem. Only the last on state directional light is used during rendering, other lights are ignored.Shaders
Only the VARIANCE_SHADOW_MAP method is available with shaders (custom or internal). In order to use shadows with user defined GLSL shaders (SoShaderProgram
orSoVolumeShader
), the following functions must be used in the shader programs.
In the vertex shader:- void OivSetupShadowVertex(): Must be called in the vertex shader.
In the fragment shader:
- float OivComputeShadow(): Returns a scalar in [0-1]. 0 means fragment is fully shadowed, 1 means no shadow. Should be used to modify the fragment color.
- void OivGenerateShadowMap(): Must be called during the shadowmap pass in order to create the shadowmap. During this pass, the shader must not write to gl_FragColor. Use the uniform OivShadowPass to know when the shadowmap is being computed.
The following uniform is available in vertex and fragment shaders:
- uniform bool OivShadowPass: Is true if the shadowmap is currently being rendered
The following code can be used as a skeleton for a GLSL shader that works with shadows:
// The vertex shader: void OivSetupShadowVertex(); void main() { ..userCode.. //Needed for shadowing OivSetupShadowVertex(); } // The fragment shader: //If true we are in shadowmap generation pass uniform bool OivShadowPass; void OivGenerateShadowMap(); float OivComputeShadow(); void main() { if ( !OivShadowPass ) { ..compute fragment color here.. // Define the final color gl_FragColor.xyz = fragColor.xyz * OivComputeShadow(); gl_FragColor.w = fragColor.w; } else { // Output the shadowmap during the shadow map pass OivGenerateShadowMap(); } } Transparency:
Transparent objects are treated as follows, depending on the transparency type:- NO_SORT: Transparent objects cast a shadow and are shadowed but the shadow intensity doesn't depend on the transparency value (the same shadow is displayed for full transparent shapes and opaque shapes).
- OPAQUE_FIRST, SORTED_OBJECT and SORTED_PIXEL: Same as previous case for VARIANCE_SHADOW_MAP.
Texture units:
In VARIANCE_SHADOW_MAP mode, this node reserves texture unit OIV_SHADOW_TEXTURE_UNIT0 for its rendering (seeSoPreferences
to set these). If this value is not set the application can specify which texture units OpenInventor should automatically use by setting environment variables (seeSoPreferences
). The texture units between OIV_FIRST_RESERVED_TEXTURE_UNIT and OIV_FIRST_RESERVED_TEXTURE_UNIT +SoShaderProgram.getNumReservedTextures()
-1 inclusive are reserved for internal OpenInventor use. If OIV_FIRST_RESERVED_TEXTURE_UNIT is not set, its default value isSoFragmentShader.getMaxTextureImageUnit()
-SoShaderProgram.getNumReservedTextures(). Note: The value returned bySoShaderProgram.getNumReservedTextures()
may change between OpenInventor versions. The total number of available texture units depends on the graphics hardware.Hardware requirements:
The Shadow and Depth Texture OpenGL extensions (standard in OpenGL 1.4) are used if they are available and generally improve performance.
In order to increase quality and performance of the shadows, OpenGL PBuffers are used. PBuffers are a limited resource on some systems. Set OIV_PBUFFER_ENABLE to 0 to disallow use of PBuffers.A DirectX 10 graphics board is needed to support VARIANCE_SHADOW_MAP.
Use the
isSupported()
static method to determine if the current graphics board supports shadowing.Limitations
SoShadowGroup
cannot be nested by design.
Notes:
- Geometry cannot receive shadows if lighting is disabled.
For example if anSoLightModel
node sets the lighting model to BASE_COLOR. - Geometry cannot receive shadows if a texture is applied using the DECAL or REPLACE models.
File format/default:
ShadowGroup {
isActive true isShapesBefore false intensity 0.5 precision 0.5 quality 0.5 shadowCachingEnabled true visibilityRadius 1.0 visibilityFlag LONGEST_BBOX_EDGE_FACTOR smoothFactor 1 minVariance 1e-5 method VARIANCE_SHADOW_MAP lightBleedingReduction 0.01
- See Also:
SoShadowStyle
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoShadowGroup.ShadowingMethods
Shadowing techniques.static class
SoShadowGroup.VisibilityFlags
visibilityRadius
interpretation-
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoNode
SoNode.RenderModes
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
Fields Modifier and Type Field Description SoSFFloat
intensity
Specifies the intensity of the shadow.SoSFBool
isActive
Activates/deactivates the shadowing.SoSFFloat
lightBleedingReduction
In some cases, a halo may appear around shadows intersecting each other.SoSFEnum<SoShadowGroup.ShadowingMethods>
method
Specifies the shadowing technique to use.SoSFFloat
minVariance
Increasing this value will decrease possible self-shadowing artifacts but will make shadows fade away.SoSFFloat
precision
Specifies the precision of the shadow.SoSFFloat
quality
Specifies the quality of the shadow.SoSFBool
shadowCachingEnabled
Indicates if a cache should be used for computing the shadows.SoSFInt32
smoothFactor
Set the smoothness of shadows.SoSFEnum<SoShadowGroup.VisibilityFlags>
visibilityFlag
Specifies howvisibilityRadius
is interpreted.SoSFFloat
visibilityRadius
Shadows are only computed within "visibility radius" distance from the camera position.-
Fields inherited from class com.openinventor.inventor.nodes.SoGroup
boundingBoxIgnoring
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoShadowGroup()
Default constructor.SoShadowGroup(int nChildren)
Constructor that takes approximate number of children.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isSupported()
Calls isSupported(SoShadowGroup.ShadowingMethods.valueOf( SoShadowGroup.ShadowingMethods.VARIANCE_SHADOW_MAP.getValue() )).static boolean
isSupported(SoShadowGroup.ShadowingMethods method)
Indicates if shadow casting is supported by your graphic board.-
Methods inherited from class com.openinventor.inventor.nodes.SoGroup
addChild, findChild, getChild, getNumChildren, insertChild, removeAllChildren, removeChild, removeChild, replaceChild, replaceChild
-
Methods inherited from class com.openinventor.inventor.nodes.SoNode
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
-
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
-
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
-
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
-
-
-
Field Detail
-
isActive
public final SoSFBool isActive
Activates/deactivates the shadowing. If deactivated, thisSoShadowGroup
behaves like anSoGroup
.
-
intensity
public final SoSFFloat intensity
Specifies the intensity of the shadow. 0 = lowest intensity (the shadow is invisible), 1 = highest intensity (the shadow is solid black).
-
precision
public final SoSFFloat precision
Specifies the precision of the shadow. 0 = lowest precision, 1 = highest precision. With lower precisions, some parts of the scene may be unlit where they should be lit, or vice versa. Increasing the precision will reduce performance.NOTE: If your graphics driver does not support the required OpenGL extensions, you may see low precision results even when this field is set to the highest precision.
-
quality
public final SoSFFloat quality
Specifies the quality of the shadow. The texture used for shadowmap rendering will be of size 2*quality*ViewportSize. Increasing the quality will reduce performance and increase memory consumption.
-
shadowCachingEnabled
public final SoSFBool shadowCachingEnabled
Indicates if a cache should be used for computing the shadows. Using a cache will improve rendering performance if the lights of your scene and your scene under this group node do not change.
-
visibilityRadius
public final SoSFFloat visibilityRadius
Shadows are only computed within "visibility radius" distance from the camera position. This radius equals:- the longest edge of the bounding box of the scene multiplied by
visibilityRadius
ifvisibilityFlag
equalsLONGEST_BBOX_EDGE_FACTOR
. visibilityRadius
ifvisibilityFlag
equalsABSOLUTE_RADIUS
.
When
visibilityRadius
= 1 andvisibilityFlag
=LONGEST_BBOX_EDGE_FACTOR
(default values), shadowing is computed throughout the entire scene.Note: With VARIANCE_SHADOW_MAP method, try to increase the
quality
field first. - the longest edge of the bounding box of the scene multiplied by
-
visibilityFlag
public final SoSFEnum<SoShadowGroup.VisibilityFlags> visibilityFlag
Specifies howvisibilityRadius
is interpreted. Use enumVisibilityFlag
. Default is LONGEST_BBOX_EDGE_FACTOR.
-
smoothFactor
public final SoSFInt32 smoothFactor
Set the smoothness of shadows. Higher values give smoother shadows. Default is 1.- Since:
- Open Inventor 8.1
-
minVariance
public final SoSFFloat minVariance
Increasing this value will decrease possible self-shadowing artifacts but will make shadows fade away. The default value is safe for most scenes. Increasing thequality
field is also preferable before tweaking this value. A special case is forSoVolumeRender
node which has a minimum of 0.001 or IVVR_SHADOW_MIN_VARIANCE if set. Default is 1e-5 and range is [0-1].- Since:
- Open Inventor 8.1
-
lightBleedingReduction
public final SoSFFloat lightBleedingReduction
In some cases, a halo may appear around shadows intersecting each other. Increasing this value will decrease this effect. Default value is safe for most scenes. Default is 0.01 and range is [0-1].- Since:
- Open Inventor 8.1
-
method
public final SoSFEnum<SoShadowGroup.ShadowingMethods> method
Specifies the shadowing technique to use. . Default is VARIANCE_SHADOW_MAP.- Since:
- Open Inventor 8.1
-
-
Method Detail
-
isSupported
public static boolean isSupported()
Calls isSupported(SoShadowGroup.ShadowingMethods.valueOf( SoShadowGroup.ShadowingMethods.VARIANCE_SHADOW_MAP.getValue() )).
-
isSupported
public static boolean isSupported(SoShadowGroup.ShadowingMethods method)
Indicates if shadow casting is supported by your graphic board. When using a debug build of Open Inventor, some "no context available" warning messages may be generated. You can ignore them or seeSoGLExtension
for an example of usingSoGLContext
to avoid them.
-
-