Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I change the normals in world space?

Discussion in 'Shader Graph' started by vladstorm_, Oct 4, 2019.

  1. vladstorm_

    vladstorm_

    Joined:
    Nov 26, 2013
    Posts:
    184
    Hi,

    I'm working on a shader in HDRP+ShaderGraph and ran into a problem that I can't override the normals.
    PBR Master graph expects normals in Tangent Space.
    https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/PBR-Master-Node.html
    Which means I can't actually modify the normals directly ??

    I know it's suitable for most of the cases when people just wanna use BumpMaps/NormalMaps but in my case I really need to set the Normals directly. Is there a way to do that?

    Or also as an option, is there a way to make a variation of existing PBR Master graph and add a new parameter there?


     
    Last edited: Oct 4, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yes, Shader Graph only accepts tangent space normals. It’d be great if it also allowed for object or world space normals, but it does not. You have to use the transform node to transform the normals from world space to tangent space, and your mesh has to have at least half way correct vertex tangents.
     
    forestrf likes this.
  3. vladstorm_

    vladstorm_

    Joined:
    Nov 26, 2013
    Posts:
    184
    @bgolus
    well i tried already to use transform node to transform the normals from world space to tangent space. it didnt work.
    i think it's not gon help coz tangent space sort of has an idea that normals are already set and not gon be changed. or maybe transformation didnt work.
    i had literally rewrite the generated code which is kinda not easy coz is a machine generated code.

    i think unity had to have an option in master node which space to use. that'd be the best option. coz to have a tangent space normals input by default is a bad decision
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    That is how to do it. Tangent space is just another space that you can transform in to and out of. Shader Graph currently always transforms the input normal vector from tangent space to world space, so you're just doing the inverse transform. Yes, it's wasteful, but that's just how it works for now.

    If it's not working, it means your shader isn't calculating proper world space normals, or you didn't set the transform node to direction mode, or your mesh doesn't have tangents.
     
  5. vladstorm_

    vladstorm_

    Joined:
    Nov 26, 2013
    Posts:
    184
    ok, i gave it another try and it worked. hooray! prob i didnt set the node in direction mode before
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Ehredt likes this.