Search Unity

Strange lighting problem with lights and instanced meshes

Discussion in 'General Graphics' started by joshcamas, Jan 21, 2018.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Hey friends :)

    I'm building a foliage system, which uses GPU instancing of meshes, and I'm trying to get it so my point light attached to my torch affects these instanced meshes (bushes and trees). However, there seems to be a problem, it looks like a render mode problem?

    Note that I am indeed using Deferred lighting, so the number of lights interacting shouldn't be a problem.

    Video of my problem:


    Thank you!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Are you sure your meshes are being rendered via the deferred pipeline? That kind of behavior looks more like forward rendering, which makes me think your shaders aren't deferred compatible.

    You might try using the Scene View Draw Modes or the Frame Debugger to make sure things are working as you expect.
    https://docs.unity3d.com/Manual/ViewModes.html
     
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    That's what I was thinking too, but it looks like it's deferred:


    Also, I'm using the same shader for other things (a house, for example) and it works fine. I've also tried using the standard shader!

    I found out that the lights do indeed show up if you make the light mode set to either important or not important (Only one of them works, I forget which one because...)

    Also, it looks like it's magically fixed...? Now the trees seem to react fine. I have no explanation of this, it's quite strange. I'll keep looking into it, maybe someone else will have the same problem.
     
  4. wtmarcek

    wtmarcek

    Joined:
    Aug 23, 2016
    Posts:
    1
    I've found out that it is caused by multiple lights affecting the instances. However at certain angle the multiple lights works.
     
  5. barbelot

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    I have a similar issue with particles drawn using the DrawMeshInstancedIndirect function. My camera and graphics settings are all set to Deferred rendering to handle multiple lights. This works fine with an opaque material, however when I try to make them transparent I get artifacts with more than one light.

    upload_2018-5-30_19-18-10.png upload_2018-5-30_19-18-33.png

    With a single light on the left, the result is fine, with a second light I get a big white quad and performance are terrible. This quad looks like it is actually drawing the particle mesh for each instance with incorrect procedural properties.

    I use a shader similar to the one from Keijiro's Cloner and I actually get the same big quad (although red as it should be) with a single light if I remove the transformation matrices updates from the procedural instancing properties
    Code (CSharp):
    1. //unity_ObjectToWorld = mul(_LocalToWorld, o2w);
    2. //unity_WorldToObject = mul(w2o, _WorldToLocal);
    which is why I thought additional lights might for some reason use incorrect instancing properties.

    A fix I found is to change the additional lights render mode to "Not Important" however I don't understand why this works as it is stated that the render mode only affects forward rendering which should not be used at all in my setup.

    I'd love an explanation or ideas as to why this is behaving like this.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Deferred is for opaque objects only. All transparent objects are rendered using the forward pipeline after the deferred passes and lighting have finished.

    Yep, it probably is. I haven't played with instanced surface shaders like this, but it's possible there's some bug here on Unity's side where they're not using the instance properties on the forward add passes.

    Setting a light to be "Not Important" forces it to use per vertex lighting. This is good for transparent objects because normal per-pixel lighting is done by rendering the object once for each light. For transparent objects rendering it multiple times can cause odd ghosting issues as each pass just renders over the previous and don't sort. Per vertex lights are calculated during the first pass and thus don't have this problem.
     
  7. barbelot

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    Thanks for the answer, this explains a lot !

    Yeah I have seen this problem pop up a lot when I used Forward rendering with instancing but didn't think about it too much because performance are way worse in Forward with a lot of instanced objects anyway, making Deferred the only viable option to have several lights in the scene with good performance.
     
  8. barbelot

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    Additional note, this problem does not appear in Unity 2017.3.
     
  9. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    same problm on 2018.2.7
     
  10. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    Anyone know if there is fix for that? On 2018.2.13 still the same problem
     
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Report a bug if you think there may be an engine side problem and we can investigate :)
     
  12. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
  13. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I've had a look at the existing issue. We have a backport in progress for it, but with the release of 2018.3 so close, I'm not sure if we will backport it now. (18.2 support ends when 18.3 is released) But I have contacted the developer to confirm whether they will complete the backport.

    Best regards,

    Richard
     
    Jakub_Machowski likes this.
  14. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    great to hear that I hope it will be possible to uprade. I didnt know that 2018.2 will totally lose support when 2018.3 released. The problem is that many system from asset store wont work for long time after 2018.3 first release cause there is many big changes, like prefabs, gpu terrain and terrain layers, and it take alot of time for asset store creators to upgrade their systems. This is why we decided to keep to 2018.2 but losing support scared me al ittle :) Hope you will be able to backport that fix ;)
     
  15. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi Jakub,

    The fix was merged into 2018.2 a few days ago. The issue will be fixed starting with 2018.2.18f1. The fix was about real-time GI and GPU instancing that didn't work properly together.
     
  16. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    Yes exactly when there was precomputed realtime GI baked and in the same time Instancing GI tuned on on object there was a problem :) Than you a lot! Waiting for that!

    Great Support!
     
    richardkettlewell likes this.
  17. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    The bug is back in unity 2021.3.... I don't know what to say unity :)