Attribute-less-rendering-based cube map filitering GLSL shader code template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2018, Benjamin "BeRo" Rosseaux (benjamin@rosseaux.de) - License: CC0 | |
#version 330 | |
layout(location = 0) out vec4 oOutput; | |
in vec2 vTexCoord; | |
flat in int vFaceIndex; | |
vec3 getCubeMapDirection(in vec2 uv, | |
in int faceIndex){ | |
vec3 zDir = vec3(ivec3((faceIndex <= 1) ? 1 : 0, | |
(faceIndex & 2) >> 1, | |
(faceIndex & 4) >> 2)) * | |
(((faceIndex & 1) == 1) ? -1.0 : 1.0), | |
yDir = (faceIndex == 2) | |
? vec3(0.0, 0.0, 1.0) | |
: ((faceIndex == 3) | |
? vec3(0.0, 0.0, -1.0) | |
: vec3(0.0, -1.0, 0.0)), | |
xDir = cross(zDir, yDir); | |
return normalize((mix(-1.0, 1.0, uv.x) * xDir) + | |
(mix(-1.0, 1.0, uv.y) * yDir) + | |
zDir); | |
} | |
void main(){ | |
vec3 direction = getCubeMapDirection(vTexCoord, vFaceIndex); | |
// put your stuff here | |
oOutput = vec4(direction, 1.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2018, Benjamin "BeRo" Rosseaux (benjamin@rosseaux.de) - License: CC0 | |
#version 330 | |
#extension GL_AMD_vertex_shader_layer : enable | |
out vec2 vTexCoord; | |
flat out int vFaceIndex; | |
void main(){ | |
// For 18 vertices (6x attribute-less-rendered "full-screen" triangles) | |
int vertexID = int(gl_VertexID), | |
vertexIndex = vertexID % 3, | |
faceIndex = vertexID / 3; | |
vec2 uv = vec2(ivec2(vertexIndex >> 1, vertexIndex & 1)); | |
vTexCoord = uv * 2.0; | |
vFaceIndex = faceIndex; | |
gl_Position = vec4(vec3((uv * 4.0) - vec2(1.0), 0.0), 1.0); | |
gl_Layer = faceIndex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment