Search Unity

Need Help with This Shader Effect

Discussion in 'Shaders' started by AhSai, Aug 29, 2019.

  1. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    I am creating a shader which will write the vertex distance from its object's origin on it's XZ axis only to the R Channel. The restrictions are 1. the distance has to be before scaling but after rotation, 2. no variables should be passing in from C# (since this will be a particle effect, I am trying not to loop through the particles to pass in things individually).
    So if I have a sphere, its radius is 1, it should look like this at any rotation from top down:
    Correct.jpg
    Currently, I am using 1 - length(v.pos.xz) to produce the above image, but it does not take rotation into a account, and will produce incorrect result if the rotation on XZ axis are other than zero.
    Incorrect.jpg
    Does anyone know how to solve this?