mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Code and content re-work: advanced OpenGL and advanced lighting.
This commit is contained in:
@@ -40,22 +40,22 @@ void main()
|
||||
vec3 color = texture(diffuseTexture, fs_in.TexCoords).rgb;
|
||||
vec3 normal = normalize(fs_in.Normal);
|
||||
vec3 lightColor = vec3(0.3);
|
||||
// Ambient
|
||||
// ambient
|
||||
vec3 ambient = 0.3 * color;
|
||||
// Diffuse
|
||||
// diffuse
|
||||
vec3 lightDir = normalize(lightPos - fs_in.FragPos);
|
||||
float diff = max(dot(lightDir, normal), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
// Specular
|
||||
// specular
|
||||
vec3 viewDir = normalize(viewPos - fs_in.FragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, normal);
|
||||
float spec = 0.0;
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
spec = pow(max(dot(normal, halfwayDir), 0.0), 64.0);
|
||||
vec3 specular = spec * lightColor;
|
||||
// Calculate shadow
|
||||
// calculate shadow
|
||||
float shadow = shadows ? ShadowCalculation(fs_in.FragPos) : 0.0;
|
||||
vec3 lighting = (ambient + (1.0 - shadow) * (diffuse + specular)) * color;
|
||||
|
||||
FragColor = vec4(lighting, 1.0f);
|
||||
FragColor = vec4(lighting, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user