matrix-engine-wgpu 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ #version 300 es
2
+ in vec3 aVertexPosition;
3
+ in vec3 aVertexNormal;
4
+ in vec2 aTextureCoord;
5
+
6
+ uniform mat4 uMVMatrix;
7
+ uniform mat4 uPMatrix;
8
+ uniform mat3 uNMatrix;
9
+ uniform vec3 uAmbientColor;
10
+ uniform vec3 uLightingDirection;
11
+ uniform vec3 uDirectionalColor;
12
+ uniform bool uUseLighting;
13
+ out vec2 vTextureCoord;
14
+ out vec3 vLightWeighting;
15
+
16
+ // Spot
17
+ uniform vec3 u_lightWorldPosition;
18
+ out vec3 v_normal;
19
+ // out vec3 v_normal_cubemap;
20
+ out vec3 v_surfaceToLight;
21
+ out vec3 v_surfaceToView;
22
+
23
+ // Specular
24
+ out mat4 uMVMatrixINTER;
25
+ out mat3 uNMatrixINTER;
26
+ out mat4 uPMatrixINNTER;
27
+
28
+ in vec4 specularColor;
29
+ out vec4 vColor;
30
+ out vec3 vNormal;
31
+ out vec4 vPosition;
32
+ out float vDist;
33
+
34
+ void main(void) {
35
+ uMVMatrixINTER = uMVMatrix;
36
+ uNMatrixINTER = uNMatrix;
37
+ uPMatrixINNTER = uPMatrix;
38
+
39
+ // GLOBAL POS SPECULAR
40
+ vColor = specularColor;
41
+ vNormal = normalize(uNMatrix * vec3(aVertexNormal));
42
+ // Calculate the modelView of the model, and set the vPosition
43
+ // mat4 modelViewMatrix = uViewMatrix * uModelMatrix;
44
+ vPosition = uMVMatrix * vec4(1, 1, 1, 1);
45
+ vDist = gl_Position.w;
46
+
47
+ // SPOT
48
+ // orient the normals and pass to the fragment shader
49
+ v_normal = mat3(uNMatrix) * aVertexNormal;
50
+
51
+ // normalize
52
+ // v_normal_cubemap = normalize(aVertexPosition.xyz);
53
+
54
+ // compute the world position of the surfoace
55
+ vec3 surfaceWorldPosition = (uNMatrix * aVertexPosition).xyz;
56
+
57
+ // compute the vector of the surface to the light
58
+ // and pass it to the fragment shader
59
+ v_surfaceToLight = u_lightWorldPosition - surfaceWorldPosition;
60
+
61
+ // compute the vector of the surface to the view/camera
62
+ // and pass it to the fragment shader
63
+ v_surfaceToView = (uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0f)).xyz - surfaceWorldPosition;
64
+
65
+ gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0f);
66
+ vTextureCoord = aTextureCoord;
67
+
68
+ if(!uUseLighting) {
69
+ vLightWeighting = vec3(1.0f, 1.0f, 1.0f);
70
+ } else {
71
+ vec3 transformedNormal = uNMatrix * aVertexNormal;
72
+ float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0f);
73
+ vLightWeighting = uAmbientColor + uDirectionalColor * directionalLightWeighting;
74
+ }
75
+ }