Search Unity

Line Renderer Normals Wrong

Discussion in 'General Graphics' started by xHammy, Feb 2, 2020.

  1. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    When you enable "generate lighting data" on a line or trail renderer the documentation says it builds normals and tangents.
    The documentation also states that the line renderer is built facing the camera, as apposed to facing the camera direction such as in the case of shuriken particles set to view alignment.
    But the normals it generates are wrong, very wrong, very very very wrong.
    In this video I am using a shader that maps normals and uses it's own toon lighting.

    seen here, the lighting on the line renderer changes dramatically as I pan the camera, not moving it about the scene at all. This is normally the part where I'd post a picture of my shader to ask what I've done wrong, but this issue exists even in the standard URP shaders. Simply putting any stock lit shader on the line renderers allows you to observe this phenomenon, though the effect is a little less dramatic when you aren't using a flat shader., doing so makes viewing the issue a bit easier.

    Using an unlit shadergraph, using the normal vector as color shows the entire line having the same normal direction. On a hunch I tested by plugging the camera direction into the color output and wasn't able to tell any difference in the results.

    Observing the line renderer in wire frame mode, it is apparent that the line does rotate with camera rotation, but it's much more so biased to face the camera.

    Lastly, the fact that tangent space normal maps still work somewhat has me more confused on why, how, and the exact nature of how broken "generate lighting data" actually is.

    To ask some questions... what can I actually do about this? Is this an issue unity is aware of? Am I just doing something wrong? Are there work arounds? Why aren't there any other posts anywhere about this issue?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Can you report a bug and post the case number here?

    FWIW, the line renderer geometry faces the camera plane, not the eye position.

    Oh and one more idea - is it self-shadowing artifacts? Turning off shadow receive, or increasing the shadow bias might confirm if it’s this.
     
  3. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    Ticket number: 1216456
    it's definitely not self shadowing, as the issue is still present with shadows disabled, or with the bias set very high.

    One more example showing the issue of normals with the default shader and inflating the issue with normal mapping + toon shading. Shadows are disabled. Also comparing trails against quads:
     
    richardkettlewell likes this.
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    From the bug report:

    The issue is present in default shaders and any example of a lit line renderer with generate lighting data enabled, so adding my project or toon shaders is unecessary.

    You probably will need to supply some kind of test project in the bug - we have examples that form part of our internal testing suites that appear to work correctly.
     
  5. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    As far as I'm aware, I cannot add a project without making a new report yes?
     
  6. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    New Test Project Bug Report: 1216759 the report includes a detailed description of the test bed and issues. (If there was a way to update a report forgive my ignorance.

     
    Elfstone and richardkettlewell like this.
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Thanks for the report. We are assuming that, as the line faces the camera, its normals can simply use the vector from the line vertex to the camera plane.

    I see from your diagram that this is an oversimplification. We will have a look at the bug report and see if we can generate better normals.

    Thanks!
     
  8. Elfstone

    Elfstone

    Joined:
    Apr 13, 2015
    Posts:
    26
    Any update on this?
    I thought I could make a nice rope with LineRenderer by manipulating the normals, only to find out I'm not getting the normals I was expecting, after much coding.
    Seriously, this should be at least in the doc - that it only gens normals from vertex to camera.
     
  9. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    Yeah, I'd also like an update on this, if any.
     
  10. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    So, I started working on building my own line renderer from scratch. Seeing as you need to build the normal and tangent vectors in order to build the line in the first place, I have NO IDEA why unities line render neglects to use these vectors and instead builds bad ones.
     
    Last edited: Oct 24, 2020
    ethanicus likes this.
  11. Elfstone

    Elfstone

    Joined:
    Apr 13, 2015
    Posts:
    26
    Ha ha, you would think it'd be at least optional, if it was for performance.
    I've learned to accept the reality that Unity's full of unexpected problems (likely because the crew don't work on building real games) and most of the time unfixable - given that I have no access to the source code - and my bug reports though made it to the issue tracker, are gonna stay there forever.

    Also, nice lines you've got.
    I needed only a few ropes on the screen, so I simply built mesh from LineRenderer every frame.
     
  12. xHammy

    xHammy

    Joined:
    Aug 11, 2017
    Posts:
    27
    I'm not really sure what the line renderer does under the hood, but seeing how it's influence by camera direction, and mine is only dependent on direction from camera to the points, I guess they use that instead for some marginal performance gain, as apposed to using view direction to each point. Not really sure.

    I wanted to be able to do ropes and do the Itano Circus.

    definitely having fun so farz but also annoyed the built in line renderer just uses the camera direction as the normals.
     
    ethanicus likes this.