Animation
Once the scene is setup no Javascript is running.
// The 4x4 world view projection matrix. float4x4 worldViewProjection : WorldViewProjection; float4x4 worldInverseTranspose : WorldInverseTranspose; float4x4 world : World; // positions of the light and camera float3 light_pos; float3 camera_pos; // lighting components of the light source float4 light_ambient; float4 light_diffuse; float4 light_specular; // shininess of the material. (for specular lighting) float shininess; float4 colorMult; // input parameters for our vertex shader struct a2v { float4 pos : POSITION; float3 normal : NORMAL; float4 col : COLOR; }; // input parameters for our pixel shader // also the output parameters for our vertex shader struct v2f { float4 pos : POSITION; float4 pos2 : TEXCOORD0; float3 norm : TEXCOORD1; float3 light : TEXCOORD2; float4 col : COLOR; }; /** * vsMain - our vertex shader * * @param IN.pos Position vector of vertex * @param IN.normal Normal of vertex * @param IN.col Color of vertex */ v2f vsMain(a2v IN) { /** * We use the standard phong illumination equation here. * We restrict (clamp) the dot products so that we * don't get any negative values. * All vectors are normalized for proper calculations. * * The output color is the summation of the * ambient, diffuse, and specular contributions. * * Note that we have to transform each vertex and normal * by the view projection matrix first. */ v2f OUT; OUT.pos = mul(IN.pos, worldViewProjection); OUT.pos2 = OUT.pos; OUT.norm = mul(float4(IN.normal, 0), worldInverseTranspose).xyz; OUT.light = light_pos - mul(IN.pos, world).xyz; OUT.col = IN.col; return OUT; } /** * psMain - pixel shader * * @param IN.pos Position vector of vertex * @param IN.col Color of vertex */ float4 psMain(v2f IN): COLOR { float3 light = normalize(IN.light); float3 normal = normalize(IN.norm); float3 r = normalize(reflect(normal, light)); float3 v = normalize(IN.pos2.xyz); float4 litR = lit(dot(normal, light), dot(r, v), shininess); return float4(((light_ambient + light_diffuse * litR.y) * colorMult + light_specular * litR.z).xyz, colorMult.w); } // Here we tell our effect file *which* functions are // our vertex and pixel shaders. // #o3d VertexShaderEntryPoint vsMain // #o3d PixelShaderEntryPoint psMain // #o3d MatrixLoadOrder RowMajor