This commit is contained in:
will
2026-04-18 21:15:28 +01:00
parent 65771dbcf8
commit 2411571ad0
38 changed files with 12311 additions and 273 deletions

View File

@@ -5,32 +5,24 @@ in vec3 Color;
out vec4 FragColor;
uniform vec3 uLightPos;
uniform vec3 uSunDir;
uniform vec3 uSunColor;
uniform vec3 uSkyColor;
uniform vec3 uGroundColor;
uniform vec3 uViewPos;
uniform vec3 uLightColor;
uniform float uAmbientStrength;
uniform float uSpecularStrength;
uniform float uShininess;
void main() {
// Normalize the normal vector
vec3 norm = normalize(Normal);
// Ambient lighting
vec3 ambient = uAmbientStrength * uLightColor;
// Diffuse lighting
vec3 lightDir = normalize(uLightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diff * uLightColor;
// Specular lighting
vec3 viewDir = normalize(uViewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), uShininess);
vec3 specular = uSpecularStrength * spec * uLightColor;
// Combine results
vec3 result = (ambient + diffuse + specular) * Color;
vec3 N = normalize(Normal);
float up = 0.5 + 0.5 * N.y;
vec3 ambient = mix(uGroundColor, uSkyColor, up);
float NdotL = max(dot(N, uSunDir), 0.0);
vec3 diffuse = NdotL * uSunColor;
vec3 V = normalize(uViewPos - FragPos);
vec3 H = normalize(uSunDir + V);
float spec = pow(max(dot(N, H), 0.0), uShininess) * (NdotL > 0.0 ? 1.0 : 0.0);
vec3 specular = uSpecularStrength * spec * uSunColor;
vec3 result = (ambient + diffuse) * Color + specular;
FragColor = vec4(result, 1.0);
}