Search Unity

Question How to generate normals from a custom object space.

Discussion in 'Shader Graph' started by Alesk, Oct 7, 2021.

  1. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    Hi,

    I'm working on a project where I need to render some kind of moving volumetric objects in curved pipes.
    These objects are bubbles in pipes of water.

    I can't use one object per bubble nor particles in this case, because I need many bubbles deforming along the pipe's shape.
    Object wouldn't be practical, and particles can't deform as I need.

    So, my current solution is to display these bubbles through a procedural 3D texture.
    To display this texture as a volume, I'm using a dense grid mesh to support the shader :
    grid_tube.jpg

    Here I'm defining custom UVs per vertex, as a Vector3 (= UVW), U and V being the horizontal and vertical axis in "pipe space" and W being the distance along the pipe. (here it's displayed with a fraction operation to see the units along the path)

    Then, in my shader, I add some nodes to alpha cut a spheroid in this grid :
    grid_blob.jpg

    And now... I would like to find a way to compute world normals of this spheroid, but I'm stuck by the curved nature of this UVW space following the shape of the mesh.

    Does someone have any idea on how to do this please ?