Simple Wind (vegetation) Shader

Wind is one way to improve the scenery with vegetation. Thus, my first shader focuses on horizontal force influence. The target is to move trees, plants, etc. horizontally (in a kinda wavy form) to simulate wind. (Empty template reused)

Fail 1

My first thought was to shift the texCoord in the vertex shader.

The pixel start to disappear on the right side and they expand on the left side. The Texture2D has a width and height limitation. Therefore, it is impossible to draw outside of the verticies.

Fail 2

Well, so, maybe I move my logic into the PixelShader? Maybe the Texture2D will expand itself magically?

No idea what was I expecting… However, the Vertex Shader is the way to go. (At least that is my last option)


Instead of moving the texture coordinate, lets move the vertex positions.

The texCoord contains values (normalized) from 0..1. With the if statement, we transform all vertices below the bendEnd. But why is the tree bending, regardless of the bendEnd value? Lets look at the mesh of a Texture2D

The Texture2D consists of 2 triangles (T1 and T2) and made up by the verticies (V1, V2, V3 and V4). The only verticies we are able to modify are, therefore, only 4. V1 equals to texCoord 0 and V3 equals the texCoord 1. No matter what value bendEnd contains (0..0.99), we can only transform V1 and V2, leading to the visible effect above. In order to achieve an even better result, a mesh with a higher resolution would be required.




Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.