Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[LWRP] Certain primitives get their world position as local position in their shaders

Discussion in 'Graphics Experimental Previews' started by JohanF_TF, Jan 15, 2019.

  1. JohanF_TF

    JohanF_TF

    Joined:
    May 20, 2015
    Posts:
    75
    Hello

    Having this issue in both 2018.2.6 with LWRP 3.0.0 as well as 2018.3.0. Haven't gotten around to trying it out in 2019.

    It appears as if certain primitives (planes, quads, cubes, cylinders) get their world positions as local positions in their shaders IF there are more than one of that type in view. Same issue occurs with a model an artist built in Blender which was also a plane.

    I've tried in LWRP, HDRP and standard, only see the issue in LWRP.

    I've tested with a super simple shader: based on the object's y position (v.vertex.y), compare it to a step value and use the result as albedo, so it'll return black or white.

    Adjusting the step value, everything behaves as expected. Setting the editor to LWRP, suddenly certain objects mentioned above use their world positions in place of local, so need to set the material to their world y position for the same effect. If there is only 1 e.g. cube in view, it works. If a second one enters view, issue appears.

    Spheres and cylinders are unaffected.

    Sorry if this is a known issue, I couldn't find anything about it. I hope I'm not missing something, but I have a hard time seeing this is how it's supposed to work.

    Attached the shader I used to debug this.
     

    Attached Files:

  2. JohanF_TF

    JohanF_TF

    Joined:
    May 20, 2015
    Posts:
    75
    Have also submitted a bug report with an example
    1117576
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  4. JohanF_TF

    JohanF_TF

    Joined:
    May 20, 2015
    Posts:
    75
    Interesting, that works. Thanks!

    I tried disabling Static and Dynamic batching as one of the first things I did, since it looked like a batching issue, but that was apparently not sufficient. Adding that tag works, though. One issue is that shaders generated in the graph have this enabled, so it's cumbersome to manually add every time.

    That leads to some follow-up questions though. Why does this only happen in LWRP? And why does it only affect certain object types? And how does setting the tag in the shader differ from globally disabling batching features?
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  6. JohanF_TF

    JohanF_TF

    Joined:
    May 20, 2015
    Posts:
    75
    Oh crap, you are right. I forgot about that...
    Disabling it in the LWRP settings gets rid of the issue.

    So fiddled around a bit more to confirm, and yes: it's the dynamic batching that does it. Sp type of object doesn't matter, as long as it's elible for dynamic batching, the issue occurs.

    GPU Instancing does not cause this issue.

    Thanks again
     
  7. JohanF_TF

    JohanF_TF

    Joined:
    May 20, 2015
    Posts:
    75
    Followup for anyone interested

    Did some testing, it seems it all boils down to batching in the end and is probably by design

    I said it only affected LWRP; that was because LWRP has its own dynamic batching setting. I tried again with HD and standard, and could reproduce the behaviour with toggling the batching settings in the player settings accordingly. Setting the static batching flags on the game objects, the same behaviour is reproduced in the capsules and spheres as well, i.e. objects that aren't automatically dynamically batched.

    So I can accept that this happens and why it happens, however I don't fully understand why worldposition would be used as local position. Even when batched, the local position should be the same?
     
  8. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584