Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Line renderer gets different color when viewed in different directions

Discussion in 'Scripting' started by eliasjgnilsson, Dec 19, 2021.

  1. eliasjgnilsson

    eliasjgnilsson

    Joined:
    Mar 1, 2021
    Posts:
    77
    I have one issue and one question. The first one is the question:

    Why is there a start/end color for the line renderer and a material with a color? If I set a material (which I have to, otherwise the line turns pink) then the start and end colors do nothing.

    Then my issue is that the line gets different colors, or different alpha at least, when being in different positions. The first one is in negative z axis and the seconds one is in positive z axis. The "real" color is the thicker one, the other is too transparent/low alpha or whatever is wrong. Why does it do this and how do I solve it to always have the same color?
    1.png 2.png

    Here are my line renderer settings:

    upload_2021-12-19_19-29-28.png

    And here is the material properties:

    upload_2021-12-19_19-29-57.png

    There is no difference when enabling or disabling emission.

    Any guidance or advice is highly appreciated, I am stuck on this for so long now..
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Usually one draws lines with an unlit shader, or else perhaps a particles additive.

    The above shader accepts light (and shadows) so of course it looks different from different angles.
     
  3. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Write a script that gets your player transform position.

    var K = transform.position // your position
    Now maybe use Vector3 angle to get an angle between you and your line renderer. I can’t say off my head you’ll have to look at the number returned by angle and decide what to do with it. And then write the parameter for which colour when your angle is within which vector 2 range.

    You might not* want but the line render when used with correct material type; the colour bar and gradient can be used instead of modifying the material. I feel like it would be better performance to do this than it would be to set material properties during an update.
     
  4. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Oh sorry —- I misread —-

    the line render will take sprite default material, there is also a line renderer default material. You should have them in your project. These are the intended material the material you use is for line renderer using mesh I believe.



    another approach to achieve this effect this by shining coloured lights on the object. Have these coloured spot lights attach to a parent that rotate when players distance from object changes. Make sure to cull all other surfaces. Another way to get some dynamic colour on there. It’ll save you blending or lerping colours by script.
     
    Last edited: Dec 19, 2021
  5. eliasjgnilsson

    eliasjgnilsson

    Joined:
    Mar 1, 2021
    Posts:
    77
    Hi,

    I already have the "effect", I don't want it hehe. I asked how to get a constant color when looking in all directions, right now it changes for some strange reason.