114 lines
2.4 KiB
HTML
114 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<script id="vertex-shader" type="x-shader/x-vertex">
|
|
#version 300 es
|
|
|
|
// assume both position and normal are in homogeneous form
|
|
|
|
in vec4 aPosition;
|
|
in vec4 aNormal;
|
|
|
|
out vec4 vColor;
|
|
|
|
uniform vec4 uAmbientProduct, uDiffuseProduct, uSpecularProduct;
|
|
uniform mat4 uModelViewMatrix;
|
|
uniform mat4 uProjectionMatrix;
|
|
uniform vec4 uLightPosition;
|
|
uniform float uShininess;
|
|
uniform mat3 uNormalMatrix;
|
|
|
|
|
|
void
|
|
main()
|
|
{
|
|
|
|
// pos is vertex position in eye coordinates
|
|
|
|
vec3 pos = (uModelViewMatrix * aPosition).xyz;
|
|
|
|
// vector from vertex position to light source
|
|
|
|
vec3 L;
|
|
|
|
// check for directional light
|
|
|
|
if(uLightPosition.w == 0.0) L = normalize(uLightPosition.xyz);
|
|
else L = normalize( uLightPosition.xyz - pos );
|
|
|
|
// Because the eye point the is at the orgin
|
|
// the vector from the vertex position to the eye is
|
|
|
|
vec3 E = -normalize(pos);
|
|
|
|
// halfway vector
|
|
|
|
vec3 H = normalize(L + E);
|
|
|
|
// Transform vertex normal into eye coordinates
|
|
|
|
vec3 N = normalize( uNormalMatrix*aNormal.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>
|
|
|
|
<p> </p>
|
|
<button id = "Button0">Increase R</button>
|
|
<button id = "Button1">Decrease R</button>
|
|
|
|
<p> </p>
|
|
<button id = "Button2">Increase theta</button>
|
|
<button id = "Button3">Decrease theta</button>
|
|
<button id = "Button4">Increase phi</button>
|
|
<button id = "Button5">Decrease phi</button>
|
|
<p> </p>
|
|
<button id = "Button6">Increase Subdivisions</button>
|
|
<button id = "Button7">Decrease Subdivisions</button>
|
|
|
|
<p></p>
|
|
|
|
<script type="text/javascript" src="../Common/initShaders.js"></script>
|
|
<script type="text/javascript" src="../Common/MVnew.js"></script>
|
|
<script type="text/javascript" src="shadedSphere1.js"></script>
|
|
|
|
<body>
|
|
<canvas id="gl-canvas" width="512" height="512">
|
|
Oops ... your browser doesn't support the HTML5 canvas element
|
|
</canvas>
|
|
</body>
|
|
</html>
|