Page MenuHome

T47478 better generated UVs for UV sphere
AbandonedPublic

Authored by peter lu (pdlla) on Sep 7 2016, 8:31 PM.

Details

Summary

UV sphere now uses equirectangular mapping to generate UVs. I would have liked to use quads on the top and bottom row but those faces only have 3 vertices so I went with the spiky triangles.

The rounding is done by scaling the x coordinate by an arbitrary factor of sin(phi*0.7) i.e. the code looks something like

theta = atan2f(y,x);
float phi = acos(z / len);
float phiScaled = (phi-M_PI/2.0f)*0.7f + M_PI/2.0f;
luv->uv[0] = 0.5f + sin(phiScaled) * theta / (float)M_PI / 2.0f;
luv->uv[1] = 1.0f -  phiScaled / (float)M_PI;

Related to D2186 though I believe both patches can be applied independently of one another.

Diff Detail

Event Timeline

peter lu (pdlla) retitled this revision from to T47478 better generated UVs for UV sphere .
peter lu (pdlla) updated this object.

Is there a way for me to tie this to maniphest task T47478? I couldn't figure out how to do this but I noticed my last D2186 is tied to the T47478.

Note, the image I used is an old one. The code in this patch (specifically lines 686-710) will shift the UV map to fit in between [0,1].

For tying tasks to a revision, just mentioning it will add links in both ways.

Is this actually an equirectangular mapping? I would expect it to fill the whole image and not have these rounded edges on the sides. In my opinion it should be compatible with typical equirectangular environment maps you can use in Cycles too, except at the poles where it's not possible unfortunately.

Was this done differently to minimize distortion in some way? To me it still seems more important to be compatible with existing maps and to wrap around nicely.

The not rounded map is a special case of the equirectangular map though I only found out just now that it's also the "standard" map for uv spheres. Someone pointed out in T47478 that the maya default uv map fills the space and is not rounded. Is this what you were thinking? I'm not familiar with cycles.

A quick fix for this would be to change.

float phiScaled = (phi-M_PI/2.0f)*0.7f + M_PI/2.0f;

to

float phiScaled = phi;

On a related note, I've been working on the UVs for Suzanne and made a few changes that could effect this patch and D2186. I'm a little confused as to what the best way to submit new diffs that are dependent on my previous diffs. I was either going to wait until these ones got added or delete both these diffs and submit a single diff with all the update UVs. I could also go back and carefully split the changes up and update the diffs so the 3 UV map patches are independent. Any suggestions?

Anyways, thanks for the input! Getting the hang of blender. This is pretty fun :).

@peter lu (pdlla)

If you can, post images with comparison of the two mapping cases and possible distortions with UV grid or a tiled texture.

Having a drop down menu with the choice of mapping between two cases wouldn't be difficult to add (for instance it already exists in Unwrapping last operator Method (Angle Based/Conformal) if both of them have benefits for users.

Yes, I was thinking something like the maya default. That's what typically meant by equirectangular in computer graphics. In Cycles you'd use maps like these, though they are inside out.
https://hdrihaven.com/hdris.php

But even if you look online for maps of e.g. earth or planets they typically fill the entire rectangle. I would try to avoid options here if possible. It's not clear to me what the advantage of this rounded mapping is for texture mapping, where using as many pixels as possible and wrapping around are important.

You can go ahead and create a new diff with all changes and close these 2 diffs, that's probably easiest.

peter lu (pdlla) abandoned this revision.Sep 12 2016, 6:31 PM

I'm closing this and D2186 to submit a new patch with updated UVs for uv sphere, icosphere and Suzanne.