SEARCH
TOOLBOX
LANGUAGES
Shadows

Shadows

From SOFAWiki

Jump to: navigation, search

Shadows

Shadow Mapping has been implemented in SOFA, in order to have a better depth feeling (and an overall nicer scene...)

Two versions has been coded :

* hard shadows : quick and not so bad visually,
* soft shadows : requires more GPU processing, but nicer than hard shadows.

Soft Shadows Hard Shadows

(example in examples/Components/visualmodel/OglShadowShader.scn)

Enabling Shadows

First, you have a light in your scene in order to have shadows (obviously). And you will need two more objects :

    <LightManager softShadows="true"/> <!-- change softShadows flag to enable (or not) soft shadows -->
    <OglShadowShader/>

As you may guess, the important parameter here is softShadows which if true, enable soft shadows, else enable only hard shadows.

Put these at the root of your scene file, if you want to cast shadows for all the visual objects in your scene.

Finally, press CONTROL + L to draw shadows when simulating. If you don't want to activate it manually, simply add the parameter shadows to true, which will automatically draws shadows.

Customize Shadows

Default parameters may be not sufficient for your needs (speed, rendering quality). One important paramater located in Light* object is the texture size, which is used in shadow mapping algorithm

    <SpotLight position="0 5 -15" direction="0 -0.2 1.0" cutoff="45" shadowTextureSize="512" />

For hard shadows, greater the number is, more precise the shadow will be, but slower the scene will be ... But for soft shadows, greater the number is, fuzzier the shadow will be.

So try to have a good balance between speed and rendering quality.

Hard Shadows with a texture of size of 128x128 Hard Shadows with a texture of size of 2048x2048

Soft Shadows with a texture of size of 128x128 Soft Shadows with a texture of size of 512x512 Soft Shadows with a texture of size of 2048x2048