This commit is contained in:
2022-08-14 19:19:36 +00:00
parent b0d2757f70
commit 28c69ff62f
27 changed files with 900 additions and 1117 deletions

View File

@@ -0,0 +1,12 @@
#version 330 core
out vec4 FragColor;
in vec3 FragPos;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{
FragColor = texture(texture_diffuse1, TexCoords);
}

View File

@@ -0,0 +1,99 @@
#version 330 core
out vec4 FragColor;
struct Light {
vec3 direction;
vec3 color;
};
struct PLight {
vec3 position;
vec3 color;
float constant;
float linear;
float quadratic;
};
struct SLight {
vec3 position;
vec3 direction;
float cutOff;
float outerCutOff;
};
uniform vec3 objectColor;
uniform vec3 lightColor;
uniform vec3 lightPos;
uniform vec3 viewPos;
uniform sampler2D diffuseTex;
uniform sampler2D specTex;
uniform float shininess;
uniform Light light;
uniform PLight plight;
uniform SLight slight;
in vec3 Normal;
in vec3 FragPos;
in vec2 TexCoords;
float near = 0.1;
float far = 100.0;
float LinearizeDepth(float depth)
{
float z = depth * 2.0 - 1.0; // back to NDC
return (2.0 * near * far) / (far + near - z * (far - near));
}
// void main()
// {
// float depth = LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration
// FragColor = vec4(vec3(depth), 1.0);
// }
void main()
{
//vec3 dirDir = normalize(-Directional.direction);
float ambientStrength = 1.f;
vec3 ambient = ambientStrength * vec3(texture(diffuseTex, TexCoords));
// vec3 norm = normalize(Normal);
// vec3 diffuse;
// Directional
//vec3 lightDir = normalize(-light.direction);
// Point
// float distance = length(plight.position - FragPos);
// float attenuation = 1.f / (plight.constant + plight.linear * distance + plight.quadratic * (distance * distance));
// vec3 lightDir = normalize(lightPos - FragPos);
// float diff = max(dot(norm, lightDir), 0.f);
//diffuse = diff * lightColor * vec3(texture(diffuseTex, TexCoords)) * attenuation;
// Spot
// lightDir = normalize(slight.position - FragPos);
// float theta = dot(lightDir, normalize(-slight.direction));
// float epsilon = slight.cutOff - slight.outerCutOff;
// float intensity = clamp((theta - slight.outerCutOff) / epsilon, 0.f, 1.f);
// diffuse = lightColor * diff * vec3(texture(diffuseTex, TexCoords)) * intensity;
// float specularStrength = 0.5f;
// vec3 viewDir = normalize(viewPos - FragPos);
// vec3 reflectDir = reflect(-lightDir, norm);
// float spec = pow(max(dot(viewDir, reflectDir), 0.f), 32);
// vec3 specular = specularStrength * spec * lightColor * texture(specTex, TexCoords).rgb;
// if(texture(specTex, TexCoords).r < 0.1f)
// discard;
//vec3 result = (ambient + diffuse + specular) * objectColor;
FragColor = vec4(ambient, 1.f);
}

View File

@@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) out vec4 color;
in vec3 vcolor;
in vec3 FragPos;
void main(void)
{
color = vec4(vcolor, 1.f);
}

View File

@@ -0,0 +1,21 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
out vec3 vcolor;
uniform mat4 model;
void main()
{
vec3 m = aPos;
vcolor.r = m.r / 1.f;
vcolor.g = m.g / 1.f;
vcolor.b = m.b / 1.f;
gl_Position = projection * view * model * (vec4(m, 1.f));
}

View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(1.0f); // set alle 4 vector values to 1.0
}

View File

@@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
}

View File

