# Precision errors when calculating normal map for planet

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

## Recommended Posts

[sharedmedia=gallery:images:7707]

You can see I'm calculating a normal map for a sphere (planet) in world space.. all looks good, except towards the poles there are some grey pixels caused by I assume lack of precision or something... I'm doing this on CPU using floats

given three points on an ideal sphere, I normalize to a given radius and add the appropriate precalulated heightmap value...
normalize(wpos1)*(1000.0+vx);
normalize(wpos2)*(1000.0+vy);
normalize(wpos)*(1000.0+vz);

where the points represent an arbitrary point wpos and its two neighbors... vx, vy, vz are the heightmap values for those points..I multiply by 1000 and then add the heightmap value to lower the overall difference between the heightmap values... and thus making the normal less strong;

then simply:
vec_sub(wpos1,wpos);
vec_sub(wpos2,wpos);

vec_cross(wpos,wpos1,wpos2);
vec_normalize(wpos,1);

As you can see in the picture, all seems to work fine except for the poles... seems there isn't enough precision (or something)  to handle this area... any suggestions?

##### Share on other sites
With the parametrization you have used, the samples at the poles are very close together. Try using doubles for the computation, but even that might not fix the very last line, because all those points map to the same point on the pole and you are then looking at degenerate triangles.

A clean solution would be to use a cubemap instead of spherical coordinates.

##### Share on other sites

You are right about the sampling distance being too close.. when I tried increasing the sampling distance near the poles it looks better.. though its hard to get it exactly right...

Yes a cubemap is probably better..although the poles aren't so important as they will be flatter... I can fix the normal in the pixel shaders...

Still I will think about a cubemap...

thanks

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013753
×