Sphere Texture Mode: Coordinates Mess

I need to create a sphere with polar coordinates for texture coordinates. This means I expect to gain two angles at least.

I’ve been debugging the coordinate values that TextureMode.Polar creates for a longer time now and I’ve also looked into the code. I’ve come to the conclusion that the coordinates, that TextureMode.Polar creates, are not polar at all, but some sort of Cartesian?!

In Sphere.java, the vertex locations are created like:

Vector3f kRadial = tempVc.set(afCos[iR], afSin[iR], 0);

Of course this is the Cartesian location of the vertex, which is right.
But then, look how the “polar” coordinates are created:

float u = r * afCos[iR] + 0.5f;
float v = r * afSin[iR] + 0.5f;

Here iR is an angle. These aren’t polar coordinates!

Questions:

  1. Why is there this misnomer?
  2. How do I get a sphere with polar texture coordinates?

From the code it seems that TextureMode.Polar has nothing to do with “polar coordinates” and instead refers to a form of mapping that shows the texture undistorted when viewed from the poles.

…for example, if you were trying to map a polar view image of the earth to a sphere.

I think it’s about what you expect ‘texture mode’ means. If you take it to mean ‘texture projection’ I don’t think polar coordinates is what is expected when talking about ‘polar’.
Some popular projections are: ‘Planar’, ‘Box’, ‘Lollipop’, ‘Cylindrical’ - the names shouldn’t lead you to expect ‘Lollipop-coordinates’ any more than ‘polar coordinates’ :smile:

here are some examples of projection names from other software.
https://renderman.pixar.com/resources/RMS_3/index.html?url=ProjTex.html
http://softimage.wiki.softimage.com/xsidocs/tex_basicproc_TypesofTextureProjection.htm#Rft19665

Indeed, but then TextureMode isn’t self-explanatory enough, especially from a shader authoring point of view, neither is the documentation clear on this point. In fact one has to dig into the code to get clarity. Maybe TextureProjection would be better.

Mhh that’s not completely clear indeed.
This class is old and inherited from jme2. Not sure what the original author wanted to do exactly.

Sure thing is that TextureNode.Polar is absolutely not using polar coordinates. So I agree it’s confusing.

If you like, you can submit a pull request with better JavaDoc :stuck_out_tongue:

But changing the meaning of the names will break backward compatibility with applications that assume those modes work in a certain way …

The description could probably be improved… but the current one does actually say what it’s doing:
“Apply texture to each pole. Eliminates polar distortion,
but mirrors the texture across the equator.”

It never mentions “coordinates” at all. And just to be clear, other PolarXXX things that it doesn’t mention and that are also not relevant:
Bear
IceCaps
Opposites
Vortex
Express
:slight_smile: :slight_smile: :smile:

Aside: I miss our old smileys.

1 Like