From 0f802beae8189f9eb38ae9dca983a09a56cc160e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 16 Dec 2022 21:03:32 +0200 Subject: [WGL/H09] Added unfinished work --- .../Homework 09 - The virus/shaders.js | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js (limited to 'Year 2/Computer Graphics with WebGL/Homework 09 - The virus/shaders.js') 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);'+ + '}'; -- cgit v1.3.1-26-gb76a