You do not need environment geometry at all. All you have to do is draw a full-screen square and just calculate the correct texture coordinates for it. Now with modern GL, we donβt even need to provide vertex data for this, we can use attribute rendering:
Vertex Shader:
where invPV is inverse(Projection*View) , so it takes into account the orientation of your camera as well as the projection. This, in principle, can be further simplified, depending on how many restrictions you can impose on the projection matrix.
Fragment Shader:
#version 330 core in vec3 dir; out color; uniform samplerCube uTexEnv; void main() { color=texture(uTexEnv, dir); }
To use this, you just need to bind the empty VAO and your texture, load your invPV matrix and call glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) .
This approach, of course, could be used for spherical display of textures instead of cubic maps
source share