90 lines
2.0 KiB
HTML
90 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<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="Exam4_03.js"></script>
|
|
|
|
<button id = "Button1">Walk</button>
|
|
<button id = "Button2">Run</button>
|
|
<button id = "Button3">Agree</button>
|
|
<button id = "Button4">Disagree</button>
|
|
<button id = "Button9">Reset</button>
|
|
|
|
<div>
|
|
torso angle -180 <input id="slider0" type="range"
|
|
min="-180" max="180" step="10" value="140"
|
|
/>
|
|
180
|
|
</div><br/>
|
|
|
|
<body>
|
|
<canvas id="gl-canvas" width="512"" height="512">
|
|
Oops ... your browser doesn't support the HTML5 canvas element
|
|
</canvas>
|
|
</body>
|
|
</html>
|