VoxelEngine/Objects/Cuboid/cuboid_geometry.glsl

355 lines
17 KiB
Text
Raw Normal View History

2017-08-27 12:51:26 +02:00
#version 410
layout(points) in;
layout(triangle_strip,max_vertices=24) out;
uniform mat4 projModelViewMatrix;
uniform mat3 rotMatrix;
2020-07-25 15:03:05 +02:00
uniform mat4 lightProjModelViewMatrix[7];
uniform int numLights;
uniform float width;
uniform float height;
uniform float near;
uniform float far;
2017-08-27 12:51:26 +02:00
layout(location = 0) in vec3 colorgeo[1];
layout(location = 1) in vec3 size[1];
layout(location = 0) out vec3 colorout;
layout(location = 1) out vec3 normal;
layout(location = 2) out vec3 pos;
2020-07-25 15:03:05 +02:00
layout(location = 3) out vec4 lightviewpos[3];
2017-08-27 12:51:26 +02:00
void main(){
//hinten
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//vorne
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//oben
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//unten
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//links
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(-size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//rechts
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,-size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
2020-07-25 15:03:05 +02:00
gl_Position = (gl_in[0].gl_Position + vec4(rotMatrix * vec3(size[0].x,size[0].y,-size[0].z),0));
for(int i = 0;i < numLights; i++){
lightviewpos[i] = lightProjModelViewMatrix[i] * gl_Position;
lightviewpos[i] = lightviewpos[i] / lightviewpos[i].w;
lightviewpos[i] = vec4(lightviewpos[i].x/2.0 + 0.5,lightviewpos[i].y/2.0 + 0.5,lightviewpos[i].z/2.0 + 0.5,lightviewpos[i].w);
lightviewpos[i].z = (2.0 * near) / (far + near - lightviewpos[i].z * (far - near));
}
gl_Position = projModelViewMatrix * gl_Position;
2017-08-27 12:51:26 +02:00
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
}