diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-06-01 16:53:47 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-06-29 09:25:34 +0000 |
commit | b70cf23d8ccc09419c57d0856f47eb3019c4b22b (patch) | |
tree | b445e585067fb0fb881b44d39d5b7b9583bc1805 /tests/manual/deferred-renderer-qml/final_gl3.frag | |
parent | b0a8cd54e02c698b3dd5a01e5d43702a55d05e66 (diff) | |
download | qt3d-b70cf23d8ccc09419c57d0856f47eb3019c4b22b.tar.gz |
Fix deferred-renderer-qml
Change-Id: I4da72e96120c3afe1e555a3f89f920cd5e91e088
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/manual/deferred-renderer-qml/final_gl3.frag')
-rw-r--r-- | tests/manual/deferred-renderer-qml/final_gl3.frag | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/manual/deferred-renderer-qml/final_gl3.frag b/tests/manual/deferred-renderer-qml/final_gl3.frag new file mode 100644 index 000000000..d760e9844 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/final_gl3.frag @@ -0,0 +1,64 @@ +#version 140 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform vec2 winSize; + +out vec4 fragColor; + +const int MAX_LIGHTS = 8; +const int TYPE_POINT = 0; +const int TYPE_DIRECTIONAL = 1; +const int TYPE_SPOT = 2; + +struct Light { + int type; + vec3 position; + vec3 color; + float intensity; + vec3 direction; + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; + float cutOffAngle; +}; + +uniform Light lights[MAX_LIGHTS]; +uniform int lightCount; + +void main() +{ + vec2 texCoord = gl_FragCoord.xy / winSize; + vec4 col = texture(color, texCoord); + vec3 pos = texture(position, texCoord).xyz; + vec3 norm = texture(normal, texCoord).xyz; + + vec3 lightColor; + vec3 s; + + for (int i = 0; i < lightCount; ++i) { + float att = 1.0; + if ( lights[i].type != TYPE_DIRECTIONAL ) { + s = lights[i].position - pos; + if (lights[i].constantAttenuation != 0.0 + || lights[i].linearAttenuation != 0.0 + || lights[i].quadraticAttenuation != 0.0) { + float dist = length(s); + att = 1.0 / (lights[i].constantAttenuation + lights[i].linearAttenuation * dist + lights[i].quadraticAttenuation * dist * dist); + } + s = normalize( s ); + if ( lights[i].type == TYPE_SPOT ) { + if ( degrees(acos(dot(-s, normalize(lights[i].direction))) ) > lights[i].cutOffAngle) + att = 0.0; + } + } else { + s = normalize( -lights[i].direction ); + } + + float diffuse = max( dot( s, norm ), 0.0 ); + + lightColor += att * lights[i].intensity * diffuse * lights[i].color; + } + fragColor = vec4(col.rgb * lightColor, col.a); +} |