# Direction to light in parallax/relief mapping

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

## 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:

[attachment=14597:Untitled-1.png]

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 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.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633755
• Total Posts
3013706
×