summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorkbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 17:54:05 +0000
committerkbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 17:54:05 +0000
commit46ef2ce78952914d3723b07aae28b024a1e8a6ad (patch)
tree933865afee43064de6c883342408a0fa63122689 /o3d
parent0908acd972c01bf7f3915575b5b53d78a0ee3c7b (diff)
downloadchromium_src-46ef2ce78952914d3723b07aae28b024a1e8a6ad.zip
chromium_src-46ef2ce78952914d3723b07aae28b024a1e8a6ad.tar.gz
chromium_src-46ef2ce78952914d3723b07aae28b024a1e8a6ad.tar.bz2
Thanks to apatrick, added missing support to GLSL ES grammar for
user-defined types in constructor calls and type names. Allows declarations of uniforms of struct types to parse. Added all shaders from WebGL demos; all parse successfully. Fixed Ant build targets. Attempted to make same changes to Bison version of grammar, but it is not working well (failing to parse some function calls the ANTLR version handles). Leaving it functionally unchanged. Cleaned up comments. Review URL: http://codereview.chromium.org/660160 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/compiler/glsl_validator/build.xml28
-rw-r--r--o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g22
-rw-r--r--o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y14
-rw-r--r--o3d/compiler/glsl_validator/shaders/many-planets-deep.frag11
-rw-r--r--o3d/compiler/glsl_validator/shaders/many-planets-deep.vert19
-rw-r--r--o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.frag5
-rw-r--r--o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.vert48
-rw-r--r--o3d/compiler/glsl_validator/shaders/particles-2d.vert69
-rw-r--r--o3d/compiler/glsl_validator/shaders/particles-3d.vert87
-rw-r--r--o3d/compiler/glsl_validator/shaders/particles.frag17
-rw-r--r--o3d/compiler/glsl_validator/shaders/san-angeles-fade.vert10
-rw-r--r--o3d/compiler/glsl_validator/shaders/san-angeles-flat.frag4
-rw-r--r--o3d/compiler/glsl_validator/shaders/san-angeles-flat.vert8
-rw-r--r--o3d/compiler/glsl_validator/shaders/san-angeles-lit.vert50
-rw-r--r--o3d/compiler/glsl_validator/shaders/shiny-teapot.frag23
-rw-r--r--o3d/compiler/glsl_validator/shaders/shiny-teapot.vert26
-rw-r--r--o3d/compiler/glsl_validator/shaders/spirit-box.frag12
-rw-r--r--o3d/compiler/glsl_validator/shaders/spirit-box.vert18
-rw-r--r--o3d/compiler/glsl_validator/shaders/spore-view.frag12
-rw-r--r--o3d/compiler/glsl_validator/shaders/spore-view.vert19
-rw-r--r--o3d/compiler/glsl_validator/shaders/teapot-per-pixel.frag46
-rw-r--r--o3d/compiler/glsl_validator/shaders/teapot-per-pixel.vert96
-rw-r--r--o3d/compiler/glsl_validator/shaders/teapot-per-vertex.frag11
-rw-r--r--o3d/compiler/glsl_validator/shaders/teapot-per-vertex.vert106
24 files changed, 746 insertions, 15 deletions
diff --git a/o3d/compiler/glsl_validator/build.xml b/o3d/compiler/glsl_validator/build.xml
index be53186..ee52a8c 100644
--- a/o3d/compiler/glsl_validator/build.xml
+++ b/o3d/compiler/glsl_validator/build.xml
@@ -10,13 +10,13 @@
<property name="build" value="build" />
<property name="test" value="test" />
<path id="antlr.classpath">
- <pathelement location="../../third_party/antlr3/lib/antlr-3.1.1.jar" />
+ <pathelement location="../../../third_party/antlr3/lib/antlr-3.1.1.jar" />
</path>
<path id="antlr.runtime.classpath">
- <pathelement location="../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
+ <pathelement location="../../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
</path>
<path id="test.classpath">
- <pathelement location="../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
+ <pathelement location="../../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
<pathelement location="${build}" />
</path>
</target>
@@ -25,7 +25,7 @@
<mkdir dir="${build}" />
<mkdir dir="${build}/glsl_es" />
<!-- Run ANTLR on the grammar -->
- <java classname="org.antlr.Tool">
+ <java classname="org.antlr.Tool" failonerror="true">
<classpath refid="antlr.classpath" />
<arg value="glsl_es/GLSL_ES.g" />
<arg value="-fo" />
@@ -45,8 +45,28 @@
<arg value="shaders/ambient.frag" />
<arg value="shaders/diffuse.vert" />
<arg value="shaders/diffuse.frag" />
+ <arg value="shaders/many-planets-deep.vert" />
+ <arg value="shaders/many-planets-deep.frag" />
+ <arg value="shaders/nvidia-vertex-buffer-object.vert" />
+ <arg value="shaders/nvidia-vertex-buffer-object.frag" />
<arg value="shaders/texture_mapping.vert" />
<arg value="shaders/texture_mapping.frag" />
+ <arg value="shaders/particles-2d.vert" />
+ <arg value="shaders/particles-3d.vert" />
+ <arg value="shaders/particles.frag" />
+ <arg value="shaders/san-angeles-flat.vert" />
+ <arg value="shaders/san-angeles-lit.vert" />
+ <arg value="shaders/san-angeles-flat.frag" />
+ <arg value="shaders/shiny-teapot.vert" />
+ <arg value="shaders/shiny-teapot.frag" />
+ <arg value="shaders/spirit-box.vert" />
+ <arg value="shaders/spirit-box.frag" />
+ <arg value="shaders/spore-view.vert" />
+ <arg value="shaders/spore-view.frag" />
+ <arg value="shaders/teapot-per-pixel.vert" />
+ <arg value="shaders/teapot-per-pixel.frag" />
+ <arg value="shaders/teapot-per-vertex.vert" />
+ <arg value="shaders/teapot-per-vertex.frag" />
</java>
</target>
diff --git a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g
index 688fbf8..e2cf26e 100644
--- a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g
+++ b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g
@@ -36,7 +36,7 @@ grammar GLSL_ES;
options {
language = Java;
- }
+}
@lexer::header { package glsl_es; }
@parser::header { package glsl_es; }
@@ -97,17 +97,19 @@ function_call_header
: function_identifier LEFT_PAREN
;
+// NOTE: change compared to GLSL ES grammar, because constructor_identifier
+// has IDENTIFIER (=TYPE_NAME) as one of its arms.
function_identifier
: constructor_identifier
- | IDENTIFIER
+// | IDENTIFIER
;
// Grammar Note: Constructors look like functions, but lexical analysis recognized most of them as
// keywords.
//
-// FIXME: do we need to register declared struct types in a dictionary
-// and look them up in order to be able to handle the TYPE_NAME
-// constructor identifier type?
+// TODO(kbr): do we need to register declared struct types in a dictionary
+// and look them up in order to be able to handle the TYPE_NAME constructor
+// identifier type?
constructor_identifier
: FLOAT
@@ -126,6 +128,7 @@ constructor_identifier
| MAT3
| MAT4
// | TYPE_NAME
+ | IDENTIFIER
;
unary_expression
@@ -243,7 +246,7 @@ function_header
;
parameter_declaration
- : (type_qualifier (parameter_qualifier)? )?
+ : (type_qualifier)? (parameter_qualifier)?
( type_specifier
// parameter_declarator
(IDENTIFIER)?
@@ -324,6 +327,7 @@ type_specifier_no_prec
| SAMPLERCUBE
| struct_specifier
// | TYPE_NAME
+ | IDENTIFIER
;
precision_qualifier
@@ -366,6 +370,7 @@ statement_no_new_scope
;
simple_statement
+options { backtrack=true; }
: declaration_statement
| expression_statement
| selection_statement
@@ -412,6 +417,7 @@ iteration_statement
;
for_init_statement
+options { backtrack=true; }
: expression_statement
| declaration_statement
;
@@ -487,7 +493,7 @@ IDENTIFIER
;
/*
-// FIXME: it isn't clear whether we need to support the TYPE_NAME
+// TODO(kbr): it isn't clear whether we need to support the TYPE_NAME
// token type; that may only be needed if typedef is supported
TYPE_NAME
: IDENTIFIER
@@ -531,7 +537,7 @@ fragment BOOLCONSTANT
| FALSE
;
-// FIXME: this needs much more work
+// TODO(kbr): this needs much more work
field_selection
: IDENTIFIER
;
diff --git a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y
index 16b5352..10c9879 100644
--- a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y
+++ b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y
@@ -84,7 +84,7 @@ translation_unit
: external_declaration
| translation_unit external_declaration
-/* FIXME: this requires much more work */
+/* TODO(kbr): this requires much more work */
FIELD_SELECTION
: IDENTIFIER
;
@@ -153,11 +153,17 @@ function_call_header
: function_identifier LEFT_PAREN
;
+// NOTE: change compared to GLSL ES grammar, because constructor_identifier
+// has IDENTIFIER (=TYPE_NAME) as one of its arms.
function_identifier
: constructor_identifier
| IDENTIFIER
;
+// TODO(kbr): do we need to register declared struct types in a dictionary
+// and look them up in order to be able to handle the TYPE_NAME constructor
+// identifier type?
+
constructor_identifier
: FLOAT
| INT
@@ -175,6 +181,7 @@ constructor_identifier
| MAT3
| MAT4
// | TYPE_NAME
+// | IDENTIFIER
;
unary_expression
@@ -291,7 +298,7 @@ conditional_expression
| logical_or_expression conditional_expression_1
;
-/* NOTE (FIXME): difference between Mesa's grammar and GLSL ES spec;
+/* NOTE (TODO(kbr)): difference between Mesa's grammar and GLSL ES spec;
Mesa uses conditional_expression after the colon, GLSL ES uses assignment_expression */
conditional_expression_1
: QUESTION expression COLON assignment_expression
@@ -457,6 +464,7 @@ type_specifier_no_prec
| SAMPLERCUBE
| struct_specifier
// | TYPE_NAME
+// | IDENTIFIER
;
precision_qualifier
@@ -535,7 +543,7 @@ compound_statement_no_new_scope
| LEFT_BRACE statement_list RIGHT_BRACE
;
-/* FIXME: may need refactoring */
+/* TODO(kbr): may need refactoring */
statement_list
: statement_no_new_scope
| statement_list statement_no_new_scope
diff --git a/o3d/compiler/glsl_validator/shaders/many-planets-deep.frag b/o3d/compiler/glsl_validator/shaders/many-planets-deep.frag
new file mode 100644
index 0000000..64bf5a4
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/many-planets-deep.frag
@@ -0,0 +1,11 @@
+uniform sampler2D sampler2d;
+
+varying float v_Dot;
+varying vec2 v_texCoord;
+
+void main()
+{
+ vec4 color = texture2D(sampler2d,v_texCoord);
+ color += vec4(0.1,0.1,0.1,1);
+ gl_FragColor = vec4(color.xyz * v_Dot, color.a);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/many-planets-deep.vert b/o3d/compiler/glsl_validator/shaders/many-planets-deep.vert
new file mode 100644
index 0000000..051a226
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/many-planets-deep.vert
@@ -0,0 +1,19 @@
+uniform mat4 u_modelViewMatrix;
+uniform mat4 u_modelViewProjMatrix;
+uniform mat4 u_normalMatrix;
+uniform vec3 lightDir;
+
+attribute vec3 vNormal;
+attribute vec4 vTexCoord;
+attribute vec4 vPosition;
+
+varying float v_Dot;
+varying vec2 v_texCoord;
+
+void main()
+{
+ gl_Position = u_modelViewProjMatrix * vPosition;
+ v_texCoord = vTexCoord.st;
+ vec4 transNormal = u_normalMatrix * vec4(vNormal,1);
+ v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.frag b/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.frag
new file mode 100644
index 0000000..98e8b27
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.frag
@@ -0,0 +1,5 @@
+varying vec4 v_color;
+
+void main() {
+ gl_FragColor = v_color;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.vert b/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.vert
new file mode 100644
index 0000000..60fc084
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/nvidia-vertex-buffer-object.vert
@@ -0,0 +1,48 @@
+// Per-vertex phong shader
+uniform mat4 worldViewProjection;
+uniform vec3 lightWorldPos;
+uniform vec4 lightColor;
+
+uniform mat4 world;
+uniform mat4 viewInverse;
+uniform mat4 worldInverseTranspose;
+
+uniform vec4 emissiveColor;
+uniform vec4 ambientColor;
+uniform vec4 diffuseColor;
+uniform vec4 specularColor;
+uniform float shininess;
+uniform float specularFactor;
+
+attribute vec3 g_Position;
+attribute vec3 g_Normal;
+
+varying vec4 v_color;
+
+vec4 lit(float n_dot_l, float n_dot_h, float m) {
+ return vec4(1.,
+ clamp(n_dot_l, 0., 1.),
+ // FIXME: approximation to
+ // (n_dot_l < 0) || (n_dot_h < 0)
+ pow(clamp(n_dot_h, 0., 1.), m),
+ 1.);
+}
+
+void main() {
+ vec4 position = vec4(g_Position, 1.);
+ vec4 worldPosition = world * position;
+ vec3 normal = normalize((worldInverseTranspose *
+ vec4(g_Normal, 0.)).xyz);
+ vec3 surfaceToLight = normalize(lightWorldPos - worldPosition.xyz);
+ vec3 surfaceToView = normalize((viewInverse[3] - worldPosition).xyz);
+ vec3 halfVector = normalize(surfaceToLight + surfaceToView);
+ vec4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector), shininess);
+ v_color =
+ vec4((emissiveColor +
+ lightColor * (ambientColor * litR.x +
+ diffuseColor * litR.y +
+ specularColor * litR.z * specularFactor)).rgb,
+ diffuseColor.a);
+ gl_Position = worldViewProjection * position;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/particles-2d.vert b/o3d/compiler/glsl_validator/shaders/particles-2d.vert
new file mode 100644
index 0000000..5197941
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/particles-2d.vert
@@ -0,0 +1,69 @@
+uniform mat4 viewProjection;
+uniform mat4 world;
+uniform mat4 viewInverse;
+uniform vec3 worldVelocity;
+uniform vec3 worldAcceleration;
+uniform float timeRange;
+uniform float time;
+uniform float timeOffset;
+uniform float frameDuration;
+uniform float numFrames;
+
+// Incoming vertex attributes
+attribute vec4 uvLifeTimeFrameStart; // uv, lifeTime, frameStart
+attribute vec4 positionStartTime; // position.xyz, startTime
+attribute vec4 velocityStartSize; // velocity.xyz, startSize
+attribute vec4 accelerationEndSize; // acceleration.xyz, endSize
+attribute vec4 spinStartSpinSpeed; // spinStart.x, spinSpeed.y
+attribute vec4 colorMult; // multiplies color and ramp textures
+
+// Outgoing variables to fragment shader
+varying vec2 outputTexcoord;
+varying float outputPercentLife;
+varying vec4 outputColorMult;
+
+void main() {
+ vec2 uv = uvLifeTimeFrameStart.xy;
+ float lifeTime = uvLifeTimeFrameStart.z;
+ float frameStart = uvLifeTimeFrameStart.w;
+ vec3 position = positionStartTime.xyz;
+ float startTime = positionStartTime.w;
+ vec3 velocity = (world * vec4(velocityStartSize.xyz,
+ 0.)).xyz + worldVelocity;
+ float startSize = velocityStartSize.w;
+ vec3 acceleration = (world * vec4(accelerationEndSize.xyz,
+ 0)).xyz + worldAcceleration;
+ float endSize = accelerationEndSize.w;
+ float spinStart = spinStartSpinSpeed.x;
+ float spinSpeed = spinStartSpinSpeed.y;
+
+ float localTime = mod((time - timeOffset - startTime), timeRange);
+ float percentLife = localTime / lifeTime;
+
+ float frame = mod(floor(localTime / frameDuration + frameStart),
+ numFrames);
+ float uOffset = frame / numFrames;
+ float u = uOffset + (uv.x + 0.5) * (1. / numFrames);
+
+ outputTexcoord = vec2(u, uv.y + 0.5);
+ outputColorMult = colorMult;
+
+ vec3 basisX = viewInverse[0].xyz;
+ vec3 basisZ = viewInverse[1].xyz;
+
+ float size = mix(startSize, endSize, percentLife);
+ size = (percentLife < 0. || percentLife > 1.) ? 0. : size;
+ float s = sin(spinStart + spinSpeed * localTime);
+ float c = cos(spinStart + spinSpeed * localTime);
+
+ vec2 rotatedPoint = vec2(uv.x * c + uv.y * s,
+ -uv.x * s + uv.y * c);
+ vec3 localPosition = vec3(basisX * rotatedPoint.x +
+ basisZ * rotatedPoint.y) * size +
+ velocity * localTime +
+ acceleration * localTime * localTime +
+ position;
+
+ outputPercentLife = percentLife;
+ gl_Position = viewProjection * vec4(localPosition + world[3].xyz, 1.);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/particles-3d.vert b/o3d/compiler/glsl_validator/shaders/particles-3d.vert
new file mode 100644
index 0000000..7f09de7
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/particles-3d.vert
@@ -0,0 +1,87 @@
+uniform mat4 worldViewProjection;
+uniform mat4 world;
+uniform vec3 worldVelocity;
+uniform vec3 worldAcceleration;
+uniform float timeRange;
+uniform float time;
+uniform float timeOffset;
+uniform float frameDuration;
+uniform float numFrames;
+
+// Incoming vertex attributes
+attribute vec4 uvLifeTimeFrameStart; // uv, lifeTime, frameStart
+attribute vec4 positionStartTime; // position.xyz, startTime
+attribute vec4 velocityStartSize; // velocity.xyz, startSize
+attribute vec4 accelerationEndSize; // acceleration.xyz, endSize
+attribute vec4 spinStartSpinSpeed; // spinStart.x, spinSpeed.y
+attribute vec4 orientation; // orientation quaternion
+attribute vec4 colorMult; // multiplies color and ramp textures
+
+// Outgoing variables to fragment shader
+varying vec2 outputTexcoord;
+varying float outputPercentLife;
+varying vec4 outputColorMult;
+
+void main() {
+ vec2 uv = uvLifeTimeFrameStart.xy;
+ float lifeTime = uvLifeTimeFrameStart.z;
+ float frameStart = uvLifeTimeFrameStart.w;
+ vec3 position = positionStartTime.xyz;
+ float startTime = positionStartTime.w;
+ vec3 velocity = (world * vec4(velocityStartSize.xyz,
+ 0.)).xyz + worldVelocity;
+ float startSize = velocityStartSize.w;
+ vec3 acceleration = (world * vec4(accelerationEndSize.xyz,
+ 0)).xyz + worldAcceleration;
+ float endSize = accelerationEndSize.w;
+ float spinStart = spinStartSpinSpeed.x;
+ float spinSpeed = spinStartSpinSpeed.y;
+
+ float localTime = mod((time - timeOffset - startTime), timeRange);
+ float percentLife = localTime / lifeTime;
+
+ float frame = mod(floor(localTime / frameDuration + frameStart),
+ numFrames);
+ float uOffset = frame / numFrames;
+ float u = uOffset + (uv.x + 0.5) * (1. / numFrames);
+
+ outputTexcoord = vec2(u, uv.y + 0.5);
+ outputColorMult = colorMult;
+
+ float size = mix(startSize, endSize, percentLife);
+ size = (percentLife < 0. || percentLife > 1.) ? 0. : size;
+ float s = sin(spinStart + spinSpeed * localTime);
+ float c = cos(spinStart + spinSpeed * localTime);
+
+ vec4 rotatedPoint = vec4((uv.x * c + uv.y * s) * size, 0.,
+ (uv.x * s - uv.y * c) * size, 1.);
+ vec3 center = velocity * localTime +
+ acceleration * localTime * localTime +
+ position;
+
+ vec4 q2 = orientation + orientation;
+ vec4 qx = orientation.xxxw * q2.xyzx;
+ vec4 qy = orientation.xyyw * q2.xyzy;
+ vec4 qz = orientation.xxzw * q2.xxzz;
+
+ mat4 localMatrix = mat4(
+ (1.0 - qy.y) - qz.z,
+ qx.y + qz.w,
+ qx.z - qy.w,
+ 0,
+
+ qx.y - qz.w,
+ (1.0 - qx.x) - qz.z,
+ qy.z + qx.w,
+ 0,
+
+ qx.z + qy.w,
+ qy.z - qx.w,
+ (1.0 - qx.x) - qy.y,
+ 0,
+
+ center.x, center.y, center.z, 1);
+ rotatedPoint = localMatrix * rotatedPoint;
+ outputPercentLife = percentLife;
+ gl_Position = worldViewProjection * rotatedPoint;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/particles.frag b/o3d/compiler/glsl_validator/shaders/particles.frag
new file mode 100644
index 0000000..25fb378
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/particles.frag
@@ -0,0 +1,17 @@
+uniform sampler2D rampSampler;
+uniform sampler2D colorSampler;
+
+// Incoming variables from vertex shader
+varying vec2 outputTexcoord;
+varying float outputPercentLife;
+varying vec4 outputColorMult;
+
+void main() {
+ vec4 colorMult = texture2D(rampSampler,
+ vec2(outputPercentLife, 0.5)) *
+ outputColorMult;
+ gl_FragColor = texture2D(colorSampler, outputTexcoord) * colorMult;
+ // For debugging: requires setup of some uniforms and vertex
+ // attributes to be commented out to avoid GL errors
+ // gl_FragColor = vec4(1., 0., 0., 1.);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/san-angeles-fade.vert b/o3d/compiler/glsl_validator/shaders/san-angeles-fade.vert
new file mode 100644
index 0000000..d2676ee42
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/san-angeles-fade.vert
@@ -0,0 +1,10 @@
+attribute vec2 pos;
+
+varying vec4 color;
+
+uniform float minFade;
+
+void main() {
+ color = vec4(minFade, minFade, minFade, 1.);
+ gl_Position = vec4(pos, 0., 1.);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/san-angeles-flat.frag b/o3d/compiler/glsl_validator/shaders/san-angeles-flat.frag
new file mode 100644
index 0000000..3f2bed8
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/san-angeles-flat.frag
@@ -0,0 +1,4 @@
+varying vec4 color;
+void main() {
+ gl_FragColor = vec4(color.rgb, 1.0);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/san-angeles-flat.vert b/o3d/compiler/glsl_validator/shaders/san-angeles-flat.vert
new file mode 100644
index 0000000..4583d20
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/san-angeles-flat.vert
@@ -0,0 +1,8 @@
+attribute vec3 pos;
+attribute vec4 colorIn;
+uniform mat4 mvp;
+varying vec4 color;
+void main() {
+ color = colorIn;
+ gl_Position = mvp * vec4(pos.xyz, 1.);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/san-angeles-lit.vert b/o3d/compiler/glsl_validator/shaders/san-angeles-lit.vert
new file mode 100644
index 0000000..022ec5ac
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/san-angeles-lit.vert
@@ -0,0 +1,50 @@
+attribute vec3 pos;
+attribute vec3 normal;
+attribute vec4 colorIn;
+
+varying vec4 color;
+
+uniform mat4 mvp;
+uniform mat3 normalMatrix;
+uniform vec4 ambient;
+uniform float shininess;
+uniform vec3 light_0_direction;
+uniform vec4 light_0_diffuse;
+uniform vec4 light_0_specular;
+uniform vec3 light_1_direction;
+uniform vec4 light_1_diffuse;
+uniform vec3 light_2_direction;
+uniform vec4 light_2_diffuse;
+
+vec3 worldNormal;
+
+vec4 SpecularLight(vec3 direction,
+ vec4 diffuseColor,
+ vec4 specularColor) {
+ vec3 lightDir = normalize(direction);
+ float diffuse = max(0., dot(worldNormal, lightDir));
+ float specular = 0.;
+ if (diffuse > 0.) {
+ vec3 halfv = normalize(lightDir + vec3(0., 0., 1.));
+ specular = pow(max(0., dot(halfv, worldNormal)), shininess);
+ }
+ return diffuse * diffuseColor * colorIn + specular * specularColor;
+}
+
+vec4 DiffuseLight(vec3 direction, vec4 diffuseColor) {
+ vec3 lightDir = normalize(direction);
+ float diffuse = max(0., dot(worldNormal, lightDir));
+ return diffuse * diffuseColor * colorIn;
+}
+
+void main() {
+ worldNormal = normalize(normalMatrix * normal);
+
+ gl_Position = mvp * vec4(pos, 1.);
+
+ color = ambient * colorIn;
+ color += SpecularLight(light_0_direction, light_0_diffuse,
+ light_0_specular);
+ color += DiffuseLight(light_1_direction, light_1_diffuse);
+ color += DiffuseLight(light_2_direction, light_2_diffuse);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/shiny-teapot.frag b/o3d/compiler/glsl_validator/shaders/shiny-teapot.frag
new file mode 100644
index 0000000..7c0667e
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/shiny-teapot.frag
@@ -0,0 +1,23 @@
+const float bumpHeight = 0.2;
+
+uniform sampler2D normalSampler;
+uniform samplerCube envSampler;
+
+varying vec2 texCoord;
+varying vec3 worldEyeVec;
+varying vec3 worldNormal;
+varying vec3 worldTangent;
+varying vec3 worldBinorm;
+
+void main() {
+ vec2 bump = (texture2D(normalSampler, texCoord.xy).xy * 2.0 - 1.0) * bumpHeight;
+ vec3 normal = normalize(worldNormal);
+ vec3 tangent = normalize(worldTangent);
+ vec3 binormal = normalize(worldBinorm);
+ vec3 nb = normal + bump.x * tangent + bump.y * binormal;
+ nb = normalize(nb);
+ vec3 worldEye = normalize(worldEyeVec);
+ vec3 lookup = reflect(worldEye, nb);
+ vec4 color = textureCube(envSampler, lookup);
+ gl_FragColor = color;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/shiny-teapot.vert b/o3d/compiler/glsl_validator/shaders/shiny-teapot.vert
new file mode 100644
index 0000000..e0eef69
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/shiny-teapot.vert
@@ -0,0 +1,26 @@
+attribute vec3 g_Position;
+attribute vec3 g_TexCoord0;
+attribute vec3 g_Tangent;
+attribute vec3 g_Binormal;
+attribute vec3 g_Normal;
+
+uniform mat4 world;
+uniform mat4 worldInverseTranspose;
+uniform mat4 worldViewProj;
+uniform mat4 viewInverse;
+
+varying vec2 texCoord;
+varying vec3 worldEyeVec;
+varying vec3 worldNormal;
+varying vec3 worldTangent;
+varying vec3 worldBinorm;
+
+void main() {
+ gl_Position = worldViewProj * vec4(g_Position.xyz, 1.);
+ texCoord.xy = g_TexCoord0.xy;
+ worldNormal = (worldInverseTranspose * vec4(g_Normal, 1.)).xyz;
+ worldTangent = (worldInverseTranspose * vec4(g_Tangent, 1.)).xyz;
+ worldBinorm = (worldInverseTranspose * vec4(g_Binormal, 1.)).xyz;
+ vec3 worldPos = (world * vec4(g_Position, 1.)).xyz;
+ worldEyeVec = normalize(worldPos - viewInverse[3].xyz);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/spirit-box.frag b/o3d/compiler/glsl_validator/shaders/spirit-box.frag
new file mode 100644
index 0000000..3013143
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/spirit-box.frag
@@ -0,0 +1,12 @@
+uniform sampler2D sampler2d;
+
+varying float v_Dot;
+varying vec2 v_texCoord;
+
+void main()
+{
+ vec2 texCoord = vec2(v_texCoord.s, 1.0 - v_texCoord.t);
+ vec4 color = texture2D(sampler2d, texCoord);
+ color += vec4(0.1, 0.1, 0.1, 1);
+ gl_FragColor = vec4(color.xyz * v_Dot, color.a);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/spirit-box.vert b/o3d/compiler/glsl_validator/shaders/spirit-box.vert
new file mode 100644
index 0000000..72f86d7
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/spirit-box.vert
@@ -0,0 +1,18 @@
+uniform mat4 u_modelViewProjMatrix;
+uniform mat4 u_normalMatrix;
+uniform vec3 lightDir;
+
+attribute vec3 vNormal;
+attribute vec4 vTexCoord;
+attribute vec4 vPosition;
+
+varying float v_Dot;
+varying vec2 v_texCoord;
+
+void main()
+{
+ gl_Position = u_modelViewProjMatrix * vPosition;
+ v_texCoord = vTexCoord.st;
+ vec4 transNormal = u_normalMatrix * vec4(vNormal, 1);
+ v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/spore-view.frag b/o3d/compiler/glsl_validator/shaders/spore-view.frag
new file mode 100644
index 0000000..72717bb
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/spore-view.frag
@@ -0,0 +1,12 @@
+varying vec3 vNormal;
+varying vec3 vViewVec;
+varying vec2 vTexCoord0;
+
+uniform vec4 uColor;
+uniform sampler2D uTexture0;
+
+void main(void) {
+ float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal));
+
+ gl_FragColor = texture2D(uTexture0, vTexCoord0.st);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/spore-view.vert b/o3d/compiler/glsl_validator/shaders/spore-view.vert
new file mode 100644
index 0000000..8ed64c3
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/spore-view.vert
@@ -0,0 +1,19 @@
+attribute vec3 aVertex;
+attribute vec3 aNormal;
+attribute vec2 aTexCoord0;
+
+uniform mat4 uPMatrix;
+uniform mat4 uMVMatrix;
+uniform vec4 uViewPosition;
+
+varying vec3 vNormal;
+varying vec3 vViewVec;
+varying vec2 vTexCoord0;
+
+void main(void) {
+ gl_Position = uPMatrix * uMVMatrix * vec4(aVertex, 1.0);
+
+ vNormal = aNormal;
+ vViewVec = uViewPosition.xyz - aVertex.xyz;
+ vTexCoord0 = aTexCoord0;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.frag b/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.frag
new file mode 100644
index 0000000..9e485f0
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.frag
@@ -0,0 +1,46 @@
+struct Light
+{
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ vec4 position;
+
+ vec3 halfVector;
+};
+
+struct Material
+{
+ vec4 emission;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ float shininess;
+};
+
+uniform sampler2D u_sampler2d;
+uniform Light u_light;
+uniform Material u_frontMaterial;
+uniform Material u_backMaterial;
+
+varying vec4 v_diffuse, v_ambient;
+varying vec3 v_normal, v_lightDir;
+varying vec2 v_texCoord;
+
+void main()
+{
+ vec4 color = v_diffuse;
+
+ vec3 n = normalize(v_normal);
+
+ Light light = u_light;
+ vec3 lightDir = v_lightDir;
+ float nDotL = max(dot(n, lightDir), 0.0);
+ if (nDotL > 0.0) {
+ color = vec4(color.rgb * nDotL, color.a);
+ float nDotHV = max(dot(n, light.halfVector), 0.0);
+ vec4 specular = u_frontMaterial.specular * light.specular;
+ color += vec4(specular.rgb * pow(nDotHV, u_frontMaterial.shininess), specular.a);
+ }
+
+ gl_FragColor = color + v_ambient;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.vert b/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.vert
new file mode 100644
index 0000000..b03e747
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/teapot-per-pixel.vert
@@ -0,0 +1,96 @@
+/*
+ Copyright (c) 2008 Seneca College
+ Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
+*/
+
+// We need to create our own light structure since we can't access
+// the light() function in the 2.0 context.
+struct Light
+{
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ vec4 position;
+
+ vec3 halfVector;
+};
+
+struct Material
+{
+ vec4 emission;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ float shininess;
+};
+//
+// vertex attributes
+//
+attribute vec4 a_vertex;
+attribute vec3 a_normal;
+attribute vec4 a_texCoord;
+
+// for every model we multiply the projection, view and model matrices
+// once to prevent having to do it for every vertex, however we still need
+// the view matrix to calculate lighting.
+uniform mat4 u_modelViewMatrix;
+
+// we can calculate this once per model to speed up processing done on the js side.
+uniform mat4 u_modelViewProjMatrix;
+
+// matrix to transform the vertex normals
+uniform mat4 u_normalMatrix;
+
+// custom light structures need to be used since we don't have access to
+// light states.
+uniform Light u_light;
+
+// material
+uniform vec4 u_globalAmbientColor;
+uniform Material u_frontMaterial;
+uniform Material u_backMaterial;
+
+// passed to fragment shader
+varying vec4 v_diffuse, v_ambient;
+varying vec3 v_normal, v_lightDir;
+varying vec2 v_texCoord;
+
+/*
+ Given a reference to the ambient and diffuse lighting variables,
+ this function will calculate how much each component contributes to the scene.
+
+ Light light - the light in view space
+ vec3 normal -
+ vec4 ambient -
+ vec4 diffuse -
+*/
+vec3 directionalLight(inout vec4 ambient, inout vec4 diffuse)
+{
+ ambient += u_light.ambient;
+ diffuse += u_light.diffuse;
+ return normalize(vec3(u_light.position));
+}
+
+void main()
+{
+ v_normal = normalize(u_normalMatrix * vec4(a_normal, 1)).xyz;
+
+ vec4 ambient = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 specular = vec4(0.0, 0.0, 0.0, 1.0);
+
+ // place the current vertex into view space
+ // ecPos = eye coordinate position.
+ vec4 ecPos4 = u_modelViewMatrix * a_vertex;
+
+ // the current vertex in eye coordinate space
+ vec3 ecPos = ecPos4.xyz/ecPos4.w;
+ v_lightDir = directionalLight(ambient, diffuse);
+
+ v_ambient = u_frontMaterial.ambient * ambient;
+ v_ambient += u_globalAmbientColor * u_frontMaterial.ambient;
+ v_diffuse = u_frontMaterial.diffuse * diffuse;
+
+ gl_Position = u_modelViewProjMatrix * a_vertex;
+ v_texCoord = a_texCoord.st;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.frag b/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.frag
new file mode 100644
index 0000000..973eddb
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.frag
@@ -0,0 +1,11 @@
+uniform sampler2D u_sampler2d;
+
+varying vec4 v_diffuse, v_specular;
+varying vec2 v_texCoord;
+
+void main()
+{
+ vec4 color = v_diffuse;
+
+ gl_FragColor = color + v_specular;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.vert b/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.vert
new file mode 100644
index 0000000..cfc0d45
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/teapot-per-vertex.vert
@@ -0,0 +1,106 @@
+/*
+ Copyright (c) 2008 Seneca College
+ Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
+*/
+
+// We need to create our own light structure since we can't access
+// the light() function in the 2.0 context.
+struct Light
+{
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ vec4 position;
+
+ vec3 halfVector;
+};
+
+struct Material
+{
+ vec4 emission;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ float shininess;
+};
+
+//
+// vertex attributes
+//
+attribute vec3 a_normal;
+attribute vec4 a_texCoord;
+attribute vec4 a_vertex;
+
+// for every model we multiply the projection, view and model matrices
+// once to prevent having to do it for every vertex, however we still need
+// the view matrix to calculate lighting.
+uniform mat4 u_modelViewMatrix;
+
+// we can calculate this once per model to speed up processing done on the js side.
+uniform mat4 u_modelViewProjMatrix;
+
+// matrix to transform the vertex normals
+uniform mat4 u_normalMatrix;
+
+// custom light structures need to be used since we don't have access to
+// light states.
+uniform Light u_light;
+
+// material
+uniform vec4 u_globalAmbientColor;
+uniform Material u_frontMaterial;
+uniform Material u_backMaterial;
+
+// passed to fragment shader
+varying vec4 v_diffuse, v_specular;
+varying vec2 v_texCoord;
+
+/*
+ Given a reference to the ambient and diffuse lighting variables,
+ this function will calculate how much each component contributes to the scene.
+
+ Light light - the light in view space
+ vec3 normal -
+ vec4 ambient -
+ vec4 diffuse -
+*/
+void directionalLight(in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
+{
+ vec3 lightDir = normalize(vec3(u_light.position));
+ ambient += u_light.ambient;
+
+ float nDotL = max(dot(normal, lightDir), 0.0);
+ if (nDotL > 0.0) {
+ diffuse += u_light.diffuse * nDotL;
+ float nDotHV = max(dot(normal, u_light.halfVector), 0.0);
+ nDotHV += 0.3;
+ vec4 specularColor = u_frontMaterial.specular * u_light.specular;
+ specular += vec4(specularColor.rgb * pow(nDotHV, u_frontMaterial.shininess), specularColor.a);
+ }
+}
+
+void main()
+{
+ vec3 normal = normalize(u_normalMatrix * vec4(a_normal, 1)).xyz;
+
+ vec4 ambient = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 specular = vec4(0.0, 0.0, 0.0, 1.0);
+
+ // place the current vertex into view space
+ // ecPos = eye coordinate position.
+ vec4 ecPos4 = u_modelViewMatrix * a_vertex;
+
+ // the current vertex in eye coordinate space
+ vec3 ecPos = ecPos4.xyz/ecPos4.w;
+ directionalLight(normal, ambient, diffuse, specular);
+
+ ambient = u_frontMaterial.ambient * ambient;
+ ambient += u_globalAmbientColor * u_frontMaterial.ambient;
+ diffuse = u_frontMaterial.diffuse * diffuse;
+
+ v_diffuse = diffuse;
+ v_specular = specular + ambient;
+ gl_Position = u_modelViewProjMatrix * a_vertex;
+ v_texCoord = a_texCoord.st;
+}