summaryrefslogtreecommitdiffstats
path: root/src/extras/shaders/es2
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-04-11 14:58:17 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2016-04-23 11:14:30 +0000
commit0542f1614aa6d50c4c9809fb0ce5f1adb5666d67 (patch)
tree77a1ed41c16262f5cc7aa9ddb2d66d3f9b61a719 /src/extras/shaders/es2
parent8677f62fa690efa29fbb6f870af1ea2b4e7111cf (diff)
Move defaults and geometries out of Qt3DRender and into Qt3DExtras
QBoundingVolumeDebug has been disabled for now. Will be re-enabled later on. Change-Id: Id6b0abab2ec2aa697330bd20d782f9d104d25d50 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/extras/shaders/es2')
-rw-r--r--src/extras/shaders/es2/diffusemap.frag25
-rw-r--r--src/extras/shaders/es2/diffusemap.vert22
-rw-r--r--src/extras/shaders/es2/diffusespecularmap.frag27
-rw-r--r--src/extras/shaders/es2/gooch.frag56
-rw-r--r--src/extras/shaders/es2/gooch.vert17
-rw-r--r--src/extras/shaders/es2/light.inc.frag131
-rw-r--r--src/extras/shaders/es2/light.inc.frag100218
-rw-r--r--src/extras/shaders/es2/normaldiffusemap.frag31
-rw-r--r--src/extras/shaders/es2/normaldiffusemap.vert38
-rw-r--r--src/extras/shaders/es2/normaldiffusemapalpha.frag32
-rw-r--r--src/extras/shaders/es2/normaldiffusespecularmap.frag32
-rw-r--r--src/extras/shaders/es2/pervertexcolor.frag14
-rw-r--r--src/extras/shaders/es2/pervertexcolor.vert20
-rw-r--r--src/extras/shaders/es2/phong.frag20
-rw-r--r--src/extras/shaders/es2/phong.vert17
-rw-r--r--src/extras/shaders/es2/phongalpha.frag22
-rw-r--r--src/extras/shaders/es2/skybox.frag8
-rw-r--r--src/extras/shaders/es2/skybox.vert12
-rw-r--r--src/extras/shaders/es2/unlittexture.frag11
-rw-r--r--src/extras/shaders/es2/unlittexture.vert17
20 files changed, 770 insertions, 0 deletions
diff --git a/src/extras/shaders/es2/diffusemap.frag b/src/extras/shaders/es2/diffusemap.frag
new file mode 100644
index 000000000..7d06d8e2c
--- /dev/null
+++ b/src/extras/shaders/es2/diffusemap.frag
@@ -0,0 +1,25 @@
+#define FP highp
+
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+uniform sampler2D diffuseTexture;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec2 texCoord;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ FP vec3 diffuseTextureColor = texture2D( diffuseTexture, texCoord ).rgb;
+
+ FP vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
+
+ gl_FragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + ks * specularColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/diffusemap.vert b/src/extras/shaders/es2/diffusemap.vert
new file mode 100644
index 000000000..13798279e
--- /dev/null
+++ b/src/extras/shaders/es2/diffusemap.vert
@@ -0,0 +1,22 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+attribute vec2 vertexTexCoord;
+
+varying vec3 worldPosition;
+varying vec3 worldNormal;
+varying vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 mvp;
+
+uniform float texCoordScale;
+
+void main()
+{
+ texCoord = vertexTexCoord * texCoordScale;
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/extras/shaders/es2/diffusespecularmap.frag b/src/extras/shaders/es2/diffusespecularmap.frag
new file mode 100644
index 000000000..4d776772c
--- /dev/null
+++ b/src/extras/shaders/es2/diffusespecularmap.frag
@@ -0,0 +1,27 @@
+#define FP highp
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D specularTexture;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec2 texCoord;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ FP vec3 diffuseTextureColor = texture2D( diffuseTexture, texCoord ).rgb;
+ FP vec3 specularTextureColor = texture2D( specularTexture, texCoord ).rgb;
+
+ FP vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
+
+ gl_FragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + specularTextureColor * specularColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/gooch.frag b/src/extras/shaders/es2/gooch.frag
new file mode 100644
index 000000000..622aaf0b4
--- /dev/null
+++ b/src/extras/shaders/es2/gooch.frag
@@ -0,0 +1,56 @@
+#define FP highp
+
+// TODO: Replace with a struct
+uniform FP vec3 kd; // Diffuse reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP vec3 kblue; // Cool color
+uniform FP vec3 kyellow; // Warm color
+uniform FP float alpha; // Fraction of diffuse added to kblue
+uniform FP float beta; // Fraction of diffuse added to kyellow
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+
+#pragma include light.inc.frag
+
+FP vec3 goochModel( const in FP vec3 pos, const in FP vec3 n )
+{
+ // Based upon the original Gooch lighting model paper at:
+ // http://www.cs.northwestern.edu/~ago820/SIG98/abstract.html
+
+ // Calculate kcool and kwarm from equation (3)
+ FP vec3 kcool = clamp(kblue + alpha * kd, 0.0, 1.0);
+ FP vec3 kwarm = clamp(kyellow + beta * kd, 0.0, 1.0);
+
+ // Calculate the vector from the light to the fragment
+ FP vec3 s = normalize( vec3( lights[0].position ) - pos );
+
+ // Calculate the cos theta factor mapped onto the range [0,1]
+ FP float sDotNFactor = ( 1.0 + dot( s, n ) ) / 2.0;
+
+ // Calculate the tone by blending the kcool and kwarm contributions
+ // as per equation (2)
+ FP vec3 intensity = mix( kcool, kwarm, sDotNFactor );
+
+ // Calculate the vector from the fragment to the eye position
+ FP vec3 v = normalize( eyePosition - pos );
+
+ // Reflect the light beam using the normal at this fragment
+ FP vec3 r = reflect( -s, n );
+
+ // Calculate the specular component
+ FP float specular = 0.0;
+ if ( dot( s, n ) > 0.0 )
+ specular = pow( max( dot( r, v ), 0.0 ), shininess );
+
+ // Sum the blended tone and specular highlight
+ return intensity + ks * specular;
+}
+
+void main()
+{
+ gl_FragColor = vec4( goochModel( worldPosition, normalize( worldNormal ) ), 1.0 );
+}
diff --git a/src/extras/shaders/es2/gooch.vert b/src/extras/shaders/es2/gooch.vert
new file mode 100644
index 000000000..dd162a66b
--- /dev/null
+++ b/src/extras/shaders/es2/gooch.vert
@@ -0,0 +1,17 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+
+varying vec3 worldPosition;
+varying vec3 worldNormal;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 mvp;
+
+void main()
+{
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/extras/shaders/es2/light.inc.frag b/src/extras/shaders/es2/light.inc.frag
new file mode 100644
index 000000000..cdec536cf
--- /dev/null
+++ b/src/extras/shaders/es2/light.inc.frag
@@ -0,0 +1,131 @@
+const int MAX_LIGHTS = 8;
+const int TYPE_POINT = 0;
+const int TYPE_DIRECTIONAL = 1;
+const int TYPE_SPOT = 2;
+struct Light {
+ int type;
+ FP vec3 position;
+ FP vec3 color;
+ FP float intensity;
+ FP vec3 direction;
+ FP vec3 attenuation;
+ FP float cutOffAngle;
+};
+uniform Light lights[MAX_LIGHTS];
+uniform int lightCount;
+
+void adsModelNormalMapped(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 eye, const in FP float shininess,
+ const in FP mat3 tangentMatrix,
+ out FP vec3 diffuseColor, out FP vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ int i;
+ FP vec3 s;
+ for (i = 0; i < lightCount; ++i) {
+ FP float att = 1.0;
+ if ( lights[i].type != TYPE_DIRECTIONAL ) {
+ s = tangentMatrix * ( lights[i].position - vpos );
+ if (length( lights[i].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * 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( tangentMatrix * -lights[i].direction );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ FP float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( tangentMatrix * ( eye - vpos ) );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ specularColor += att * lights[i].intensity * specular * lights[i].color;
+ }
+}
+
+void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 eye, const in FP float shininess,
+ out FP vec3 diffuseColor, out FP vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ int i;
+ FP vec3 s;
+ for (i = 0; i < lightCount; ++i) {
+ FP float att = 1.0;
+ if ( lights[i].type != TYPE_DIRECTIONAL ) {
+ s = lights[i].position - vpos;
+ if (length( lights[i].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * 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 );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ FP float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( eye - vpos );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ specularColor += att * lights[i].intensity * specular * lights[i].color;
+ }
+}
+
+void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffuseColor)
+{
+ diffuseColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ int i;
+ FP vec3 s;
+ for (i = 0; i < lightCount; ++i) {
+ FP float att = 1.0;
+ if ( lights[i].type != TYPE_DIRECTIONAL ) {
+ s = lights[i].position - vpos;
+ if (length( lights[i].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * dist + lights[i].attenuation.z * 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 );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ }
+}
diff --git a/src/extras/shaders/es2/light.inc.frag100 b/src/extras/shaders/es2/light.inc.frag100
new file mode 100644
index 000000000..b4988ad82
--- /dev/null
+++ b/src/extras/shaders/es2/light.inc.frag100
@@ -0,0 +1,218 @@
+const int MAX_LIGHTS = 2; // RPi: cannot use more than two as we run out of uniforms
+const int TYPE_POINT = 0;
+const int TYPE_DIRECTIONAL = 1;
+const int TYPE_SPOT = 2;
+struct Light {
+ int type;
+ FP vec3 position;
+ FP vec3 color;
+ FP float intensity;
+ FP vec3 direction;
+ FP vec3 attenuation;
+ FP float cutOffAngle;
+};
+uniform Light lights[MAX_LIGHTS];
+uniform int lightCount;
+
+void adsModelNormalMapped(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 eye, const in FP float shininess,
+ const in FP mat3 tangentMatrix,
+ out FP vec3 diffuseColor, out FP vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ // 0
+ if (lightCount < 1)
+ return;
+ FP vec3 s;
+ FP float att = 1.0;
+ if ( lights[0].type != TYPE_DIRECTIONAL ) {
+ s = tangentMatrix * ( lights[0].position - vpos );
+ if (length( lights[0].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[0].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[0].direction))) ) > lights[0].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( tangentMatrix * -lights[0].direction );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ FP float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( tangentMatrix * ( eye - vpos ) );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[0].intensity * diffuse * lights[0].color;
+ specularColor += att * specular;
+
+ // 1
+ if (lightCount < 2)
+ return;
+ att = 1.0;
+ if ( lights[1].type != TYPE_DIRECTIONAL ) {
+ s = tangentMatrix * ( lights[1].position - vpos );
+ if (length( lights[1].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[1].attenuation.x + lights[1].attenuation.y * dist + lights[1].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[1].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[1].direction))) ) > lights[1].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( tangentMatrix * -lights[1].direction );
+ }
+
+ diffuse = max( dot( s, n ), 0.0 );
+
+ specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( tangentMatrix * ( eye - vpos ) );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[1].intensity * diffuse * lights[1].color;
+ specularColor += att * specular;
+}
+
+void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 eye, const in FP float shininess,
+ out FP vec3 diffuseColor, out FP vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ // 0
+ if (lightCount < 1)
+ return;
+ FP vec3 s;
+ FP float att = 1.0;
+ if ( lights[0].type != TYPE_DIRECTIONAL ) {
+ s = lights[0].position - vpos;
+ if (length( lights[0].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[0].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[0].direction))) ) > lights[0].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( -lights[0].direction );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ FP float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( eye - vpos );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[0].intensity * diffuse * lights[0].color;
+ specularColor += att * specular;
+
+ // 1
+ if (lightCount < 2)
+ return;
+ att = 1.0;
+ if ( lights[1].type != TYPE_DIRECTIONAL ) {
+ s = lights[1].position - vpos;
+ if (length( lights[1].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[1].attenuation.x + lights[1].attenuation.y * dist + lights[1].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[1].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[1].direction))) ) > lights[1].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( -lights[1].direction );
+ }
+
+ diffuse = max( dot( s, n ), 0.0 );
+
+ specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP vec3 v = normalize( eye - vpos );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, v ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * lights[1].intensity * diffuse * lights[1].color;
+ specularColor += att * specular;
+}
+
+void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffuseColor)
+{
+ diffuseColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ // 0
+ if (lightCount < 1)
+ return;
+ FP vec3 s;
+ FP float att = 1.0;
+ if ( lights[0].type != TYPE_DIRECTIONAL ) {
+ s = lights[0].position - vpos;
+ if (length( lights[0].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[0].attenuation.x + lights[0].attenuation.y * dist + lights[0].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[0].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[0].direction))) ) > lights[0].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( -lights[0].direction );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ diffuseColor += att * lights[0].intensity * diffuse * lights[0].color;
+
+ // 1
+ if (lightCount < 2)
+ return;
+ att = 1.0;
+ if ( lights[1].type != TYPE_DIRECTIONAL ) {
+ s = lights[1].position - vpos;
+ if (length( lights[1].attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (lights[1].attenuation.x + lights[1].attenuation.y * dist + lights[1].attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( lights[1].type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(lights[1].direction))) ) > lights[1].cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( -lights[1].direction );
+ }
+
+ diffuse = max( dot( s, n ), 0.0 );
+
+ diffuseColor += att * lights[1].intensity * diffuse * lights[1].color;
+}
diff --git a/src/extras/shaders/es2/normaldiffusemap.frag b/src/extras/shaders/es2/normaldiffusemap.frag
new file mode 100644
index 000000000..c69aa8b81
--- /dev/null
+++ b/src/extras/shaders/es2/normaldiffusemap.frag
@@ -0,0 +1,31 @@
+#define FP highp
+
+varying FP vec3 worldPosition;
+varying FP vec2 texCoord;
+varying FP mat3 tangentMatrix;
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D normalTexture;
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ // Sample the textures at the interpolated texCoords
+ FP vec4 diffuseTextureColor = texture2D( diffuseTexture, texCoord );
+ FP vec3 normal = 2.0 * texture2D( normalTexture, texCoord ).rgb - vec3( 1.0 );
+
+ // Calculate the lighting model, keeping the specular component separate
+ FP vec3 diffuseColor, specularColor;
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+
+ // Combine spec with ambient+diffuse for final fragment color
+ gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + ks * specularColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/normaldiffusemap.vert b/src/extras/shaders/es2/normaldiffusemap.vert
new file mode 100644
index 000000000..ecc689f69
--- /dev/null
+++ b/src/extras/shaders/es2/normaldiffusemap.vert
@@ -0,0 +1,38 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+attribute vec2 vertexTexCoord;
+attribute vec4 vertexTangent;
+
+varying vec3 worldPosition;
+varying vec2 texCoord;
+varying mat3 tangentMatrix;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 projectionMatrix;
+uniform mat4 mvp;
+
+uniform float texCoordScale;
+
+void main()
+{
+ // Pass through texture coordinates
+ texCoord = vertexTexCoord * texCoordScale;
+
+ // Transform position, normal, and tangent to world coords
+ vec3 normal = normalize( modelNormalMatrix * vertexNormal );
+ vec3 tangent = normalize( modelNormalMatrix * vertexTangent.xyz );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
+
+ // Calculate binormal vector
+ vec3 binormal = normalize( cross( normal, tangent ) );
+
+ // Construct matrix to transform from eye coords to tangent space
+ tangentMatrix = mat3 (
+ tangent.x, binormal.x, normal.x,
+ tangent.y, binormal.y, normal.y,
+ tangent.z, binormal.z, normal.z );
+
+ // Calculate vertex position in clip coordinates
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/extras/shaders/es2/normaldiffusemapalpha.frag b/src/extras/shaders/es2/normaldiffusemapalpha.frag
new file mode 100644
index 000000000..98acbf01d
--- /dev/null
+++ b/src/extras/shaders/es2/normaldiffusemapalpha.frag
@@ -0,0 +1,32 @@
+#define FP highp
+
+varying FP vec3 worldPosition;
+varying FP vec2 texCoord;
+varying FP mat3 tangentMatrix;
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D normalTexture;
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ // Sample the textures at the interpolated texCoords
+ FP vec4 diffuseTextureColor = texture2D( diffuseTexture, texCoord );
+ FP vec3 normal = 2.0 * texture2D( normalTexture, texCoord ).rgb - vec3( 1.0 );
+
+ // Calculate the lighting model, keeping the specular component separate
+ FP vec3 diffuseColor, specularColor;
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+
+ // Combine spec with ambient+diffuse for final fragment color
+ // Use the alpha from the diffuse texture (for alpha to coverage)
+ gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + ks * specularColor, diffuseTextureColor.a );
+}
diff --git a/src/extras/shaders/es2/normaldiffusespecularmap.frag b/src/extras/shaders/es2/normaldiffusespecularmap.frag
new file mode 100644
index 000000000..b30c1bd5f
--- /dev/null
+++ b/src/extras/shaders/es2/normaldiffusespecularmap.frag
@@ -0,0 +1,32 @@
+#define FP highp
+
+varying FP vec3 worldPosition;
+varying FP vec2 texCoord;
+varying FP mat3 tangentMatrix;
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D specularTexture;
+uniform sampler2D normalTexture;
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ // Sample the textures at the interpolated texCoords
+ FP vec4 diffuseTextureColor = texture2D( diffuseTexture, texCoord );
+ FP vec4 specularTextureColor = texture2D( specularTexture, texCoord );
+ FP vec3 normal = 2.0 * texture2D( normalTexture, texCoord ).rgb - vec3( 1.0 );
+
+ // Calculate the lighting model, keeping the specular component separate
+ FP vec3 diffuseColor, specularColor;
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+
+ // Combine spec with ambient+diffuse for final fragment color
+ gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + specularTextureColor.rgb * specularColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/pervertexcolor.frag b/src/extras/shaders/es2/pervertexcolor.frag
new file mode 100644
index 000000000..ab429d942
--- /dev/null
+++ b/src/extras/shaders/es2/pervertexcolor.frag
@@ -0,0 +1,14 @@
+#define FP highp
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec3 color;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ FP vec3 diffuseColor;
+ adModel(worldPosition, worldNormal, diffuseColor);
+ gl_FragColor = vec4( color + color * diffuseColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/pervertexcolor.vert b/src/extras/shaders/es2/pervertexcolor.vert
new file mode 100644
index 000000000..7fc3e649f
--- /dev/null
+++ b/src/extras/shaders/es2/pervertexcolor.vert
@@ -0,0 +1,20 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+attribute vec3 vertexColor;
+
+varying vec3 worldPosition;
+varying vec3 worldNormal;
+varying vec3 color;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 mvp;
+
+void main()
+{
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
+ color = vertexColor;
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/extras/shaders/es2/phong.frag b/src/extras/shaders/es2/phong.frag
new file mode 100644
index 000000000..c00f89db0
--- /dev/null
+++ b/src/extras/shaders/es2/phong.frag
@@ -0,0 +1,20 @@
+#define FP highp
+
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 kd; // Diffuse reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+
+uniform FP vec3 eyePosition;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ FP vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
+ gl_FragColor = vec4( ka + kd * diffuseColor + ks * specularColor, 1.0 );
+}
diff --git a/src/extras/shaders/es2/phong.vert b/src/extras/shaders/es2/phong.vert
new file mode 100644
index 000000000..2b4c51b14
--- /dev/null
+++ b/src/extras/shaders/es2/phong.vert
@@ -0,0 +1,17 @@
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+
+varying vec3 worldPosition;
+varying vec3 worldNormal;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 modelViewProjection;
+
+void main()
+{
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = modelViewProjection * vec4( vertexPosition, 1.0 );
+}
diff --git a/src/extras/shaders/es2/phongalpha.frag b/src/extras/shaders/es2/phongalpha.frag
new file mode 100644
index 000000000..c5ec43049
--- /dev/null
+++ b/src/extras/shaders/es2/phongalpha.frag
@@ -0,0 +1,22 @@
+#define FP highp
+
+// TODO: Replace with a struct
+uniform FP vec3 ka; // Ambient reflectivity
+uniform FP vec3 kd; // Diffuse reflectivity
+uniform FP vec3 ks; // Specular reflectivity
+uniform FP float shininess; // Specular shininess factor
+uniform FP float alpha;
+
+uniform FP vec3 eyePosition;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ FP vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
+ gl_FragColor = vec4( ka + kd * diffuseColor + ks * specularColor, alpha );
+}
diff --git a/src/extras/shaders/es2/skybox.frag b/src/extras/shaders/es2/skybox.frag
new file mode 100644
index 000000000..3de08be44
--- /dev/null
+++ b/src/extras/shaders/es2/skybox.frag
@@ -0,0 +1,8 @@
+varying highp vec3 texCoord0;
+uniform samplerCube skyboxTexture;
+
+void main()
+{
+ gl_FragColor = textureCube(skyboxTexture, texCoord0);
+}
+
diff --git a/src/extras/shaders/es2/skybox.vert b/src/extras/shaders/es2/skybox.vert
new file mode 100644
index 000000000..e2de1d88b
--- /dev/null
+++ b/src/extras/shaders/es2/skybox.vert
@@ -0,0 +1,12 @@
+attribute vec3 vertexPosition;
+varying vec3 texCoord0;
+
+uniform mat4 mvp;
+uniform mat4 inverseProjectionMatrix;
+uniform mat4 inverseModelView;
+
+void main()
+{
+ texCoord0 = vertexPosition.xyz;
+ gl_Position = vec4(mvp * vec4(vertexPosition, 1.0)).xyww;
+}
diff --git a/src/extras/shaders/es2/unlittexture.frag b/src/extras/shaders/es2/unlittexture.frag
new file mode 100644
index 000000000..66752ed32
--- /dev/null
+++ b/src/extras/shaders/es2/unlittexture.frag
@@ -0,0 +1,11 @@
+#define FP highp
+
+uniform sampler2D diffuseTexture;
+
+varying FP vec3 position;
+varying FP vec2 texCoord;
+
+void main()
+{
+ gl_FragColor = texture2D( diffuseTexture, texCoord );
+}
diff --git a/src/extras/shaders/es2/unlittexture.vert b/src/extras/shaders/es2/unlittexture.vert
new file mode 100644
index 000000000..050b2b7e2
--- /dev/null
+++ b/src/extras/shaders/es2/unlittexture.vert
@@ -0,0 +1,17 @@
+attribute vec3 vertexPosition;
+attribute vec2 vertexTexCoord;
+
+varying vec3 position;
+varying vec2 texCoord;
+
+uniform mat4 modelView;
+uniform mat4 mvp;
+uniform vec2 texCoordOffset;
+
+void main()
+{
+ texCoord = vertexTexCoord + texCoordOffset;
+ position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}