Skip to content

Shadowing

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.

[caption id="attachment_1419" align="alignnone" width="400"]Hard shadows Hard shadows[/caption] [caption id="attachment_1420" align="alignnone" width="400"]Soft shadows Soft shadows[/caption]


(example in examples/Component/Visual/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 :


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 parameter located in Light* object is the texture size, which is used in shadow mapping algorithm.


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.

[caption id="attachment_1430" align="alignnone" width="401"]Hard_shadows_128{.wp-image-1430 width="401" height="300"} Hard shadows with 128x128 texture size[/caption]

[caption id="attachment_1431" align="alignnone" width="401"]Hard_shadows_2048{.wp-image-1431 width="401" height="300"} Hard shadows with 2048x2048 texture size[/caption]

[caption id="attachment_1432" align="alignnone" width="401"]Soft_shadows_128{.wp-image-1432 width="401" height="300"} Soft shadows with 128x128 texture size[/caption]

[caption id="attachment_1433" align="alignnone" width="401"]Soft_shadows_512{.wp-image-1433 width="401" height="300"} Soft shadows with 512x512 texture size[/caption]

[caption id="attachment_1434" align="alignnone" width="401"]Soft_shadows_2048{.wp-image-1434 width="401" height="300"} Soft shadows with 2048x2048 texture size[/caption]