Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Shadows

Description of Real-time Shadows

"Warning"

VARIANCE_SHADOW_MAP:

VARIANCE_SHADOW_MAP:

This method supports soft shadows (see image below). The smoothness field can be used to increase or decrease the softness. Unlike the SHADOW_MAP method, aliasing is not a problem, but on large scenes, shadows will progressively fade away. Increasing the quality value will reduce this problem. Only one directional light, the last one traversed before the SoShadowGroup, is used to compute shadows with this method, other lights are ignored. In this mode VolumeViz nodes can cast and receive shadows.

Lights that are children of SoShadowGroup are ignored and can give unexpected or incorrect results.

The shadow casting feature is not yet compatible with the bump mapping feature. Trying to combine these two features will give you an incorrect visual result.

Applying shadows

To simply apply shadows to your entire scene, replace the SoGroup containing your 3D scene (but not your camera and your light(s)) with an SoShadowGroup :

Scene graph organization for shadow casting

"Tip" Cylinder can cast a shadow and can be shadowed (**CASTS_SHADOW_AND_SHADOWED**), the sphere only casts a shadow (**CASTS_SHADOW**), and the cube can only be shadowed (**SHADOWED**).

Example of use of SoShadowStyle

Only the VARIANCE_SHADOW_MAP method is available with custom shaders. In order to use shadows with user defined shaders, a set of functions are available for GLSL shaders under a SoShadowGroup :

  • void OivSetupShadowVertex(): Must be called in the vertex shader only. The following functions are provided for use in fragment shaders only:
  • float OivComputeShadow(): Return a scalar in [0-1]. 0 means fragment is fully shadowed, 1 means no shadows.
  • 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. The following uniform is available in vertex and fragment GLSL shader:
  • uniform bool OivShadowPass: Is true if the shadowmap is currently being rendered. The following code can be used as a skeleton for a custom shadowed shader:

The vertex shader:

C++ :

void OivSetupShadowVertex();
void
main()
{
..userCode..
// Needed for shadowing
OivSetupShadowVertex();
}

The fragment shader:

// If true we are in shadowmap generation pass
uniform bool OivShadowPass;
// Generate the shadowmap
void OivGenerateShadowMap();
// Compute shadow for the current fragment
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();
}
}

See OIVHOME/src/Inventor/examples/Features/Shaders/shadowShader for a complete example.

Support for Shadows

Depending on your hardware capabilities, shadow casting may not be available. Shadows should be supported on any graphics board that support OpenGL 1.4 or higher, but can also work with previous OpenGL versions if specific OpenGL extensions are available. The static method SoShadowGroup::isSupported will indicate if shadow casting is supported by your graphics board.

On some older graphics boards, e.g., GeForce2, you will need to set the
environment variable OIV_FORCE_DUAL_TEX_SHADOW to 1.

On some older graphics boards, e.g., Rage 128, you will need to set SoShadowGroup::quality <= 0.25.