Search Unity

Question (Absolute) World vs Object Space Triplanar mapping performances

Discussion in 'Shaders' started by Beauque, Jan 5, 2021.

  1. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    61
    Hi, with Shader Graph I am working on a URP terrain shader that will be used in PC (and maybe Android) VR apps, and I plan to implement different mapping options such as Triplanar and UV mapping.

    For the triplanar mapping, I suspect having it in Object space costs less than using Absolute world space as input position, but I wish to know what's the real deal, if there is any, between the two options in terms of shader optimisation. It's also important for me to know because the choice will impact my workflow.

    Thanks in advance :)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Absolute world space is cheaper.

    By default lit Shader Graph shaders already always have the world space position, as it's needed for lighting. It does not have the object space position, so it must calculate it from the world space position if you use it in the node graph. It's not much more expensive, as it's only an extra matrix multiply, but it is slower.

    Plus if you're using normal maps, the Triplanar node is totally broken when using object space inputs. It always assumes you're passing in a world space position and normals. I posted a sub graph layout that handles object space triplaner normal mapping here:
    https://forum.unity.com/threads/sha...pace-normal-mapping-help.546322/#post-3605377
     
    andrew-lukasik and Beauque like this.
  3. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    61
    Thank you very much bgolus for the explanations. Lets go world space then

    Yes noticed that. In a different project I needed everything object space and there your graph came to the rescue already :D
     
  4. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    I've been using a custom triplanar node built 99% on your solution, later on however i noticed i could simply use the Triplanar node in Default mode and then use that to sample a normal map and then pass it through a Normal Unpack node set to tangent space. Is there some reason i shouldnt do that what do you think?

    edit: never tested with a complex object, turns out the tangents dont work quite right in motion when done that way.
     
    Last edited: May 11, 2021