From 74f7343e14addefc74446c19018b3f82ad961207 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 9 Feb 2023 10:58:45 +0200 Subject: [WGL/P] Added initial setup --- .../Project/shaders.js | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Year 2/Computer Graphics with WebGL/Project/shaders.js (limited to 'Year 2/Computer Graphics with WebGL/Project/shaders.js') diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js new file mode 100644 index 0000000..d936756 --- /dev/null +++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js @@ -0,0 +1,40 @@ +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