Inertia

Why use inertia?

While the GPU excels in many tasks, it cannot easily access memory from the last frame. This can lead to situations where a wind zone passes by a tree bending it properly but when it fully passes by the tree, the tree immediately bounces back without any spring force.

Shader Graph

Adding inertia support to a shader graph is simple! All you need to do is add two properties to your shader and Zephyr's built-in nodes will work out of the box with no other customizations required.

1

Add Wind History Vector

First, add a new Vector3 property to your shader graph

Next, name this new property "_ZEPHYR_WindHistory" and set the scope to "Hybrid Per Instance".

2

Add the define

Next, you need to add the _ZEPHYR_USEINERTIA define to your shader. In Shader Graph, we can do this by adding a boolean keyword.

Once this is created, name the keyword "_ZEPHYR_USEINERTIA" and set the definition to Multi Compile. Optionally, set Is Overridable and Generate Material Property to true to expose a toggle in your material editor.

3

Add Inertia component

For every object that uses this material, you will need to apply a Wind Inertia component that passes the wind information from the CPU to the GPU.

Amplify Shader Editor

In order to add support for inertia using ASE, all we need to do is declare the _ZEPHYR_USEINERTIA directive in our shader.

1

Add the define

To begin, add the _ZEPHYR_USEINERTIA define to your shader. In Amplify Shader Editor, we can do this by adding a boolean keyword. Create a new switch node in your graph

Next, rename it to _ZEPHYR_USEINERTIA and set the keyword type to multi-compile and enable auto register to not have to add it to your graph.

2

Add Inertia component

For every object that uses this material, you will need to apply a Wind Inertia component that passes the wind information from the CPU to the GPU.

HLSL

In order to add support for inertia in an HLSL shader, all we need to do is declare the _ZEPHYR_USEINERTIA directive in our shader and add the _ZEPHYR_WindHistory property.

1

Add wind history vector

Add this line with the rest of your shader properties:

[HideInInspector] _ZEPHYR_WindHistory( "_ZEPHYR_WindHistory", Vector ) = ( 0, 0, 0, 0 )
2

Add use inertia define

Next, add this line along with your pragmas and defines:

#define _ZEPHYR_USEINERTIA

(Optional) Add a property to be able to toggle the define from the material inspector.

Use this line instead in your pragmas:

			#pragma multi_compile_local __ _ZEPHYR_USEINERTIA

Then add a toggle with your properties:

[Toggle( _ZEPHYR_USEINERTIA )] _ZEPHYR_USEINERTIA( "UseInertia", Float ) = 1
3

Add inertia component

For every object that uses this material, you will need to apply a Wind Inertia component that passes the wind information from the CPU to the GPU.

Last updated