Search Unity

Surface shader ParallaxOffset issue

Discussion in 'Shaders' started by MaT227, Oct 26, 2016.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Hi there,

    I am trying to use the ParallaxOffset function to calculate parallax but it gives strange results. Any special thing to do to make parallax working with surface shaders ?

    The issue appears when I rotate my object, which destroys the parallax offset effect.

    Code (CSharp):
    1. half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w;
    2. float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
    Thanks a lot
     
    Last edited: Oct 26, 2016
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    That's just how Unity's ParallaxOffset works. It's cheap and it looks decent for small offsets, but it falls down completely for large offsets and most viewing angles.

    When most people think of parallax shader effects they're actually thinking of parallax occlusion mapping or one of several other similar shader effects which are much more expensive.

    There's a bunch of examples around the internet of parallax occlusion mapping, or relief mapping which is a slightly better alternative, but there's not too many free examples available directly for Unity.

    Here's the only one I know of. The majority of the shader code is kind of worthless for Unity 5, but the main bit of code that does the actual relief mapping should work fine.
    http://wiki.unity3d.com/index.php?title=ReliefSpecular
     
    olli_vrcoaster likes this.
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,413
  4. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Thanks for your answers @bgolus @mgear . It seems that my issue came from the fact that I was not outputing the Normals from my surface function. This can be seen when you output the viewDir. It's not the same with and without Normals.
    So Unity was doing some under the hood stuff which was breaking my parallax calculations. But I don't really know why... as in my opinion this is not a nice behaviour.
     
  5. IllidanS4

    IllidanS4

    Joined:
    Jul 23, 2013
    Posts:
    7
    Yeah, Unity removes all the viewDir computation if you don't use normals. This makes the result significantly cheaper, but parallax won't work since it needs that too. For the same reason default parallax effect doesn't work for shadows.