I want to write an spherical mapping for my ray-tracer to generate UV-coordinates for the sphere. The texture applied with that mapping should looks like that:
I have the sphere that is located at [0.0f,0.0f,0.0f]
with the radius
of 20.0f
.
For given xyz
point on sphere's surface (position where ray from ray-tracer hit the sphere) I calculate the uv
coordinates with this formula:
float u = 0.5f + atan2(point.getX(), point.getZ()) / (2 * PI);
float v = 0.5f - asin(point.getY() / radius) / PI;
I decided to output u
and v
values to test the mapping.
As for v
it looks quite ok (values from one pole to another, from 0.0f
to 1.0f
):
But the u
does not look so good:
Shouldn't it be an sphere where color depends on XZ (same for all points on the same longitude, gradually changing from one longitude to another)?
Am I wrong with interpretation of point
, formula or something else?