VoxelEngine/Objects/Cuboid/cuboid_geometry.glsl
2020-07-25 15:03:05 +02:00

355 lines
No EOL
17 KiB
GLSL

#version 410
layout(points) in;
layout(triangle_strip,max_vertices=24) out;
uniform mat4 projModelViewMatrix;
uniform mat3 rotMatrix;
uniform mat4 lightProjModelViewMatrix[7];
uniform int numLights;
uniform float width;
uniform float height;
uniform float near;
uniform float far;
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;
layout(location = 3) out vec4 lightviewpos[3];
void main(){
//hinten
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,-1));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//vorne
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,0,1));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//oben
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,1,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//unten
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(0,-1,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//links
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(-1,0,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
//rechts
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
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;
colorout = colorgeo[0];
normal = normalize(rotMatrix * vec3(1,0,0));
pos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
}