@@ -0,0 +1,185 @@
#version 330 core
out vec4 FragColor;
struct Light {
vec3 direction;
vec3 color;
float strength;
};
struct PLight {
vec3 position;
float constant;
float linear;
float quadratic;
vec3 color;
float strength;
};
struct SpotLight {
vec3 position;
vec3 direction;
vec3 color;
float strength;
float cutoff;
float outerCutoff;
float distance;
float constant;
float linear;
float quadratic;
};
in vec3 FragPos;
in vec2 TexCoords;
in vec4 FragPosLightSpace;
in mat3 TBN;
//in vec3 TangentLightPos;
in vec3 TangentViewPos;
in vec3 TangentFragPos;
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_normal1;
uniform sampler2D shadowMap;
uniform Light dirLight;
uniform vec3 viewPos;
vec3 norm;
vec3 viewDir;
#define NR_POINT_LIGHTS 1
uniform PLight pointLights[NR_POINT_LIGHTS];
uniform SpotLight spotLight;
float ShadowCalculation(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir) {
// perform perspective divide
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
// transform to [0,1] range
projCoords = projCoords * 0.5 + 0.5;
// get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
float closestDepth = texture(shadowMap, projCoords.xy).r;
// get depth of current fragment from light's perspective
float currentDepth = projCoords.z;
// calculate bias (based on depth map resolution and slope)
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
// check whether current frag pos is in shadow
// float shadow = currentDepth - bias > closest Depth ? 1.0 : 0.0;
// PCF
float shadow = 0.0;
vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
for(int x = -1; x <= 1; ++x)
{
for(int y = -1; y <= 1; ++y)
{
float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
}
shadow /= 9.0;
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
if(projCoords.z > 1.0)
shadow = 0.0;
return shadow;
}
vec3 CalcDirLight(Light light) {
vec3 lightDir = TBN * normalize(-light.direction);
float lightStrength = 3.f;
vec3 lightColor = vec3(1.f);
// diffuse shading
float diff = max(dot(norm, lightDir), 0.f);
// specular shading
float specularStrength = 0.5f;
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir); // Use this instead of reflectDir?
float spec = pow(max(dot(viewDir, halfwayDir), 0.0), 32.f) * specularStrength; // 32.f is "shininess"
float shadow = ShadowCalculation(FragPosLightSpace, norm, lightDir);
// combine results
return light.strength * (diff + spec) * (1.f-shadow) * light.color;
}
vec3 CalcPointLight(PLight light) {
vec3 tbnPos = TBN * light.position;
vec3 lightDir = normalize(tbnPos - TangentFragPos);
// Diffuse
float diff = max(dot(norm, lightDir), 0.f);
// specular
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(viewDir, halfwayDir), 0.f), 32.f);
// Attenuation
float distance = length(light.position - TangentFragPos);
float attenuation = 1.f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
return light.color * attenuation * light.strength * (diff + spec);
}
vec3 CalcSpotLight(SpotLight light) {
vec3 tbnPos = TBN * light.position;
vec3 tbnDir = TBN * light.direction;
vec3 lightDir = normalize(tbnPos - TangentFragPos);
float diff = max(dot(norm, lightDir), 0.f);
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(viewDir, halfwayDir), 0.f), 32.f);
float theta = dot(lightDir, normalize(-tbnDir));
float epsilon = light.cutoff - light.outerCutoff;
float intensity = clamp((theta - light.outerCutoff) / epsilon, 0.f, 1.f);
float distance = length(light.position - FragPos);
float attenuation = 1.f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
return light.color * light.strength * (diff + spec) * intensity * attenuation;
}
void main()
{
vec4 model = texture(texture_diffuse1, TexCoords);
if (model.a <= 0.1f)
discard;
vec3 albedo = model.rgb;
norm = texture(texture_normal1, TexCoords).rgb;
norm = normalize(norm * 2.f - 1.f);
//vec3 norm = normalize(TangentViewPos);
viewDir = normalize(TangentViewPos - TangentFragPos);
// Ambient doesn't change
float ambientStrength = 0.3f;
vec3 ambientColor = vec3(1.f);
vec3 ambient = ambientStrength * ambientColor;
// Per light calculation
// Directional
vec3 result = CalcDirLight(dirLight);
result += ambient;
// Point
for (int i = 0; i < NR_POINT_LIGHTS; i++)
result += CalcPointLight(pointLights[i]);
result += CalcSpotLight(spotLight);
FragColor = vec4(result * model.rgb, 1.f);
}

View File

@@ -0,0 +1,68 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
layout (location = 5) in ivec4 boneIds;
layout (location = 6) in vec4 weights;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
//out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;
//out vec3 TangentLightPos;
out vec3 TangentViewPos;
out vec3 TangentFragPos;
out vec4 FragPosLightSpace;
out mat3 TBN;
uniform mat4 model;
uniform mat4 lightSpaceMatrix;
uniform vec3 viewPos;
const int MAX_BONES = 100;
const int MAX_BONE_INFLUENCE = 4;
uniform mat4 finalBonesMatrices[MAX_BONES];
void main()
{
vec4 totalPosition = vec4(0.f);
for (int i = 0; i < MAX_BONE_INFLUENCE; i++) {
if (boneIds[i] == -1)
continue;
if (boneIds[i] >= 4) {
totalPosition = vec4(aPos, 1.f);
break;
}
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos, 1.f);
totalPosition += localPosition * weights[i];
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
}
FragPos = vec3(model * vec4(aPos, 1.f));
TexCoords = aTexCoords;
mat3 normalMatrix = transpose(inverse(mat3(model)));
vec3 T = normalize(normalMatrix * aTangent);
vec3 N = normalize(normalMatrix * aNormal);
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N, T);
TBN = transpose(mat3(T, B, N));
// TangentLightPos = TBN * lightPos;
TangentViewPos = TBN * viewPos;
TangentFragPos = TBN * FragPos;
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.f);
gl_Position = projection * view * model * totalPosition;
}

View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(0.92f, 0.86f, 0.68f, 1.0f);
}

View File

@@ -0,0 +1,15 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
uniform mat4 model;
void main()
{
gl_Position = projection * view * model * vec4(aPos + (aNormal * 2.f), 1.f);
}

View File

@@ -0,0 +1,6 @@
#version 330 core
void main()
{
// gl_FragDepth = gl_FragCoord.z;
}

View File

@@ -0,0 +1,10 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}

View File

@@ -0,0 +1,19 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 2) in vec2 aTexCoords;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
out vec2 TexCoords;
uniform mat4 model;
void main()
{
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos, 1.f);
}

View File

@@ -0,0 +1,11 @@
#version 330 core
out vec4 FragColor;
in vec3 TexCoords;
uniform samplerCube skybox;
void main()
{
FragColor = texture(skybox, TexCoords);
}

View File

@@ -0,0 +1,18 @@
#version 330 core
layout (location = 0) in vec3 aPos;
out vec3 TexCoords;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
uniform mat4 skyview;
void main()
{
TexCoords = aPos;
vec4 pos = projection * skyview * vec4(aPos, 1.0);
gl_Position = pos.xyww;
}

View File

@@ -0,0 +1,22 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.f));
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos, 1.0f); // see how we directly give a vec3 to vec4's constructor
}