Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


HLSL - Convert Normal map to Parallax Occlusion Map


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Migi0027   Crossbones+   -  Reputation: 2129

Like
0Likes
Like

Posted 13 October 2013 - 09:52 AM

Hi guys! happy.png

 

Just a quick question.

 

I've had parallax occlusion mapping implemented for a while now, but I soon realized that problems came, not every artist wants to create a parallax occlusion compatible map just for some bricks, they've already made some normal maps, but unfortunately they aren't compatible. (Not that I know of...)

  • So how would you be able to convert a normal map to a pom map in realtime, preferably in hlsl?
  • Is the performance worth it? dry.png

I've seen some offline examples, but again, is this possible in runtime?

 

Thanks, as usual.

-MIGI0027


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

Sponsor:

#2 Migi0027   Crossbones+   -  Reputation: 2129

Like
0Likes
Like

Posted 13 October 2013 - 11:16 AM

And how (If possible), would you convert it the other way: Parallax -> Normal?


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

#3 MJP   Moderators   -  Reputation: 11781

Like
2Likes
Like

Posted 13 October 2013 - 01:19 PM

You just need a height map for POM, so there's nothing to "convert" really. You can put the height value in the alpha channel of the normal map if you want as a convenience/optimization, but you can also keep it separate. Usually normal maps are generated from height maps, so your artists should be able to get you one. If you're using a tool like xNormal to bake a normal map from a high-poly mesh it can spit out a height map for you. Or a tool like CrazyBump can try to auto-generate a height map from a color map, although this is an imperfect process. Usually these sorts of tools first generate a height map when you ask them to make a normal map from a color map, and they typically do this by generating height values based on the luminosity of the texel.



#4 Juliean   GDNet+   -  Reputation: 2742

Like
3Likes
Like

Posted 13 October 2013 - 01:50 PM

There is no way to do this properly, at least not in real-time. A parallax-map works by giving the height-offset at a certain point, while a normal map does just that - give the normal vector at a certain spot. You can't directly judge from one of those properties to the other - a normal with (0, 1, 0) at a certain point might be at height 0 or at height 2,5, speaking in geometry. So you'd at least have to look at the whole texture to get a somewhat passable value. Its a bit like creating a normalmap from a diffuse texture - it works (offline), but is never nearly as good as creating a normal map from a high-res model. So, no, AFAIK there is no such way (at last in real time).



#5 Migi0027   Crossbones+   -  Reputation: 2129

Like
0Likes
Like

Posted 14 October 2013 - 12:39 AM

Well that was what I was fearing. MJP: About putting the height in the alpha channel of the normal map, that would be a useful way without wasting any (almost) resources, the only problem is if I don't have a heightmap, just the normal map.

 

Anyway, thanks for giving me this information. smile.png  

 

-MIGI0027


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

#6 Hodgman   Moderators   -  Reputation: 31920

Like
4Likes
Like

Posted 14 October 2013 - 01:00 AM

You can kind-of convert a normal-map back into a height-map. The normal map defines slopes per pixel. If you step from one pixel to the next treating all the slopes as lines (in 1d) or planes (in 2d), and fitting them all so they connect to their neighbours, then you end up with a surface that you can calculate the height of per pixel. Depending on where you start this process from, the whole surface will be shifted up or down, so you'll want to renormalize the heights, by offsetting them all so the average height is 0, or 127 or whatever.

e.g.

dKjiybr.png

 

 If a 2D normal map isn't based on a physical model, or simply due to quantization errors in the normal map, this surface might be impossible, like an Escher-esque staircase. I guess you'd want to apply neighbour constraints in a few iterations, in different orders to converge towards the most sensible solution, which is obviously going to be slow...

 

IIRC, the nVidia photoshop plugin has a filter that can do this for you, so you could ask the artists to generate them that way.

Or, you could implement this algorithm yourself and either execute it on your loading screen, as each normal map is loaded from disk, or make it into an executable that you can use to batch-process all of the normal map files ahead of time.


Edited by Hodgman, 14 October 2013 - 01:23 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS