This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
121 lines (101 loc) · 4.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<title>My Universe</title>
<meta charset="UTF-8" />
<!-- using glMatrix (http://glmatrix.net/) for Vector and Matrix operations in JS -->
<script src="js/gl-matrix-min.js" type="text/javascript"></script>
<script src="js/utils.js"></script>
<script src="js/matrixstack.js" type="application/javascript"></script>
<script src="js/scene/node.js"></script>
<script src="js/gl/geometricobject.js" type="application/javascript"></script>
<script src="js/scene/skybox.js"></script>
<script src="js/gl/triangle.js" type="text/javascript"></script>
<script src="js/gl/square.js" type="text/javascript"></script>
<script src="js/gl/quader.js" type="application/javascript"></script>
<script src="js/gl/sphere.js" type="application/javascript"></script>
<script src="js/light/light.js"></script>
<script src="js/light/material.js"></script>
<script src="js/light/texture.js"></script>
<script src="js/gl/camera.js" type="application/javascript"></script>
<script src="js/scene/orb.js"></script>
<script src="js/scene/orbit.js"></script>
<script src="js/scene/BorgOrbit.js"></script>
<script src="js/scene/BorgCubus.js"></script>
<script src="js/scene/scenegraph.js"></script>
<script src="js/gamecontroller.js"></script>
<script src="js/scene/main.js"></script>
<script src="js/keyboardobserver.js" type="application/javascript"></script>
<script src="js/webglstart.js" type="text/javascript"></script>
<!-- Vertex Shader-->
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aNormalPosition;
attribute vec2 aTextureCoordinates;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
varying vec3 vVertexPos;
varying vec3 vNormalPos;
varying vec2 vTextureCoord;
void main(void) {
gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aVertexPosition, 1);
vec4 pos = uModelViewMatrix * vec4(aVertexPosition, 1);
vVertexPos = pos.xyz / pos.w;
vNormalPos = normalize(uNormalMatrix * aNormalPosition);
vTextureCoord = aTextureCoordinates;
}
</script>
<!-- Fragment Shader-->
<script id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision mediump float;
#endif
uniform vec4 uLightPosition;
uniform vec4 uLightAmbient;
uniform vec4 uLightDiffuse;
uniform vec4 uLightSpecular;
uniform vec4 uMaterialEmission;
uniform vec4 uMaterialAmbient;
uniform vec4 uMaterialDiffuse;
uniform vec4 uMaterialSpecular;
uniform float uMaterialShininess;
uniform sampler2D uSampler;
varying vec3 vVertexPos;
varying vec3 vNormalPos;
varying vec4 vColor;
varying vec2 vTextureCoord;
void main(void) {
vec3 N = normalize(vNormalPos);
vec4 emissiv = uMaterialEmission;
vec4 ambient = uMaterialAmbient * uLightAmbient;
vec3 Eye = vec3(0.0, 0.0, 1.0);
vec3 L = vec3(0.0);
vec3 H = vec3(0.0);
vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);
if(uLightPosition.w == 0.0){
L = normalize(vec3(uLightPosition));
}
else {
L = normalize(vec3(uLightPosition) - vVertexPos);
}
H = normalize(L + Eye);
vec4 specular = vec4(0.0, 0.0, 0.0, 1.0);
float a = max(dot(N, L), 0.0);
if (a > 0.0) {
float specLight = pow(max(dot(H, N), 0.0), uMaterialShininess);
specular = specLight * uMaterialSpecular * uLightSpecular;
float diffuseLight = max(dot(N, L), 0.0);
diffuse = diffuseLight * uMaterialDiffuse * uLightDiffuse;
}
vec4 fullLight = emissiv + ambient + diffuse + specular;
float d = length(vec3(uLightPosition) - vVertexPos);
vec4 I_Modifiziert = (fullLight / d*d);
gl_FragColor = I_Modifiziert * texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
}
</script>
</head>
<body onload="webGLStart();">
<canvas id="glCanvas" style="border: none;" width="1500" height="500"></canvas>
</body>
</html>