Jump to content
  • Advertisement
Sign in to follow this  

Direction to light in parallax/relief mapping

This topic is 1995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm implementing parallax/relief mapping and I have a question. With this technique I'm calculating offset from incoming uv coordinates. Next I'm getting color from maps based on this uv. But I can't get correct vector to light now. Here's a picture:




Here initially I have a fragment a with uv, vector to light etc. After calculating offset, I have fragment b. As can be seen, I don't know fragment's world position, so I can't calculate vector to light.


In existing sources in the web normal is taken from point a. It's not corect, but it seems that it works. But may be there's a solution? What can you say?

Share this post

Link to post
Share on other sites

depending on the depth of your displacement, the light is supposedly so much farther than the vector will not be very different. it will make a difference only on very incident angles AND deep regions in the depth map AND with lights very close to the parallaxed surface. Many conditions that suggest that the calculation overhead to get the correct vector is not necessary.

If you really want that vector : you know the UV to get the color ? then you also know the UV to read the height map, you just have to use the world position of the plane at UV b and go towards the inverse normal from a distance dictacted by the heightmap's value (x artist factor that tunes the depth extent).


To get the world position of b : either you can use the rastered world position passed from the vertex shader through the varyings (which is the world position of a) and displace it according to ddx/ddy of the depth of the position reprojected into viewspace, and multiply by the difference of UV rescaled into viewspace. (using the vertex buffer min/max of the coordinates and the world matrix to estimate this scale factor).

This one is complicated and imprecise.


Another way would be determining the vector a to impact.


or, the one I recommend : find the local position (in plane space) using the UV; normally the UV should range 0 to 1 (in float2) and simply be an exact equivalent of the local coordinate in object space. then you just need to make it 3d by putting 0 in the Z (since it is a plane) and multiply by the world matrix and projection matrix to get the world coordinate. there you go.


Remain the problem of shadowing, you need to evaluate if that ray is free to reach the light or not. same principle than what you did to find b.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!