Added mipmapping.
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 vec2 vTextureCoord;
16 varying vec3 vTransformedNormal;
17 varying vec4 vPosition;
19 uniform float uMaterialShininess;
21 uniform bool uUseLighting;
22 uniform bool uUseTexture;
24 uniform sampler2D uSampler;
26 uniform vec3 uAmbientColour;
27 uniform vec3 uPointLightingLocation;
28 uniform vec3 uPointLightingSpecularColour;
29 uniform vec3 uPointLightingDiffuseColour;
36 lightWeighting = vec3(1.0, 1.0, 1.0);
40 vec3 lightDirection = normalize(uPointLightingLocation - vPosition.xyz);
41 vec3 normal = normalize(vTransformedNormal);
42 vec3 eyeDirection = normalize(-vPosition.xyz);
43 vec3 reflectionDirection = reflect(-lightDirection, normal);
44 float specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), uMaterialShininess);
45 float diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
46 lightWeighting = uAmbientColour + uPointLightingSpecularColour * specularLightWeighting
47 + uPointLightingDiffuseColour * diffuseLightWeighting;
52 colour = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
58 gl_FragColor = vec4(colour.rgb * lightWeighting, colour.a);
62 <script id="vertex-shader" type="x-shader/x-vertex">
63 attribute vec3 aVertexPosition;
64 attribute vec3 aVertexNormal;
65 attribute vec4 aVertexColour;
66 attribute vec2 aTextureCoord;
68 uniform mat4 uMVMatrix;
69 uniform mat4 uPMatrix;
70 uniform mat3 uNMatrix;
73 varying vec2 vTextureCoord;
74 varying vec3 vTransformedNormal;
75 varying vec4 vPosition;
79 vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
80 gl_Position = uPMatrix * vPosition;
81 vColour = aVertexColour;
82 vTextureCoord = aTextureCoord;
83 vTransformedNormal = uNMatrix * aVertexNormal;
88 <body onload="boot();">
90 Download a browser with WebGL support, like Chrome or Firefox.