summaryrefslogtreecommitdiffstats
path: root/src/render/shaders
diff options
context:
space:
mode:
authorLorenz <Lorenz.Esch@tu-ilmenau.de>2015-03-06 22:31:39 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-03-11 13:19:36 +0000
commitd0f29fee3ebfa916c2ee44ea805c8ebf6cc64bf9 (patch)
tree26a844492a2b95a97e308e624d7a40cbe3420c2e /src/render/shaders
parenta21a41759f4fc115f34ce0891fedb255c4d32937 (diff)
Add new material QPerVertexColorMaterial
The new QPerVertexColorMaterial class provides color per vertex rendering. Change-Id: Idc87c21a07c2c8cd1ebfd5bed54c300c55e307ba Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/shaders')
-rw-r--r--src/render/shaders/es2/pervertexcolor.frag25
-rw-r--r--src/render/shaders/es2/pervertexcolor.vert20
-rw-r--r--src/render/shaders/gl3/pervertexcolor.frag29
-rw-r--r--src/render/shaders/gl3/pervertexcolor.vert22
-rw-r--r--src/render/shaders/pervertexcolor.frag29
-rw-r--r--src/render/shaders/pervertexcolor.vert22
6 files changed, 147 insertions, 0 deletions
diff --git a/src/render/shaders/es2/pervertexcolor.frag b/src/render/shaders/es2/pervertexcolor.frag
new file mode 100644
index 000000000..ff00557f3
--- /dev/null
+++ b/src/render/shaders/es2/pervertexcolor.frag
@@ -0,0 +1,25 @@
+#define FP highp
+
+uniform FP vec4 lightPosition;
+uniform FP vec3 lightIntensity;
+
+varying FP vec3 position;
+varying FP vec3 normal;
+varying FP vec3 color;
+
+FP vec3 adModel( const FP vec3 pos, const FP vec3 n, const FP vec3 col )
+{
+ // Calculate the vector from the light to the fragment
+ FP vec3 s = normalize( vec3( lightPosition ) - pos );
+
+ // Calculate the diffuse component
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ // Combine the ambient and diffuse
+ return lightIntensity * ( col + col * diffuse );
+}
+
+void main()
+{
+ gl_FragColor = vec4( adModel( position, normalize( normal ) ), 1.0 );
+}
diff --git a/src/render/shaders/es2/pervertexcolor.vert b/src/render/shaders/es2/pervertexcolor.vert
new file mode 100644
index 000000000..e7303052b
--- /dev/null
+++ b/src/render/shaders/es2/pervertexcolor.vert
@@ -0,0 +1,20 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+attribute vec3 vertexColor;
+
+varying vec3 position;
+varying vec3 normal;
+varying vec3 color;
+
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ normal = normalize( modelViewNormal * vertexNormal );
+ position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ color = vertexColor;
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/render/shaders/gl3/pervertexcolor.frag b/src/render/shaders/gl3/pervertexcolor.frag
new file mode 100644
index 000000000..a636781c4
--- /dev/null
+++ b/src/render/shaders/gl3/pervertexcolor.frag
@@ -0,0 +1,29 @@
+#version 150 core
+
+// TODO: Replace with a uniform block
+uniform vec4 lightPosition;
+uniform vec3 lightIntensity;
+
+in vec3 position;
+in vec3 normal;
+in vec3 color;
+
+out vec4 fragColor;
+
+vec3 adModel( const in vec3 pos, const in vec3 n, const in vec3 col )
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize( vec3( lightPosition ) - pos );
+
+ // Calculate the diffuse component
+ float diffuse = max( dot( s, n ), 0.0 );
+
+ // Combine the ambient and diffuse contributions
+ return lightIntensity * ( col + col * diffuse );
+}
+
+void main()
+{
+ fragColor = vec4( adModel( position, normalize( normal ), color ), 1.0 );
+}
+
diff --git a/src/render/shaders/gl3/pervertexcolor.vert b/src/render/shaders/gl3/pervertexcolor.vert
new file mode 100644
index 000000000..b6b1a5da7
--- /dev/null
+++ b/src/render/shaders/gl3/pervertexcolor.vert
@@ -0,0 +1,22 @@
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec3 vertexColor;
+
+out vec3 position;
+out vec3 normal;
+out vec3 color;
+
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ normal = normalize( modelViewNormal * vertexNormal );
+ position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ color = vertexColor;
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/render/shaders/pervertexcolor.frag b/src/render/shaders/pervertexcolor.frag
new file mode 100644
index 000000000..a636781c4
--- /dev/null
+++ b/src/render/shaders/pervertexcolor.frag
@@ -0,0 +1,29 @@
+#version 150 core
+
+// TODO: Replace with a uniform block
+uniform vec4 lightPosition;
+uniform vec3 lightIntensity;
+
+in vec3 position;
+in vec3 normal;
+in vec3 color;
+
+out vec4 fragColor;
+
+vec3 adModel( const in vec3 pos, const in vec3 n, const in vec3 col )
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize( vec3( lightPosition ) - pos );
+
+ // Calculate the diffuse component
+ float diffuse = max( dot( s, n ), 0.0 );
+
+ // Combine the ambient and diffuse contributions
+ return lightIntensity * ( col + col * diffuse );
+}
+
+void main()
+{
+ fragColor = vec4( adModel( position, normalize( normal ), color ), 1.0 );
+}
+
diff --git a/src/render/shaders/pervertexcolor.vert b/src/render/shaders/pervertexcolor.vert
new file mode 100644
index 000000000..b6b1a5da7
--- /dev/null
+++ b/src/render/shaders/pervertexcolor.vert
@@ -0,0 +1,22 @@
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec3 vertexColor;
+
+out vec3 position;
+out vec3 normal;
+out vec3 color;
+
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ normal = normalize( modelViewNormal * vertexNormal );
+ position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ color = vertexColor;
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}