1
0
Fork 0
fgdata/Shaders/HDR/quad_cubemap.vert

41 lines
1.2 KiB
GLSL
Raw Normal View History

2021-04-10 09:14:16 +00:00
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multitexcoord0;
2021-04-10 09:14:16 +00:00
out vec3 cubemap_coord;
2021-04-10 09:14:16 +00:00
uniform mat4 osg_ModelViewProjectionMatrix;
uniform int fg_CubemapFace;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
vec2 texcoord = multitexcoord0.xy * 2.0 - 1.0;
2021-04-10 09:14:16 +00:00
// Map the quad texture coordinates to a direction vector to sample
// the cubemap. This assumes that we are using the weird left-handed
// orientations given by the OpenGL spec.
// See https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation
switch(fg_CubemapFace) {
case 0: // +X
cubemap_coord = vec3(1.0, -texcoord.y, -texcoord.x);
2021-04-10 09:14:16 +00:00
break;
case 1: // -X
cubemap_coord = vec3(-1.0, -texcoord.y, texcoord.x);
2021-04-10 09:14:16 +00:00
break;
case 2: // +Y
cubemap_coord = vec3(texcoord.x, 1.0, texcoord.y);
2021-04-10 09:14:16 +00:00
break;
case 3: // -Y
cubemap_coord = vec3(texcoord.x, -1.0, -texcoord.y);
2021-04-10 09:14:16 +00:00
break;
case 4: // +Z
cubemap_coord = vec3(texcoord.x, -texcoord.y, 1.0);
2021-04-10 09:14:16 +00:00
break;
case 5: // -Z
cubemap_coord = vec3(-texcoord.x, -texcoord.y, -1.0);
2021-04-10 09:14:16 +00:00
break;
}
}