machine.html
author Eugen Sawin <sawine@me73.com>
Wed, 27 Apr 2011 02:04:45 +0200
changeset 28 9df7034275e8
parent 25 3b66f92dbc4d
child 30 95688249c40c
permissions -rwxr-xr-x
Weird positioned scene objects.
     1 <html>
     2 <head>
     3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     4 <title>Machine Alpha</title>
     5 <style type="text/css">
     6  body {margin: 0px;}
     7 </style>
     8 <script language="javascript" src="scripts/boot.js"></script>
     9 <script id="fragment-shader" type="x-shader/x-fragment"> 
    10     #ifdef GL_ES
    11     precision highp float;
    12     #endif
    13 
    14     varying vec4 vColour;
    15     varying vec3 vLightWeighting;
    16  
    17     void main(void) 
    18     {
    19         gl_FragColor = vec4(vColour.rgb * vLightWeighting, vColour.a);
    20     }
    21 </script> 
    22  
    23 <script id="vertex-shader" type="x-shader/x-vertex"> 
    24     attribute vec3 aVertexPosition;
    25     attribute vec3 aVertexNormal;
    26     attribute vec4 aVertexColour;    
    27 
    28     uniform mat4 uMVMatrix;
    29     uniform mat4 uPMatrix;
    30     uniform mat3 uNMatrix;
    31 
    32     uniform vec3 uAmbientColour;
    33     uniform vec3 uLightingDirection;
    34     uniform vec3 uDirectionalColour;
    35 
    36     uniform bool uUseLighting;
    37 
    38     varying vec4 vColour;
    39     varying vec3 vLightWeighting;
    40  
    41     void main(void) 
    42     {
    43         gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
    44         vColour = aVertexColour;
    45 
    46         if (!uUseLighting)
    47         {
    48             vLightWeighting = vec3(1.0, 1.0, 1.0);
    49         }
    50         else
    51         {
    52             vec3 transformedNormal = uNMatrix * aVertexNormal;
    53             float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
    54             vLightWeighting = uAmbientColour + uDirectionalColour * directionalLightWeighting;
    55         }
    56     }
    57 </script>
    58 </head>
    59  
    60 <body onload="boot();">
    61 <canvas id="machine">
    62   Download a browser with WebGL support, like Chrome or Firefox.
    63 </canvas>
    64 </body>
    65  
    66 </html>