summaryrefslogtreecommitdiffstats
path: root/src/extras/shaders/gl3
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2017-08-02 11:17:12 +0200
committerKevin Ottens <kevin.ottens@kdab.com>2017-09-25 11:34:35 +0000
commitbae599898a8a6c49df2e4141b7f3750efa40da50 (patch)
tree2484de0def90c91f6c2df143fb210859a6e3d8aa /src/extras/shaders/gl3
parente67119b71d1b63c5710100349fa634113e93ada2 (diff)
Base PerVertexColorMaterial on adsModel
Since this was the sole user of adModel we also remove it in the process. Change-Id: Ibb79bb05c10b33e69601624ea9ad1fdf8523fdbf Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/extras/shaders/gl3')
-rw-r--r--src/extras/shaders/gl3/light.inc.frag55
-rw-r--r--src/extras/shaders/gl3/pervertexcolor.frag5
2 files changed, 4 insertions, 56 deletions
diff --git a/src/extras/shaders/gl3/light.inc.frag b/src/extras/shaders/gl3/light.inc.frag
index 1af88ba77..c4c08c7d9 100644
--- a/src/extras/shaders/gl3/light.inc.frag
+++ b/src/extras/shaders/gl3/light.inc.frag
@@ -92,58 +92,3 @@ void adsModel(const in vec3 worldPos,
specularColor += att * lights[i].intensity * specular * lights[i].color;
}
}
-
-void adModel(const in vec3 worldPos,
- const in vec3 worldNormal,
- out vec3 diffuseColor)
-{
- diffuseColor = vec3(0.0);
-
- // We perform all work in world space
- vec3 n = normalize(worldNormal);
- vec3 s = vec3(0.0);
-
- for (int i = 0; i < lightCount; ++i) {
- float att = 1.0;
- float sDotN = 0.0;
-
- if (lights[i].type != TYPE_DIRECTIONAL) {
- // Point and Spot lights
-
- // Light position is already in world space
- vec3 sUnnormalized = lights[i].position - worldPos;
- s = normalize(sUnnormalized); // Light direction
-
- // Calculate the attenuation factor
- sDotN = dot(s, n);
- if (sDotN > 0.0) {
- if (lights[i].constantAttenuation != 0.0
- || lights[i].linearAttenuation != 0.0
- || lights[i].quadraticAttenuation != 0.0) {
- float dist = length(sUnnormalized);
- att = 1.0 / (lights[i].constantAttenuation +
- lights[i].linearAttenuation * dist +
- lights[i].quadraticAttenuation * dist * dist);
- }
-
- // The light direction is in world space already
- if (lights[i].type == TYPE_SPOT) {
- // Check if fragment is inside or outside of the spot light cone
- if (degrees(acos(dot(-s, lights[i].direction))) > lights[i].cutOffAngle)
- sDotN = 0.0;
- }
- }
- } else {
- // Directional lights
- // The light direction is in world space already
- s = normalize(-lights[i].direction);
- sDotN = dot(s, n);
- }
-
- // Calculate the diffuse factor
- float diffuse = max(sDotN, 0.0);
-
- // Accumulate the diffuse contributions
- diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
- }
-}
diff --git a/src/extras/shaders/gl3/pervertexcolor.frag b/src/extras/shaders/gl3/pervertexcolor.frag
index b5ed5a33d..910efe554 100644
--- a/src/extras/shaders/gl3/pervertexcolor.frag
+++ b/src/extras/shaders/gl3/pervertexcolor.frag
@@ -6,11 +6,14 @@ in vec3 color;
out vec4 fragColor;
+uniform vec3 eyePosition;
+
#pragma include light.inc.frag
void main()
{
vec3 diffuseColor;
- adModel(worldPosition, worldNormal, diffuseColor);
+ vec3 specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, 0.0, diffuseColor, specularColor);
fragColor = vec4( color + color * diffuseColor, 1.0 );
}