# Repeating textures on a sphere

This topic is 3362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I've a small problem with calculating a spherical uv map. I use the following equation to get the u and the v values: $\theta = \arccos{\frac{z - z_{c}}{R}}$ $v = \frac{\pi - \theta}{\pi}$ $\phi = arctan2(y - y_{c}, z - z_{c})$ $u = \frac{\phi}{2 \cdot \pi}$ Now my problem is when I use bilinear interpolation to render the image and my image is smaller than the surface of the sphere, this equation will simply "enlarge" my image. This is absolutely not what I want, I want it to "create" "tiles" so the surface of my sphere is filled with replicas of my image. If you think there is a problem with my bilinear interpolation: on triangles my "tiling" DOES work (combined with bilinear interpolation). So any ideas how I can fix this? Thanks for your time and effort!

##### Share on other sites
You can simply scale up u and v by multiplying both of them by a scaling factor. Make sure your rendering pipeline is configured in a mode where wrapping will repeat the texture (e.g., in OpenGL set GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_REPEAT).

##### Share on other sites
I'm sorry, I'm using ray tracing. Not perspective projection.

##### Share on other sites
Same deal though. Just take the (u,v) coordinates you calculate as above, multiply u and v by the u and v frequencies with which you want to tile (meaning: how may times the texture repeats in each direction). A mod operation is needed later on when you calculate indexes into your texture to wrap the result.

I.e. (simplified),

u = as above
v = as above

u2 = uFrequency*u
v2 = vFrequency*u

textureValue = texture[u2%textureUsize][v2%textureVsize];

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×