125 lines
4.1 KiB
HTML
125 lines
4.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<p>
|
|
<button id="button1">Rotate X</button>
|
|
<button id="button2">Rotate Y</button>
|
|
<button id="button3">Rotate Z</button>
|
|
<button id="button4">Toggle Rotation</button>
|
|
<button id="button5">Pause </button>
|
|
</p>
|
|
<p> Material Ambient (RGB)
|
|
<input type="range" id="slider1" name="Material Ambient R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider2" name="Material Ambient G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider3" name="Material Ambient B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Material Diffuse (RGB)
|
|
<input type="range" id="slider4" name="Material Diffuse R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider5" name="Material Diffuse G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider6" name="Material Diffuse B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Material Specular (RGB)
|
|
<input type="range" id="slider7" name="Material Specular R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider8" name="Material Specular G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider9" name="Material Specular B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Light Ambient (RGB)
|
|
<input type="range" id="slider10" name="Material Ambient R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider11" name="Material Ambient G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider12" name="Material Ambient B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Light Diffuse (RGB)
|
|
<input type="range" id="slider13" name="Material Diffuse R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider14" name="Material Diffuse G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider15" name="Material Diffuse B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Light Specular (RGB)
|
|
<input type="range" id="slider16" name="Material Specular R" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider17" name="Material Specular G" min="0" max="1.0" value="0" step=".01" />
|
|
<input type="range" id="slider18" name="Material Specular B" min="0" max="1.0" value="0" step=".01" />
|
|
</p>
|
|
<p> Shininess
|
|
<input type="range" id="slider19" name="Shininess" min="0" max="100" value="0" step="1" />
|
|
</p>
|
|
|
|
|
|
<script id="vertex-shader" type="x-shader/x-vertex">
|
|
#version 300 es
|
|
|
|
in vec4 aPosition;
|
|
in vec3 aNormal;
|
|
out vec4 vColor;
|
|
|
|
uniform vec4 uAmbientProduct, uDiffuseProduct, uSpecularProduct;
|
|
uniform mat4 uModelViewMatrix;
|
|
uniform mat4 uProjectionMatrix;
|
|
uniform vec4 uLightPosition;
|
|
uniform float uShininess;
|
|
|
|
void main()
|
|
{
|
|
|
|
|
|
vec3 pos = -(uModelViewMatrix * aPosition).xyz;
|
|
|
|
//fixed light postion
|
|
|
|
vec3 light = uLightPosition.xyz;
|
|
vec3 L = normalize(light - pos);
|
|
|
|
|
|
vec3 E = normalize(-pos);
|
|
vec3 H = normalize(L + E);
|
|
|
|
vec4 NN = vec4(aNormal,0);
|
|
|
|
// Transform vertex normal into eye coordinates
|
|
|
|
vec3 N = normalize((uModelViewMatrix*NN).xyz);
|
|
|
|
// Compute terms in the illumination equation
|
|
vec4 ambient = uAmbientProduct;
|
|
|
|
float Kd = max(dot(L, N), 0.0);
|
|
vec4 diffuse = Kd*uDiffuseProduct;
|
|
|
|
float Ks = pow( max(dot(N, H), 0.0), uShininess );
|
|
vec4 specular = Ks * uSpecularProduct;
|
|
|
|
if( dot(L, N) < 0.0 ) {
|
|
specular = vec4(0.0, 0.0, 0.0, 1.0);
|
|
}
|
|
|
|
gl_Position = uProjectionMatrix * uModelViewMatrix *aPosition;
|
|
vColor = ambient + diffuse +specular;
|
|
|
|
vColor.a = 1.0;
|
|
}
|
|
</script>
|
|
|
|
<script id="fragment-shader" type="x-shader/x-fragment">
|
|
#version 300 es
|
|
|
|
precision mediump float;
|
|
|
|
|
|
in vec4 vColor;
|
|
out vec4 fColor;
|
|
|
|
void
|
|
main()
|
|
{
|
|
fColor = vColor;
|
|
}
|
|
</script>
|
|
|
|
<script type="text/javascript" src="../Common/initShaders.js"></script>
|
|
<script type="text/javascript" src="../Common/MVnew.js"></script>
|
|
<script type="text/javascript" src="exercise3c.js"></script>
|
|
|
|
<body>
|
|
<canvas id="gl-canvas" width="512" height="512">
|
|
Oops ... your browser doesn't support the HTML5 canvas element
|
|
</canvas>
|
|
</body>
|
|
|
|
</html> |