87 lines
2.0 KiB
HTML
87 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<script id="vertex-shader" type="x-shader/x-vertex">
|
|
#version 300 es
|
|
|
|
in vec4 aPosition;
|
|
in vec4 aNormal;
|
|
out vec3 N, L, E;
|
|
|
|
uniform mat4 uModelViewMatrix;
|
|
uniform mat4 uProjectionMatrix;
|
|
uniform vec4 uLightPosition;
|
|
uniform mat3 uNormalMatrix;
|
|
|
|
void main()
|
|
{
|
|
vec3 light;
|
|
vec3 pos = (uModelViewMatrix * aPosition).xyz;
|
|
if(uLightPosition.z == 0.0) L = normalize(uLightPosition.xyz);
|
|
else L = normalize(uLightPosition).xyz - pos;
|
|
|
|
E = -normalize(pos);
|
|
N = normalize(uNormalMatrix*aNormal.xyz);
|
|
gl_Position = uProjectionMatrix * uModelViewMatrix * aPosition;
|
|
|
|
}
|
|
</script>
|
|
|
|
<script id="fragment-shader" type="x-shader/x-fragment">
|
|
#version 300 es
|
|
|
|
precision mediump float;
|
|
|
|
uniform vec4 uAmbientProduct;
|
|
uniform vec4 uDiffuseProduct;
|
|
uniform vec4 uSpecularProduct;
|
|
uniform float uShininess;
|
|
|
|
in vec3 N, L, E;
|
|
out vec4 fColor;
|
|
|
|
void main()
|
|
{
|
|
|
|
vec3 H = normalize( L + E );
|
|
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);
|
|
|
|
fColor = ambient + diffuse +specular;
|
|
fColor.a = 1.0;
|
|
|
|
}
|
|
</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="shadedSphere4.js"></script>
|
|
|
|
<body>
|
|
<canvas id="gl-canvas" width="512" height="512">
|
|
Oops ... your browser doesn't support the HTML5 canvas element
|
|
</canvas>
|
|
</body>
|
|
</html>
|