summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-04 14:47:29 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-04 15:55:41 +0000
commit464cff07bfc365e51e7c0130132aa9834d6c06d6 (patch)
tree84bf63400e86ec9f42ce2f706ee9091215cf1ce3 /src
parent0346752609b79671f85589639a890d5b04e1db11 (diff)
Fix directional lights
The interpretation of lightDir was different for point and directional lights: it was surface-to-light for point lights, but light-to-surface for directional. Fix this by getting rid of lightDir and instead setting up s (surface-to-light) correctly. Change-Id: I0bc6947dc94622d7a95f55fd65b3baf43fd11528 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/shaders/es2/light.inc.frag30
-rw-r--r--src/render/shaders/gl3/light.inc.frag33
2 files changed, 33 insertions, 30 deletions
diff --git a/src/render/shaders/es2/light.inc.frag b/src/render/shaders/es2/light.inc.frag
index 516d701f1..a42e573a4 100644
--- a/src/render/shaders/es2/light.inc.frag
+++ b/src/render/shaders/es2/light.inc.frag
@@ -20,17 +20,17 @@ void adsModelNormalMapped(const in FP vec3 vpos, const in FP vec3 vnormal, const
FP vec3 n = normalize( vnormal );
// TODO dynamic indexing may not be supported with GLSL 1.00 so take only the first light into account
- FP vec3 lightDir = lights[0].direction;
+ FP vec3 s = -lights[0].direction;
FP float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[0].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[0].position - vpos;
if (length( lights[0].attenuation ) != 0.0) {
- FP float dist = length(lightDir);
+ FP float dist = length(s);
att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
}
}
- FP vec3 s = normalize( tangentMatrix * lightDir );
+ s = normalize( tangentMatrix * s );
FP float diffuse = max( dot( s, n ), 0.0 );
FP float specular = 0.0;
@@ -54,17 +54,17 @@ void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3
FP vec3 n = normalize( vnormal );
// TODO dynamic indexing may not be supported with GLSL 1.00 so take only the first light into account
- FP vec3 lightDir = lights[0].direction;
+ FP vec3 s = -lights[0].direction;
FP float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[0].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[0].position - vpos;
if (length( lights[0].attenuation ) != 0.0) {
- FP float dist = length(lightDir);
+ FP float dist = length(s);
att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
}
}
- FP vec3 s = normalize( lightDir );
+ s = normalize( s );
FP float diffuse = max( dot( s, n ), 0.0 );
FP float specular = 0.0;
@@ -86,17 +86,17 @@ void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffus
FP vec3 n = normalize( vnormal );
// TODO dynamic indexing may not be supported with GLSL 1.00 so take only the first light into account
- FP vec3 lightDir = lights[0].direction;
+ FP vec3 s = -lights[0].direction;
FP float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[0].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[0].position - vpos;
if (length( lights[0].attenuation ) != 0.0) {
- FP float dist = length(lightDir);
+ FP float dist = length(s);
att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
}
}
- FP vec3 s = normalize( lightDir );
+ s = normalize( s );
FP float diffuse = max( dot( s, n ), 0.0 );
diffuseColor += att * lights[0].intensity * diffuse * lights[0].color;
diff --git a/src/render/shaders/gl3/light.inc.frag b/src/render/shaders/gl3/light.inc.frag
index 6d4b8b68f..e9dc021c4 100644
--- a/src/render/shaders/gl3/light.inc.frag
+++ b/src/render/shaders/gl3/light.inc.frag
@@ -20,18 +20,19 @@ void adsModelNormalMapped(const in vec3 vpos, const in vec3 vnormal, const in ve
vec3 n = normalize( vnormal );
int i;
+ vec3 s;
for (i = 0; i < lightCount; ++i) {
- vec3 lightDir = lights[i].direction;
+ s = -lights[i].direction;
float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[i].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[i].position - vpos;
if (length( lights[i].attenuation ) != 0.0) {
- float dist = length(lightDir);
+ float dist = length(s);
att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * dist * dist);
}
}
- vec3 s = normalize( tangentMatrix * lightDir );
+ s = normalize( tangentMatrix * s );
float diffuse = max( dot( s, n ), 0.0 );
float specular = 0.0;
@@ -56,18 +57,19 @@ void adsModel(const in vec3 vpos, const in vec3 vnormal, const in vec3 eye, cons
vec3 n = normalize( vnormal );
int i;
+ vec3 s;
for (i = 0; i < lightCount; ++i) {
- vec3 lightDir = lights[i].direction;
+ s = -lights[i].direction;
float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[i].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[i].position - vpos;
if (length( lights[i].attenuation ) != 0.0) {
- float dist = length(lightDir);
+ float dist = length(s);
att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * dist * dist);
}
}
- vec3 s = normalize( lightDir );
+ s = normalize( s );
float diffuse = max( dot( s, n ), 0.0 );
float specular = 0.0;
@@ -90,18 +92,19 @@ void adModel(const in vec3 vpos, const in vec3 vnormal, out vec3 diffuseColor)
vec3 n = normalize( vnormal );
int i;
+ vec3 s;
for (i = 0; i < lightCount; ++i) {
- vec3 lightDir = lights[i].direction;
+ s = -lights[i].direction;
float att = 1.0;
- if (length( lightDir ) == 0.0) {
- lightDir = lights[i].position - vpos;
+ if (length( s ) == 0.0) {
+ s = lights[i].position - vpos;
if (length( lights[i].attenuation ) != 0.0) {
- float dist = length(lightDir);
+ float dist = length(s);
att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * dist * dist);
}
}
- vec3 s = normalize( lightDir );
+ s = normalize( s );
float diffuse = max( dot( s, n ), 0.0 );
diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;