Why do parallax maps in unity not work?

Hey everyone! I have noticed that the parallax maps in unity are not giving the results I’v been looking for. What I’m looking for is something like the relief mapping seen on unity forums and youtube. Here is what result I am looking for

note this is in another engine of course but i know unity can do this.

as you can see it is just a basic cube but when he makes the depth lower you can not tell that it is a cube it looks like he/she modeled each brick!

I’v tried relief mapping shaders but they did not work at all.

ALSO how do i turn a texture into a height map? I’v used displacement maps witch look the same but they do not seem to work, maybe that is the issue?

I know it’s an old question, but I felt the need to answer it in case others run into the same issues.

First, Unity cannot do -that- out of the box. Unity has parallax mapping via builtin shaders, but not parallax occlusion mapping, steep parallax mapping, or cone step mapping. So you won’t get results that look as good as that video. (It’s not Crysis after all). In fact, if you’re curious, the snippet of code that does the actual parallax mapping in Unity’s builtin shaders looks like this:

(From UnityCG.cginc):

// Calculates UV offset for parallax bump mapping
inline float2 ParallaxOffset( half h, half height, half3 viewDir )
{
h = h * height - height/2.0;
float3 v = normalize(viewDir);
v.z += 0.42;
return h * (v.xy / v.z);
}

All it does is distorts UV coordinates by adding an offset determined by the lookup value of the parallax map. The math itself dictates that the bigger your height field is, the less realistic it will look. To do real displacement mapping you would need something like a linear search (steep parallax mapping) or a different type of algorithm completely (cone-step mapping is one of the best, but is unfortunately bogged down in patents).

But to answer your question of why your parallax maps do not work, it’s most likely because your parallax maps are not in the right format. If you look carefully, the default Parallax Diffuse and Parallax Specular shaders require your parallax map to be packed into the Alpha channel (not the RGB components) of the texture marked “Height”. The RGB components for this texture are not used at all. No idea why that’s the way it is, but it does work. This means that your parallax map needs to be either a TGA file or a PNG file, since JPEGs and BMPs don’t support an alpha channel. Also, shaders other people post are not reliable either. Most of them don’t work ever since Unity changed the way some of the builtin shader passes are referenced. Odds are good if the shader was posted before Unity 1.4 came out, it will need some tweaking.

Displacement maps (like the kind CrazyBump generates) are synonymous with parallax maps (or height maps, as Unity may call them), so you’re okay there. It’s probably the alpha channel thing.

Check out my test room to see how Unity parallax mapping is supposed to look:

http://unavail.net/something/alex/detail/WebPlayer.html

Hope this helps =)

Thank you!

By the way, the link is broken :(:(:frowning: