I would like to simulate a moving sun on the sky. What I have managed to do so far is calculating the exact location of the sun, that is the 3D direction vector from the camera's position in the world to the sun. The sky is the cube with 6 faces textured with some cube map texture. The skybox positon is constantly being set to the position of the camera, so that the camera is always in the cube's center.

Now, I have a simple 2D texture of the sun that I would like to render onto the cube map texture using the aforementioned direction vector. Could you please describe how I can achieve this? My reasoning is that I need to bind the framebuffer of the cube map and then render the sun mesh with the correct sun texture. But how do I specify the position of the sun here so that it matches the direction vector I have calculated earlier? Another question is if there might be problem when it happens that part of the sun is supposed to be rendered on one face of the cube texture and the other part on some other face of the cube texture?

Thank you in advance.


1 Answer 1


Why render the sun into the skybox? Just render the skybox and then draw the sun without using a depth test. This way you don't have to modify any textures and then redraw them. It's much easier to draw the sun where it belongs that way, too.

As Nicol Bolas mentions in the comment, you can put the sun behind the skybox if it's transparent. You might do something like set the clear color to a sky blue and clear it, draw the sun in the appropriate position, then draw the skybox containing clouds after that. If you're simulating an entire day, you'll need to change the clear color over time, and rotate the skybox so the clouds look like they're moving.

  • 2
    \$\begingroup\$ Or better yet, render the sun behind the skybox. That allows clouds in the skybox to occlude it. \$\endgroup\$ Dec 17, 2017 at 17:59
  • \$\begingroup\$ That's an interesting point. I was assuming an opaque skybox, but you're right. I'll update my answer. \$\endgroup\$ Dec 17, 2017 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .