Advertisement

State-of-the-Art SkyBox Rendering

Started by May 15, 2020 01:27 PM
1 comment, last by Adam_42 4 years, 8 months ago

So I'm just looking at doing a simple skybox that samples a cubemap. I can think of two main ways I'd do this:

  • Classic, geometry centered around the camera rendered at full depth. I think I'd opt for a tetrahedron instead of a box, but it's the same general idea.
  • Full-screen quad where the sampling direction is just figured out in the shader.

I like the latter option for its simplicity and because it seems like I could just make a compute shader for it. But I'll lose any benefit of the z-buffer, won't I. I'll have to evaluate every pixel and I might as well render it up-front and then draw on top of it. Whereas with the geometry approach I can render it last and only shade the parts of the sky that are visible.

Anyone have any insights? What's state-of-the-art right now, specifically for skybox rendering? (Not sky rendering in general, i'm not looking for ray-marched clouds or atmospheric scattering. Specifically just the skybox itself)

Your geometry (full screen quad, or actual box / sphere / tetrahedron) wants to be rendered with depth testing enabled, and depth writes disabled, at the far plane, after all other opaque geometry. To move it to the far plane, just set position.w = position.z at the end of the vertex shader. That way the depth test will avoid the cost of shading any pixels that are behind other geometry.

To look up the texture in the cube map, what you need is the direction from the camera to the sky. That's simple to calculate if you have real geometry instead of a full screen quad as you'll have the position from the vertex shader and can just subtract it from the camera position.

This topic is closed to new replies.

Advertisement