diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2017-08-02 11:17:12 +0200 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@kdab.com> | 2017-09-25 11:34:35 +0000 |
commit | bae599898a8a6c49df2e4141b7f3750efa40da50 (patch) | |
tree | 2484de0def90c91f6c2df143fb210859a6e3d8aa /src/extras | |
parent | e67119b71d1b63c5710100349fa634113e93ada2 (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')
-rw-r--r-- | src/extras/shaders/es2/light.inc.frag | 50 | ||||
-rw-r--r-- | src/extras/shaders/es2/light.inc.frag100 | 54 | ||||
-rw-r--r-- | src/extras/shaders/es2/pervertexcolor.frag | 5 | ||||
-rw-r--r-- | src/extras/shaders/gl3/light.inc.frag | 55 | ||||
-rw-r--r-- | src/extras/shaders/gl3/pervertexcolor.frag | 5 |
5 files changed, 8 insertions, 161 deletions
diff --git a/src/extras/shaders/es2/light.inc.frag b/src/extras/shaders/es2/light.inc.frag index aec04139d..d19af6e2a 100644 --- a/src/extras/shaders/es2/light.inc.frag +++ b/src/extras/shaders/es2/light.inc.frag @@ -74,53 +74,3 @@ void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 specularColor += att * light.intensity * specular * light.color; } } - -void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffuseColor) -{ - diffuseColor = vec3(0.0); - - FP vec3 n = normalize( vnormal ); - - FP vec3 s; - Light light; - for (int i = 0; i < MAX_LIGHTS; ++i) { - if (i >= lightCount) // Make brcm happy with the for loop - break; - if (i == 0) - light = lights[0]; - else if (i == 1) - light = lights[1]; - else if (i == 2) - light = lights[2]; - else if (i == 3) - light = lights[3]; - else if (i == 4) - light = lights[4]; - else if (i == 5) - light = lights[5]; - else if (i == 6) - light = lights[6]; - else if (i == 7) - light = lights[7]; - - FP float att = 1.0; - if ( light.type != TYPE_DIRECTIONAL ) { - s = light.position - vpos; - if (length( light.attenuation ) != 0.0) { - FP float dist = length(s); - att = 1.0 / (light.attenuation.x + light.attenuation.y * dist + light.attenuation.z * dist * dist); - } - s = normalize( s ); - if ( light.type == TYPE_SPOT ) { - if ( degrees(acos(dot(-s, normalize(light.direction))) ) > light.cutOffAngle) - att = 0.0; - } - } else { - s = normalize( -light.direction ); - } - - FP float diffuse = max( dot( s, n ), 0.0 ); - - diffuseColor += att * light.intensity * diffuse * light.color; - } -} diff --git a/src/extras/shaders/es2/light.inc.frag100 b/src/extras/shaders/es2/light.inc.frag100 index 6c6f6a259..24766168b 100644 --- a/src/extras/shaders/es2/light.inc.frag100 +++ b/src/extras/shaders/es2/light.inc.frag100 @@ -87,57 +87,3 @@ void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 diffuseColor += att * lights[1].intensity * diffuse * lights[1].color; specularColor += att * specular; } - -void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffuseColor) -{ - diffuseColor = vec3(0.0); - - FP vec3 n = normalize( vnormal ); - - // 0 - if (lightCount < 1) - return; - FP vec3 s; - FP float att = 1.0; - if ( lights[0].type != TYPE_DIRECTIONAL ) { - s = lights[0].position - vpos; - if (length( lights[0].attenuation ) != 0.0) { - FP float dist = length(s); - att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist); - } - s = normalize( s ); - if ( lights[0].type == TYPE_SPOT ) { - if ( degrees(acos(dot(-s, normalize(lights[0].direction))) ) > lights[0].cutOffAngle) - att = 0.0; - } - } else { - s = normalize( -lights[0].direction ); - } - - FP float diffuse = max( dot( s, n ), 0.0 ); - - diffuseColor += att * lights[0].intensity * diffuse * lights[0].color; - - // 1 - if (lightCount < 2) - return; - att = 1.0; - if ( lights[1].type != TYPE_DIRECTIONAL ) { - s = lights[1].position - vpos; - if (length( lights[1].attenuation ) != 0.0) { - FP float dist = length(s); - att = 1.0 / (lights[1].attenuation.x + lights[1].attenuation.y * dist + lights[1].attenuation.z * dist * dist); - } - s = normalize( s ); - if ( lights[1].type == TYPE_SPOT ) { - if ( degrees(acos(dot(-s, normalize(lights[1].direction))) ) > lights[1].cutOffAngle) - att = 0.0; - } - } else { - s = normalize( -lights[1].direction ); - } - - diffuse = max( dot( s, n ), 0.0 ); - - diffuseColor += att * lights[1].intensity * diffuse * lights[1].color; -} diff --git a/src/extras/shaders/es2/pervertexcolor.frag b/src/extras/shaders/es2/pervertexcolor.frag index ab429d942..186e93dc9 100644 --- a/src/extras/shaders/es2/pervertexcolor.frag +++ b/src/extras/shaders/es2/pervertexcolor.frag @@ -4,11 +4,14 @@ varying FP vec3 worldPosition; varying FP vec3 worldNormal; varying FP vec3 color; +uniform FP vec3 eyePosition; + #pragma include light.inc.frag void main() { FP vec3 diffuseColor; - adModel(worldPosition, worldNormal, diffuseColor); + FP vec3 specularColor; + adsModel(worldPosition, worldNormal, eyePosition, 0.0, diffuseColor, specularColor); gl_FragColor = vec4( color + color * diffuseColor, 1.0 ); } 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 ); } |