Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Resolved Gradient based on relative direction

Discussion in 'Shaders' started by Beauque, Jul 13, 2020.

  1. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    39
    Hi.
    I would like to map a normalised gradient on a mesh, for instance like if using the local position on the x axis (remapped to 0-1), but I want it aligned to a specific direction, towards a specific position in space or toward the world's origin. Something I thought would be trivial in Amplify but I tend to get stuck even with simple maths.

    To give a better idea: If we plug the result in the emissive port, every object with the shader would appear to be lit by a same object standing somewhere in the scene.

    (I want to use this gradient to fake ambient lighting on a planet shader and light its atmosphere, according to its relative position to the star. For a matter of flexibility I would like to use a given transform position rather than using lighting informations. Also I would rather not use the normal information of the meshes since they are not so spherical.)

    I hope this is understandable. I am sure it has to do with the nodes below but I ended up trying every combinaison I could think of without getting the desired result..
    upload_2020-7-13_21-29-44.png

    Any help would be appreciated. :)
     
    Last edited: Jul 13, 2020
  2. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    39
    Well it seens I figured it out myself, with a simple dot product.
    upload_2020-7-15_23-1-5.png

    Not sure if this is the best solution but it does the job in my case. Here is the result what I was looking for:
    upload_2020-7-15_23-4-8.png
     
    Last edited: Jul 15, 2020
unityunity