Jump to content
  • Advertisement
Sign in to follow this  
Magmatwister

Sky Sphere/Spherical Texture Mapping

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Before you tell me to consult google, believe me I have xD. I'm looking for a real code sample or else some good detail on how to create a Sky Sphere. For my game (Space game with a starfield), I need to create a Sky Sphere programatically and then render stars (Point sprites at this time) to it. At the moment I'm using a normal(box) for a skybox and then just rotating the camera 90 degrees and rendering it to the skybox textures directly. I have no idea how I would translate this into a sphere. Can anyone give me some non-vague information? (I'm sure there are others like me who would really appreciate a decent tutorial on this, or code sample, I have been unable to find either).

(I have heard the terms Sky dome and sky Sphere being used interchangeably, but seeing as I need stars to be rendered onto the skybox, 360 degrees, I am confident I need a sky sphere).

Cheers :P

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Magmatwister
Before you tell me to consult google, believe me I have xD. I'm looking for a real code sample or else some good detail on how to create a Sky Sphere. For my game (Space game with a starfield), I need to create a Sky Sphere programatically ...


I was thinking of outlining an algorithm here for creating a (sky) sphere programmatically, but then realized I could not beat the information Google gives for the question create a sphere programmatically, namely this long gamedev thread: Programatically create sphere.

;)


Share this post


Link to post
Share on other sites
I've been on that thread before actually ;P, but no, I can make the the sphere but.. actually utilising it as a sky sphere is an entirely different thing? First I think I'd have to reverse the normals so that the texture is on the inside of it? But then after that how do I render point sprites onto the sphere texture, without distortion? That's the major problem here, I should have been more clear I suppose ;P

Share this post


Link to post
Share on other sites
Sure, reverse the normals, *and* flip the triangle winding order (if you have culling enabled for the sphere).

I am not sure which distortion you are referring to with respect to the point sprites. If the issue is that the point spheres are clipping through the sky sphere, it will help to draw the sky sphere without depth writes enabled. If you are having issues that the point sprites are screen-facing unrotatable billboards, but the sky texture is curving, then perhaps generate the geometry yourself, or keep to small point sprite sizes so that the issue is not noticeable.

If it's something else, perhaps you could clarify on that a bit?

Share this post


Link to post
Share on other sites
No, I mean actually rendering all the sprites to texture and then applying that to the sphere. The texture is a square essentially, how could I possibly apply that to an entire sphere? Whereas with a normal skybox you would just rotate 90 degrees each time and render to 6 textures, how would I do that for a sphere? I'm rendering the point sprites ONCE and then placing them into a texture which gets applied to the sphere. I don't know how else I can explain it.

Share this post


Link to post
Share on other sites
Quote:

...But then after that how do I render point sprites onto the sphere texture, without distortion?


I think that you can't get "perfect" UV mapping with spheres.
Have you tried creating cube texture and saving it into file so you
can later use it with skybox?

Share this post


Link to post
Share on other sites
Ah, I see. So you're pre-generating a texture to be used in your sky geometry. The first link I posted also touches UV mapping on a sphere, and you can find several others with keywords like uv mapping sphere. See for example here for a quick comparison: VTerrain: Spherical Textures.

With a textured approach you will always have distortion, since the texels will never match the screen-space pixels 1:1.

When UV mapping a sphere, there is also extra distortion due to Gauss's Theorema Egregium. For more information on different kinds of projection methods you can "settle on", see for example Wikipedia's map projection page.

Share this post


Link to post
Share on other sites
Quote:
Original post by Erik Rufelt
Why do you need a sphere instead of a box?
Or are you asking how to generate the stars on a sphere to render them to box textures?


Because at the moment, you can clearly see the borders of the skybox. There are too many inaccuracies in terms of depth at the borderlines. It's not REALLY bad, but if you look too closely It is easily noticeable, too much so for me to be comfortable with it. I want to use a sphere instead because It should generate "perfect" depth perception as well as no borders, if my logic serves me correct :P

Quote:
Original post by clb
Ah, I see. So you're pre-generating a texture to be used in your sky geometry. The first link I posted also touches UV mapping on a sphere, and you can find several others with keywords like uv mapping sphere. See for example here for a quick comparison: VTerrain: Spherical Textures.

With a textured approach you will always have distortion, since the texels will never match the screen-space pixels 1:1.

When UV mapping a sphere, there is also extra distortion due to Gauss's Theorema Egregium. For more information on different kinds of projection methods you can "settle on", see for example Wikipedia's map projection page.


0_o that stuff look's incredibly complicated to implement. I'm going to have to try though ;D

EDIT:
If I ever manage to get a working sample that gives good results, I'll make sure to make a code sample somewheres ;P

Share this post


Link to post
Share on other sites
Quote:
Original post by Magmatwister
Because at the moment, you can clearly see the borders of the skybox. There are too many inaccuracies in terms of depth at the borderlines. It's not REALLY bad, but if you look too closely It is easily noticeable, too much so for me to be comfortable with it. I want to use a sphere instead because It should generate "perfect" depth perception as well as no borders, if my logic serves me correct :P


If you render your stars as point-sprites, they will be in view-space, which will be different for each cube-face, and therefore give you borders. If you make them face the center point no matter which cube face you are rendering, then you should get the correct behavior. Rendering correctly to a cube-map and then rendering that as a skybox should not give you any kind of visible borders at all.
What API/version are you using?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!