Files
OpenSpace/shaders/singlepassraycaster.gs
T

53 lines
1.4 KiB
GLSL

#version 400 core
layout(points) in;
layout(triangle_strip, max_vertices = 24) out;
in vec4 vPosition[1];
uniform mat4 modelViewProjection;
// uniform mat4 ProjectionMatrix;
// uniform mat4 ViewMatrix;
// uniform mat4 Modelview;
vec4 objCube[8]; // Object space coordinate of cube corner
vec4 ndcCube[8]; // Normalized device coordinate of cube corner
ivec4 faces[6]; // Vertex indices of the cube faces
void emit_vert(int vert)
{
gl_Position = ndcCube[vert];
EmitVertex();
}
void emit_face(int face)
{
emit_vert(faces[face][1]); emit_vert(faces[face][0]);
emit_vert(faces[face][3]); emit_vert(faces[face][2]);
EndPrimitive();
}
void main()
{
faces[0] = ivec4(0,1,3,2); faces[1] = ivec4(5,4,6,7);
faces[2] = ivec4(4,5,0,1); faces[3] = ivec4(3,2,7,6);
faces[4] = ivec4(0,3,4,7); faces[5] = ivec4(2,1,6,5);
vec4 P = vPosition[0];
vec4 I = vec4(1,0,0,0);
vec4 J = vec4(0,1,0,0);
vec4 K = vec4(0,0,1,0);
objCube[0] = P+K+I+J; objCube[1] = P+K+I-J;
objCube[2] = P+K-I-J; objCube[3] = P+K-I+J;
objCube[4] = P-K+I+J; objCube[5] = P-K+I-J;
objCube[6] = P-K-I-J; objCube[7] = P-K-I+J;
// Transform the corners of the box:
for (int vert = 0; vert < 8; vert++)
ndcCube[vert] = modelViewProjection * objCube[vert];
// Emit the six faces:
for (int face = 0; face < 6; face++)
emit_face(face);
}