attenuation!
This commit is contained in:
@@ -18,10 +18,13 @@ float dither(vec2 uv) {
|
||||
|
||||
const vec3 objectColor = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 lightColor = vec3(0.5, 0.5, 0.5);
|
||||
|
||||
const float ambientStrength = 0.1;
|
||||
const float specularStrength = 0.5;
|
||||
const float shininess = 32.0;
|
||||
|
||||
const float la = 0.1, lb = 0.01, lc = 0.001;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(normal);
|
||||
@@ -31,7 +34,10 @@ void main()
|
||||
vec3 result = ambient;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
vec3 lightDir = normalize(lightPositions[i] - worldPositions);
|
||||
vec3 lightVector = lightPositions[i] - worldPositions;
|
||||
vec3 lightDir = normalize(lightVector);
|
||||
float d = length(lightVector);
|
||||
float attenuation = 1.0 / (la + d * lb + d * d * lc);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
@@ -39,7 +45,7 @@ void main()
|
||||
float spec = pow(max(dot(norm, halfwayDir), 0.0), shininess);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
result += (diffuse + specular) * objectColor;
|
||||
result += attenuation * (diffuse + specular) * objectColor;
|
||||
}
|
||||
|
||||
color = vec4(result, 1.0);
|
||||
|
||||
Reference in New Issue
Block a user