Search code examples
openglgraphicsrendering

Project cubemap to 2D texture


I'd like to debug my render to cubemap function by projecting the whole thing to a 2D texture just like this one:

On my render from texture shader I've only got the UV texture coordinates available (ranging from (0,0) to (1,1)). How can I project the cubemap to the screen in a single draw call?


Solution

  • You can do this by rendering 6 quads and using 3D texture coords (s,t,p) pointing to each vertex of the cube so 8 variations of ( +/-1,+/-1,+/-1 ).

    The UV 2D coords (s,t) like 4 variations of (0/1,0/1) are not usable for whole CUBE_MAP only for its individual sides.

    Look for txr_skybox in here

    on how CUBE_MAP is used in fragment shader.

    PS in OpenGL the texture coords are called s,t,p,q instead of u,v,w,...

    Here related QA: