31 lines
974 B
Plaintext
31 lines
974 B
Plaintext
|
out vec3 TexCoords;
|
||
|
uniform int face;
|
||
|
|
||
|
vec3 cubemapCoord(vec2 uv, int face) {
|
||
|
vec2 UV = 2.0 * uv - 1.0;
|
||
|
if (face == 0) return vec3(1.0, -UV.y, -UV.x); // +X
|
||
|
else if (face == 1) return vec3(-1.0, -UV.y, UV.x); // -X
|
||
|
else if (face == 2) return vec3(UV.x, 1.0, -UV.y); // +Y
|
||
|
else if (face == 3) return vec3(UV.x, -1.0, UV.y); // -Y
|
||
|
else if (face == 4) return vec3(UV.x, -UV.y, 1.0); // +Z
|
||
|
else return vec3(-UV.x, -UV.y, -1.0); // -Z
|
||
|
}
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
// Generate a fullscreen quad
|
||
|
vec2 positions[6] = vec2[6](
|
||
|
vec2(-1.0, -1.0),
|
||
|
vec2( 1.0, -1.0),
|
||
|
vec2(-1.0, 1.0),
|
||
|
vec2(-1.0, 1.0),
|
||
|
vec2( 1.0, -1.0),
|
||
|
vec2( 1.0, 1.0)
|
||
|
);
|
||
|
|
||
|
gl_Position = vec4(positions[gl_VertexID], 0.0, 1.0);
|
||
|
|
||
|
// Calculate texture coordinates for cubemap
|
||
|
vec2 texCoord = positions[gl_VertexID] * 0.5 + 0.5;
|
||
|
TexCoords = cubemapCoord(texCoord, face);
|
||
|
}
|