Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Interactive puddles with a surface shader

Discussion in 'Shaders' started by shanataru, Jul 4, 2020.

  1. shanataru

    shanataru

    Joined:
    Mar 4, 2019
    Posts:
    13
    Hello,
    I would like to create interactive puddles which are placed all over a long road.

    I am placing puddles with a low-resolution greyscale puddle texture and mapping it through world coordinates to avoid repeating pattern (the road has repeating tiles).
    The puddles have reflection made using a render texture which is then set to emission. The reflection is distorted using water normals (just some generic wavy normal map) - most of the code was taken from standard water asset in Unity.

    I am able to simulate water surface on one tile of a road using custom render texture (I am simulating water like a 2D grid, creating a height map) and later use it to modify the wavy normals to create fake water ripples. The ripples are generated when an object collides with the road surface, using raycast hit I change the height value in custom render texture at the needed UV coords.

    This works fine on one tile of the road (obviously - see figure below), but I would like to make it scalable, preferably on the whole puddle map. Tiling the custom render texture will not make it seamless and it will be heavy on computation (right now the custom render texture is 2048 by 2048).



    I tried to map the custom render texture to world coordinates (so I cover a bigger area, more puddles), but here is where raycast fail me. I cannot seem to get the right UV coordinates to simulate a ripple at the spot of raycast hit. The ripples generate in a different place, most likely because a portion of the custom render texture covers multiple parts of a long road or maybe I am just lost in mapping the UV correctly.

    Is there a better way to get this working? Any idea or criticism would be welcome, even a completely different approach. I am quite lost right now!

    Thank you in advance
     

    Attached Files: