cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

ouch
Journeyman III

HLSL shader question

ok, I feel so stupid because I can't seem to fix this myself without takeing extreme measures. (there must be a better way) But here's the problem:

lets say you have a 2d plane model. (flat square) And on that plane is a normal map of half a sphere. So when you look around the plane the light reflects off it's seemingly smooth surface. Now what i want to do is to take an ordinary picture (ati logo for instance) and apply it to that plane. This sounds simple enough, and it is, but how do you get the image to distort approprietly according to the normal map? So that when rotated the image appears to be on the curved surface of the normal?

The only thing I've come up with involves reflections and refractions. But there must be a less GPU intensive approach.

0 Likes
3 Replies
bpurnomo
Staff

Are you trying to apply a texture map to a 2D plane with a normal map such that the texture map follows the distorted 2D plane from the normal map?

If so, then I don't think there is a simple solution.

The sketch of the solution above is to compute the displacement of the 2D plane based on the normal map (by integrating), and then perform the texture map based on the resulting displacement (both these steps can be done in a pixel shader).  The second step is similar to the parallax mapping technique.

 

0 Likes

could you maybe provide some sample code? (or at least a rough layout)

 

thanks for the reply.

0 Likes

I am not aware of any public codes relating to the solution of your problem.  You might have to piece several parts together and conduct your own experiment.

For the first part, computing the displacement from a normal map, his is typically done by integrating the normal map.  You might be able to find some codes online.  If you assume your normal map is a normal map of half a sphere, you can do some simple calculations.  Basically the normal vector at each texel can be used as the displacement (you just need to scale it appropriately). 

For the second part, you need to adjust the texture coordinates of each pixel in the 2D plane according to the displacement.   For this, you can study the parallax mapping codes in the Microsoft DX9 SDK samples (or any parallax mapping codes you can find online).

Good luck!

0 Likes