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): half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w; float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir); Thanks a lot
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
tested this while ago, Parallax Occlusion Mapping + Self Occlusion shader https://github.com/amsgames94/POM (not really good texture)
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.
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.