diff options
[WGL/H09] Added unfinished work
1 files changed, 39 insertions, 0 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js | 39 |
diff --git a/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js b/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js new file mode 100644 index 0000000..d78f08f --- /dev/null +++ b/Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js @@ -0,0 +1,39 @@ +
+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*max(dot(normal,light),0.0);'+
+ '}';
+
+var fShader =
+ 'precision mediump float;'+
+ 'varying vec3 vColor;'+
+ 'void main( )'+
+ '{'+
+ ' gl_FragColor = vec4(vColor,1);'+
+ '}';
|
