Added per-vertex positional lighting.
3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4 <title>Machine Alpha</title>
5 <style type="text/css">
8 <script language="javascript" src="scripts/boot.js"></script>
9 <script id="fragment-shader" type="x-shader/x-fragment">
11 precision highp float;
15 varying vec3 vLightWeighting;
19 gl_FragColor = vec4(vColour.rgb * vLightWeighting, vColour.a);
23 <script id="vertex-shader" type="x-shader/x-vertex">
24 attribute vec3 aVertexPosition;
25 attribute vec3 aVertexNormal;
26 attribute vec4 aVertexColour;
28 uniform mat4 uMVMatrix;
29 uniform mat4 uPMatrix;
30 uniform mat3 uNMatrix;
32 uniform vec3 uAmbientColour;
33 uniform vec3 uLightingDirection;
34 uniform vec3 uDirectionalColour;
35 uniform vec3 uPointLightingLocation;
36 uniform vec3 uPointLightingColour;
38 uniform bool uUseLighting;
41 varying vec3 vLightWeighting;
45 vec4 mvPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
46 gl_Position = uPMatrix * mvPosition;
47 vColour = aVertexColour;
51 vLightWeighting = vec3(1.0, 1.0, 1.0);
55 //vec3 transformedNormal = uNMatrix * aVertexNormal;
56 //float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
57 //vLightWeighting = uAmbientColour + uDirectionalColour * directionalLightWeighting;
59 vec3 lightDirection = normalize(uPointLightingLocation - mvPosition.xyz);
60 vec3 transformedNormal = uNMatrix * aVertexNormal;
61 float directionalLightWeighting = max(dot(transformedNormal, lightDirection), 0.0);
62 vLightWeighting = uAmbientColour + uPointLightingColour * directionalLightWeighting;
68 <body onload="boot();">
70 Download a browser with WebGL support, like Chrome or Firefox.