91 lines
2.0 KiB
HTML
91 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<script id="vertex-shader" type="x-shader/x-vertex">
|
|
#version 300 es
|
|
/* bump map vertex shader */
|
|
|
|
in vec2 aTexCoord;
|
|
in vec4 aPosition;
|
|
|
|
out vec3 L; /* light vector in texture-space coordinates */
|
|
out vec3 V; /* view vector in texture-space coordinates */
|
|
out vec2 vTexCoord;
|
|
|
|
uniform vec4 uNormal;
|
|
uniform vec4 uLightPosition;
|
|
uniform mat4 uModelViewMatrix;
|
|
uniform mat4 uProjectionMatrix;
|
|
uniform mat3 uNormalMatrix;
|
|
uniform vec3 uObjTangent; /* tangent vector in object coordinates */
|
|
|
|
void main()
|
|
{
|
|
gl_Position = uProjectionMatrix*uModelViewMatrix*aPosition;
|
|
|
|
vTexCoord = aTexCoord;
|
|
|
|
vec3 eyePosition = (uModelViewMatrix*aPosition).xyz;
|
|
vec3 eyeLightPos = (uModelViewMatrix*uLightPosition).xyz;
|
|
|
|
/* normal, tangent and binormal in eye coordinates */
|
|
|
|
vec3 N = normalize(uNormalMatrix*uNormal.xyz);
|
|
vec3 T = normalize(uNormalMatrix*uObjTangent);
|
|
vec3 B = cross(N, T);
|
|
|
|
/* light vector in texture space */
|
|
|
|
L.x = dot(T, eyeLightPos-eyePosition);
|
|
L.y = dot(B, eyeLightPos-eyePosition);
|
|
L.z = dot(N, eyeLightPos-eyePosition);
|
|
|
|
L = normalize(L);
|
|
|
|
/* view vector in texture space */
|
|
|
|
V.x = dot(T, -eyePosition);
|
|
V.y = dot(B, -eyePosition);
|
|
V.z = dot(N, -eyePosition);
|
|
|
|
V = normalize(V);
|
|
|
|
}
|
|
</script>
|
|
|
|
<script id="fragment-shader" type="x-shader/x-fragment">
|
|
#version 300 es
|
|
|
|
precision mediump float;
|
|
|
|
in vec3 L;
|
|
in vec3 V;
|
|
in vec2 vTexCoord;
|
|
|
|
uniform sampler2D uTexMap;
|
|
uniform vec4 uDiffuseProduct;
|
|
|
|
out vec4 fColor;
|
|
|
|
void main()
|
|
{
|
|
vec4 N = texture(uTexMap, vTexCoord);
|
|
vec3 NN = normalize(2.0*N.xyz-1.0);
|
|
vec3 LL = normalize(L);
|
|
float Kd = max(dot(NN, LL), 0.0);
|
|
|
|
fColor = vec4(Kd*uDiffuseProduct.xyz, 1.0);
|
|
}
|
|
</script>
|
|
|
|
<script type="text/javascript" src="../Common/initShaders.js"></script>
|
|
<script type="text/javascript" src="../Common/MVnew.js"></script>
|
|
<script type="text/javascript" src="bumpMap.js"></script>
|
|
|
|
<body>
|
|
<canvas id="gl-canvas" width="512" height="512">
|
|
Oops ... your browser doesn't support the HTML5 canvas element
|
|
</canvas>
|
|
</body>
|
|
</html>
|