Open jayden-ong opened 10 months ago
I now noticed that the header file specifies to use Mercator parametrization, but in grading, I don't really care which projection you are using. However, using the inverse projection (the one in tutorial and in class) will lead to numerical issues like that.
Since for sphere.cpp, we are working with UV (we basically map UV to a 3D sphere), so maybe it is easier to do Mercator in the first place. Nevertheless, using inverse projection is also intuitive.
Is ||x|| just the absolute value of "x"?
No. $||x||$ is the 3D coordinate of the point, since we are working with a sphere $||x||$ will be the radius of the sphere. EDIT: I made a mistake here!
What happens if z/||x|| isn't between -1 and 1? For example, what happens if "x" is really small?
In the case of a sphere, if your sphere center is at the 0 vector and the sphere is sufficiently sampled (for discretization), I think this will not happen unless it is the north/south pole. For north/south pole of the sphere, x and z will both be zero, and it in theory maps the north/south pole to the top/bottom boundary of the UV texture. Heuristically, I think you can choose a point on the top/bottom boundary of the UV if you are assigning v for north/south pole.
Let me know if this doesn't work.
Be careful that the formula I have in the tutorial is the same as the one in the lecture slides, which assumes our view angle is Y-up on the XZ plane.
EDIT: fixes for the stretching artifact in inverse projection formula
For people reading this: please skip sphere UV and work on other files first if you are running into similar issues.
Several students have reported using inverse projection will lead to visual artifacts. I need to implement the inverse projection formula and see if it is possible to get bug-free UV at all.
EDIT: I am still trying to fix the inverse projection formula visual artifact. Please see the post below for how you should approach Mercator parametrization
.
EDIT2: for fixes of inverse projection, please see the post above.
I think Mercator parametrization
might refer to the $\mathbb{R}^2 \to \mathbb{S}^2 \in \mathbb{R}^3$ sphere paramtrization mapping:
$$(\theta, \phi) = (2\pi u, \pi v),$$
$$(x,y,z) = (\cos(\theta)\sin(\phi), \sin(\theta)\sin(\phi), \cos(\phi))$$
where $(u,v) \in [0, 1]^2 \subset \mathbb{R}^2$ in the UV (image) space, $(x,y,z) \in \mathbb{R}^3$ in Euclidean coordinate space, $\theta \in [0, 2\pi]$ is the azimuth angle and $\phi \in [0, \pi]$ is the polar angle in spherical coordinate system. Here, we omit the radius term $r$ since we are working with a $r=1$ unit sphere.
Therefore, it becomes trivial to construct the UV mapping for a sphere as we map the UV (matrix UV
) to a 3D coordinate (matrix V
).
Note that due to libigl/OpenGL viewer coordinate system, you might want to negate the $z$-component in $(x,y,z)$ so that the sphere gets the correct UV orientation. Otherwise, Toronto will be on the "West Coast" lol.
Sorry for the confusion. See here for details. For the implementation of sphere UV, please follow the derivation done in this post.
According to the tutorial pdf, in order to calculate "v", we have to do: acos(z/||x||).
Is ||x|| just the absolute value of "x"?
What happens if z/||x|| isn't between -1 and 1? For example, what happens if "x" is really small?
Edit: My current problem is that there are many points where "v" is nan.