From 89a30182211c8a2a379494ecd63a08158d139a5e Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 19 Nov 2014 00:46:51 +0100 Subject: [PATCH] Clamping diffuse color for more realistic lighting. --- Shader/phong.fsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 7776aad..938c5be 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -29,8 +29,8 @@ void main() if(length(directionalLightVector)>0.0f) { vec3 directionalVector = normalize(directionalLightVector); - diffuseColor += dot(normalize(vNormal), directionalVector) - *diffuseFactor*directionalIntensity*directionalColor; + diffuseColor += clamp(dot(normalize(vNormal), directionalVector) + *diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0); vec3 cameraVector = normalize(camera - vec3(fragPosition)); specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) *specularFactor*directionalIntensity*directionalColor; @@ -41,8 +41,8 @@ void main() if (distance > 0.001f) { vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition)); float intensity = (lightIntensities[i])/(distance); - diffuseColor += dot(normalize(vNormal), lightVector) - *diffuseFactor*intensity*lightColors[i]; + diffuseColor += clamp(dot(normalize(vNormal), lightVector) + *diffuseFactor*intensity*lightColors[i], 0.0, 1.0); vec3 cameraVector = normalize(camera - vec3(fragPosition)); specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) *specularFactor*intensity*lightColors[i];