summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-08-11 15:18:26 +0200
committerSean Harmer <sean.harmer@kdab.com>2014-08-14 15:18:58 +0200
commit8090c3ab57d193529b81b8791d92f705c20d2af4 (patch)
treef6b1762d502fa11b1366341773923216cba77810 /examples
parent492541c062918f8d996f8e405e7c6606e648e3f8 (diff)
Simple-qml updated to use multiple render pass and drawstates
Change-Id: I0d3bd813549ea660b18ccf64c61fa6db0b07e197 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/simple-qml/ForwardRenderer.qml4
-rw-r--r--examples/simple-qml/main.qml87
2 files changed, 89 insertions, 2 deletions
diff --git a/examples/simple-qml/ForwardRenderer.qml b/examples/simple-qml/ForwardRenderer.qml
index 70b24e00f..e074c96ae 100644
--- a/examples/simple-qml/ForwardRenderer.qml
+++ b/examples/simple-qml/ForwardRenderer.qml
@@ -80,7 +80,7 @@ TechniqueFilter {
LayerFilter {
id : layerFilter
objectName : "layerFilter"
- RenderPassFilter { criteria : [Criterion {name : "Name"; value : "Texture";}] }
+ RenderPassFilter { criteria : [Criterion {name : "Name"; value : "TextureLighting";}] }
}
}
}
@@ -92,6 +92,8 @@ TechniqueFilter {
CameraSelector {
id: cameraSelectorBottomLeft
objectName : "cameraSelector"
+ RenderPassFilter { criteria : [Criterion {name : "Name"; value : "Texture";}] }
+ RenderPassFilter { criteria : [Criterion {name : "Name"; value : "Lighting";}] }
}
}
}
diff --git a/examples/simple-qml/main.qml b/examples/simple-qml/main.qml
index ed3875154..4e7706dcd 100644
--- a/examples/simple-qml/main.qml
+++ b/examples/simple-qml/main.qml
@@ -69,7 +69,7 @@ Entity {
ball2.mesh = test ? null : ballMesh
ball1.mesh = test ? cubeMesh : ballMesh
test = !test
- // instanciator.active = test
+// instanciator.active = test
external_forward_renderer.activeFrameGraph.layerFilters = test ? ["balls"] : []
}
}
@@ -306,6 +306,91 @@ Entity {
gl_FragColor = texture2D(texture, texCoord) * color;
}"
}
+ },
+ RenderPass {
+ criteria : [Criterion {name : "Name"; value : "Texture" }]
+ shaderProgram : ShaderProgram {
+ vertexShader : "
+ #version 140
+ in vec4 vertexPosition;
+ in vec2 vertexTexCoord;
+ out vec2 texCoord;
+
+ uniform mat4 mvp;
+
+ void main()
+ {
+ texCoord = vertexTexCoord;
+ gl_Position = mvp * vertexPosition;
+ }"
+
+ fragmentShader: "
+ #version 140
+ in vec2 texCoord;
+ uniform sampler2D tex;
+
+ void main()
+ {
+ gl_FragColor = texture2D(tex, texCoord);
+ }
+ "
+ }
+ },
+ RenderPass {
+ criteria : [Criterion {name : "Name"; value : "Lighting" }]
+ drawStates : [BlendState {srcRGB: BlendState.One; dstRGB : BlendState.One},
+ BlendEquation {mode: BlendEquation.FuncAdd},
+ CullFace { mode : CullFace.Back },
+ DepthTest { func : DepthTest.LessOrEqual}
+ ]
+ shaderProgram : ShaderProgram {
+ vertexShader: "
+ #version 140
+ in vec4 vertexPosition;
+ in vec3 vertexNormal;
+
+ out vec3 worldPosition;
+ out vec3 normal;
+
+ uniform mat4 modelViewProjection;
+ uniform mat4 modelView;
+ uniform mat3 modelViewNormal;
+
+ void main()
+ {
+ worldPosition = vec3(modelView * vertexPosition);
+ normal = normalize(modelViewNormal * vertexNormal);
+ gl_Position = modelViewProjection * vertexPosition;
+ }
+ "
+
+ fragmentShader: "
+ #version 140
+ in vec3 worldPosition;
+ in vec3 normal;
+
+ struct PointLight
+ {
+ vec3 position;
+ vec3 direction;
+ vec4 color;
+ float intensity;
+ };
+
+ const int lightCount = 3;
+ uniform PointLight pointLights[lightCount];
+
+ void main()
+ {
+ vec4 color;
+ for (int i = 0; i < lightCount; i++) {
+ vec3 s = normalize(pointLights[i].position - worldPosition);
+ color += pointLights[i].color * (pointLights[i].intensity * max(dot(s, normal), 0.0));
+ }
+ color /= float(lightCount);
+ gl_FragColor = color;
+ }"
+ }
}
]
}