Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Homework 09 - The virus / shaders2.js
diff options
context:
space:
mode:
1 files changed, 38 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders2.js38
diff --git a/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders2.js b/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders2.js
new file mode 100644
index 0000000..64e873a
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders2.js
@@ -0,0 +1,38 @@
+var vShader =
+ 'uniform mat4 uProjectionMatrix;' +
+ 'uniform mat4 uViewMatrix;' +
+ 'uniform mat4 uModelMatrix;' +
+ 'uniform mat4 uNormalMatrix;' +
+ 'uniform bool uUseNormalMatrix;' +
+ '' +
+ 'uniform vec3 uAmbientColor;' +
+ 'uniform vec3 uDiffuseColor;' +
+ '' +
+ 'uniform vec3 uLightDir;' +
+ '' +
+ 'attribute vec3 aXYZ;' +
+ 'attribute vec3 aColor;' +
+ 'attribute vec3 aNormal;' +
+ '' +
+ 'varying vec3 vColor;' +
+ '' +
+ 'void main ()' +
+ '{' +
+ ' mat4 mvMatrix = uViewMatrix * uModelMatrix;' +
+ ' gl_Position = uProjectionMatrix * mvMatrix * vec4(aXYZ,1);' +
+ ' mat4 nMatrix = uUseNormalMatrix?uNormalMatrix:mvMatrix;' +
+ '' +
+ ' vColor = uAmbientColor*aColor;' +
+ '' +
+ ' vec3 light = normalize(-uLightDir);' +
+ ' vec3 normal = vec3(normalize(nMatrix*vec4(aNormal,0)));' +
+ ' vColor += aColor*uDiffuseColor*abs(dot(normal,light));' +
+ '}';
+
+var fShader =
+ 'precision mediump float;' +
+ 'varying vec3 vColor;' +
+ 'void main( )' +
+ '{' +
+ ' gl_FragColor = vec4(vColor,1);' +
+ '}';