View Full Version : What part of textured sphere is viewable
07-21-2011, 11:29 AM
I have a textured sphere that is centered at the middle of the viewport. It's always centered at the middle of the viewport but can be rotated and I can zoom in by changing the fov. To the side of that, I have the same texture that I put on a sphere painted on a flat (2d) quad. What I am trying to figure out is no matter what rotation or zoom level I am on the sphere, how can I highlight, on the 2d quad, what part of the texture is viewable on the sphere.
Sometimes the whole sphere is shown and sometimes not. The middle parts of sphere aren't too bad but the poles are what's giving me troubles.
This may be a little confusing so I attached a picture of what I'm trying to do. Let's just say the red box on the sphere is the viewport, so only part of the sphere is being seen while the rect on the left is the texture and the red box on this rect is the highlight of what is viewable in the sphere's viewport
The Little Body
07-21-2011, 03:24 PM
This is typically the problem of the polar mapping (problem with the mapping on the poles) :(
This can be minimised used this technic http://www.thebest3d.com/dogwaffle/lua/polar/index.html
Or something like the log-polar mapping http://users.isr.ist.utl.pt/~alex/Projects/TemplateTracking/logpolar.htm
(or his inverse ....)
Cube mapping can be a good solution too
07-22-2011, 07:36 AM
Thanks for the reply but I'm not really having trouble texturing the sphere. What I'm looking for is how to determine what part of the texture is viewable depending on the rotation and zoom level of the sphere
The Little Body
07-22-2011, 05:06 PM
Why using viewport transformation (cf. "zoom in by changing the fov") instead to use model transformations like glRotate, glTranslate or glScale ???
Are you sure that the projection of the viewable part of the texture on the sphere is a rectangle ?
(never tested/verified, but I think that is more an ovalo´d shape than a rectangle, but perhaps that is effectively a rectangle)
07-22-2011, 06:55 PM
I use the fov to zoom because if I used glTranslate or glScale and I went in too close I ended up going inside the sphere which I didn't want.
The viewable part of the texture is definitely not a rectangle I just threw that image together quickly in mspaint. I'd just like to highlight a general area of what is viewable so a rectangle would do in regions that don't include either pole.
The Little Body
07-22-2011, 07:15 PM
If you don't want to going into the sphere, you can handle a constraint for that the viewpoint can never go too near the sphere
Perhaps that using/mixing the inverses of texture, modelview, projection, viewport and viewing matrices can help ?
Or store fragments (u,v) values into a pbuffer and read this pbuffer after but to find the "min/max (u,v) values" (cf. the 4 corners of the part of the texture that is used) ?
Better, directly compare/store min/max textures coordinates (u0,v0)/(u1,v1) with the current fragment shader (u,v) coordinates values via uniforms
and convert them at the end to the (x,y) position and (width,height) size of the rectangle using
x = u0
y = v0
width = (u1 - u0)
height = (v1 - v0)
07-23-2011, 11:43 AM
That was my strategy at first if I'm reading your post correctly. The poles, though, present problems with this technique. Also presents a problem where the left and the right ends of the texture meet on the sphere.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.