Skip to content

Add tutorial + example SDF for shadow texture size #2597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 10, 2024
Merged
73 changes: 73 additions & 0 deletions examples/worlds/shadow_texture_size.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" ?>
<sdf version="1.9">
<world name="default">
<scene>
<background>0.1 0.1 0.1</background>
<ambient>0.0 0.0 0.0</ambient>
</scene>

<!--GUI plugins-->
<gui>
<plugin filename="MinimalScene" name="3D View">
<engine>ogre2</engine>
<camera_pose>-10 0 7 0 0.5 0</camera_pose>
<shadows>
<texture_size light_type="directional">16384</texture_size>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set this to 8192 as I see that's what the tutorial tells the user to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</shadows>
</plugin>

<plugin filename="GzSceneManager" name="Scene Manager"/>
<plugin filename="InteractiveViewControl" name="Interactive view control"/>
</gui>

<!--lighting-->
<light type="directional" name="sun">
<pose>0 0 8 0 0 0</pose>
<diffuse>1 1 1 1</diffuse>
<specular>0 0 0 0</specular>
<attenuation>
<range>50</range>
<constant>0</constant>
<linear>0</linear>
<quadratic>0</quadratic>
</attenuation>
<cast_shadows>true</cast_shadows>
<direction>-2 2 -1.5</direction>
<intensity>1.0</intensity>
</light>

<!--scene objects-->
<include>
<pose>0 0 0 0 0 -1.57</pose>
<uri>
https://fuel.gazebosim.org/1.0/OpenRobotics/models/Garden Mascot
</uri>
</include>

<model name="floor">
<pose>-5 0 -0.5 0 0 0</pose>
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<box>
<size>15 15 1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>15 15 1</size>
</box>
</geometry>
<material>
<ambient>0.8 0.8 0.8 1</ambient>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.8 0.8 0.8 1</specular>
</material>
</visual>
</link>
</model>
</world>
</sdf>
1 change: 1 addition & 0 deletions tutorials.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ If you are an absolute beginner, start with the Tutorials section.
* \subpage logicalaudiosensor "Logical Audio Sensor": Using the LogicalAudioSensor system to mimic logical audio emission and detection in simulation.
* \subpage auto_inertia_calculation "Automatic Inertia Calculation": Automatically compute inertia values(mass, mass matrix, center of mass) for SDFormat links.
* \subpage jointcontrollers "Joint Controllers": Using available joint controller plugins to control joints.
* \subpage shadow_texture_size "Shadow texture size": Change the texture size of shadows casted by lights.

### Advanced

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions tutorials/shadow_texture_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
\page shadow_texture_size Shadow Texture Size

This tutorial showcases how to change the texture size of shadows casted by lights.

<div style="text-align:center;">
\image html files/shadow_texture_size/shadow_texsize_2k_to_16k.gif width=60%
</div>

## Texture size options

Supported texture sizes include: 512 px, 1024 px, 2048 px, 4096 px, 8192 px, 16384 px.

The default shadow texture size for all lights is 2K. The default max texture size is 16K, but for less powerful computers, it may be a lower value, like 8K.

## Changing shadow texture size

The shadow texture size can be changed for the GUI with the usage of the Minimal Scene GUI plugin in the SDF.

### Example usage for the GUI

Let's change the shadow texture size for directional light with the SDF file below. (The finished SDF file can be viewed [here](https://github.com/gazebosim/gz-sim/blob/main/examples/worlds/shadow_texture_size.sdf).)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you mention that we currently only support changing shadow texture size for directional lights?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup = done here b48725b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh can you also change the link to point to gz-sim9 branch? i.e. https://github.com/gazebosim/gz-sim/tree/gz-sim9/examples/worlds/shadow_texture_size.sdf


1) Save the below in an SDF file named `shadow_texsize_demo.sdf`:

```xml
<?xml version="1.0" ?>
<sdf version="1.9">
<world name="default">
<scene>
<background>0.1 0.1 0.1</background>
<ambient>0.0 0.0 0.0</ambient>
</scene>

<!--GUI plugins-->
<gui>
<plugin filename="MinimalScene" name="3D View">
<engine>ogre2</engine>
<camera_pose>-10 0 7 0 0.5 0</camera_pose>
</plugin>

<plugin filename="GzSceneManager" name="Scene Manager"/>
<plugin filename="InteractiveViewControl" name="Interactive view control"/>
</gui>

<!--lighting-->
<light type="directional" name="sun">
<pose>0 0 8 0 0 0</pose>
<diffuse>1 1 1 1</diffuse>
<specular>0 0 0 0</specular>
<attenuation>
<range>50</range>
<constant>0</constant>
<linear>0</linear>
<quadratic>0</quadratic>
</attenuation>
<cast_shadows>true</cast_shadows>
<direction>-2 2 -1.5</direction>
<intensity>1.0</intensity>
</light>

<!--scene objects-->
<include>
<pose>0 0 0 0 0 -1.57</pose>
<uri>
https://fuel.gazebosim.org/1.0/OpenRobotics/models/Garden Mascot
</uri>
</include>

<model name="floor">
<pose>-5 0 -0.5 0 0 0</pose>
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<box>
<size>15 15 1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>15 15 1</size>
</box>
</geometry>
<material>
<ambient>0.8 0.8 0.8 1</ambient>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.8 0.8 0.8 1</specular>
</material>
</visual>
</link>
</model>
</world>
</sdf>
```

2) Add the following lines to the Minimal Scene GUI plugin.

```xml
</shadows>
<texture_size light_type="directional">8192</texture_size>
</shadows>
```

The `<texture_size>` value can be changed as per the Texture size options section.

3) Open the `shadow_texsize_demo.sdf` world with

```bash
gz sim shadow_texsize_demo.sdf
```

## Impact on VRAM usage

Keep in mind that the larger the shadow texture size, the more VRAM is used. Thus, in a scene populated with many lights, changing the directional light's shadow texture size should be fine because there is typically only one directional light in a scene. But if the scene has many point lights and the point light's shadow texture size is increased, the VRAM consumption goes up significantly.
Loading