diff options
Diffstat (limited to 'src/extras/shaders/gl3/light.inc.frag')
-rw-r--r-- | src/extras/shaders/gl3/light.inc.frag | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/extras/shaders/gl3/light.inc.frag b/src/extras/shaders/gl3/light.inc.frag index c4c08c7d9..f588acce3 100644 --- a/src/extras/shaders/gl3/light.inc.frag +++ b/src/extras/shaders/gl3/light.inc.frag @@ -26,7 +26,7 @@ uniform int envLightCount = 0; void adsModel(const in vec3 worldPos, const in vec3 worldNormal, - const in vec3 worldEye, + const in vec3 worldView, const in float shininess, out vec3 diffuseColor, out vec3 specularColor) @@ -36,7 +36,6 @@ void adsModel(const in vec3 worldPos, // We perform all work in world space vec3 n = normalize(worldNormal); - vec3 v = normalize(worldEye - worldPos); vec3 s = vec3(0.0); for (int i = 0; i < lightCount; ++i) { @@ -84,7 +83,7 @@ void adsModel(const in vec3 worldPos, if (diffuse > 0.0 && shininess > 0.0) { float normFactor = (shininess + 2.0) / 2.0; vec3 r = reflect(-s, n); // Reflection direction in world space - specular = normFactor * pow(max(dot(r, v), 0.0), shininess); + specular = normFactor * pow(max(dot(r, worldView), 0.0), shininess); } // Accumulate the diffuse and specular contributions @@ -92,3 +91,22 @@ void adsModel(const in vec3 worldPos, specularColor += att * lights[i].intensity * specular * lights[i].color; } } + +vec4 phongFunction(const in vec4 ambient, + const in vec4 diffuse, + const in vec4 specular, + const in float shininess, + const in vec3 worldPosition, + const in vec3 worldView, + const in vec3 worldNormal) +{ + // Calculate the lighting model, keeping the specular component separate + vec3 diffuseColor, specularColor; + adsModel(worldPosition, worldNormal, worldView, shininess, diffuseColor, specularColor); + + // Combine spec with ambient+diffuse for final fragment color + vec3 color = (ambient.rgb + diffuseColor) * diffuse.rgb + + specularColor * specular.rgb; + + return vec4(color, diffuse.a); +} |