summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/deferred-renderer-cpp/final_gl3.frag
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-03-04 16:05:02 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-03-04 15:21:01 +0000
commitc82207d54c76d8b66be010bfa63e45f9507891fa (patch)
tree8d112e96bc1fa42dbc49907f53d71fa5b893869a /examples/qt3d/deferred-renderer-cpp/final_gl3.frag
parent8bff6813ee2e7a59d27bd8639dc9a6e23287a0c8 (diff)
Move the examples under a qt3d subdir
Modules cannot have their examples in the top-level examples directory because in the pre-built packages all modules' examples are merged together. Change-Id: I80fdbb8f1ec6f3d8fd793e4d856e705000237127 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples/qt3d/deferred-renderer-cpp/final_gl3.frag')
-rw-r--r--examples/qt3d/deferred-renderer-cpp/final_gl3.frag37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/qt3d/deferred-renderer-cpp/final_gl3.frag b/examples/qt3d/deferred-renderer-cpp/final_gl3.frag
new file mode 100644
index 000000000..88abd5cb1
--- /dev/null
+++ b/examples/qt3d/deferred-renderer-cpp/final_gl3.frag
@@ -0,0 +1,37 @@
+#version 140
+
+uniform sampler2D color;
+uniform sampler2D position;
+uniform sampler2D normal;
+uniform vec2 winSize;
+
+out vec4 fragColor;
+
+struct PointLight
+{
+ vec3 position;
+ vec3 direction;
+ vec4 color;
+ float intensity;
+};
+
+const int lightCount = 3;
+uniform PointLightBlock {
+ PointLight lights[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;
+
+ vec4 lightColor;
+ for (int i = 0; i < 3; i++) {
+ vec3 s = normalize(lights[i].position - pos);
+ lightColor += lights[i].color * (lights[i].intensity * max(dot(s, norm), 0.0));
+ }
+ lightColor /= float(lightCount);
+ fragColor = col * lightColor;
+}