added all project files

This commit is contained in:
Hannes
2018-03-27 20:27:54 +02:00
parent 528797d9de
commit 2fffd4b7c4
53 changed files with 2064 additions and 0 deletions

12
shaders/cubemap.fs.glsl Normal file
View File

@@ -0,0 +1,12 @@
#version 330
in vec3 texCoord;
out vec4 outputColor;
uniform samplerCube cubemap;
void main()
{
outputColor = texture(cubemap, texCoord);
}

14
shaders/cubemap.vs.glsl Normal file
View File

@@ -0,0 +1,14 @@
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 texturePos;
out vec3 texCoord;
uniform mat4 CameraMatrix;
uniform mat4 ModelMatrix;
void main() {
gl_Position = CameraMatrix * ModelMatrix * vec4(position, 1.0);
texCoord = vec3(texturePos.x, -texturePos.y, texturePos.z);
}

63
shaders/object.fs.glsl Normal file
View File

@@ -0,0 +1,63 @@
#version 400
struct LightSource {
//int type; so far only point lights supported
int enabled;
vec3 position;
};
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
int shininess;
};
in vec2 fragTexCoord;
in vec3 fragNormal;
in vec3 fragPos;
out vec4 outputColor;
uniform mat4 ModelMatrix;
uniform sampler2D textureSampler;
uniform Material material;
uniform vec3 EyePos;
const int MaxLigths = 10;
uniform LightSource lights[MaxLigths];
void main()
{
//calculate normal in world coordinates
mat3 normalMatrix = transpose(inverse(mat3(ModelMatrix)));
vec3 normal = normalize(normalMatrix * fragNormal);
vec3 eyeDir = normalize(EyePos - fragPos);
for(int i = 0; i < MaxLigths; ++i) {
//calculate the vector from this pixels surface to the light source
vec3 lightDir = lights[i].position - fragPos;
float attenuation = 1.0 / length(lightDir);
lightDir = normalize(lightDir);
//Diffuse
float diffuseIntensity = max(0.0, dot(normal, lightDir));
vec3 diffuseLight = attenuation * material.diffuse * diffuseIntensity;
//Specular
vec3 reflection = 2 * dot(lightDir, normal) * normal - lightDir;
float specularIntensity = max(0.0, dot(reflection, eyeDir));
specularIntensity = pow(specularIntensity, material.shininess);
vec3 specularLight = attenuation * specularIntensity * material.specular;
vec4 color = texture(textureSampler, fragTexCoord);
outputColor += lights[i].enabled * color * vec4(material.ambient + diffuseLight, 1.0) + specularLight;
}
}

20
shaders/object.vs.glsl Normal file
View File

@@ -0,0 +1,20 @@
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texturePos;
layout(location = 2) in vec3 normalVec;
out vec2 fragTexCoord;
out vec3 fragNormal;
out vec3 fragPos;
uniform mat4 ModelMatrix;
uniform mat4 CameraMatrix;
void main() {
gl_Position = CameraMatrix * ModelMatrix * vec4(position, 1.0);
fragTexCoord = texturePos;
fragNormal = normalVec;
fragPos = vec3(ModelMatrix * vec4(position, 1));
}