@luma.gl/shadertools 9.0.19 → 9.0.20

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.
@@ -43,102 +43,21 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
43
43
  vec3 view_direction = normalize(cameraPosition - position_worldspace);
44
44
  lightColor = material.ambient * surfaceColor * lighting.ambientColor;
45
45
 
46
- if (lighting.lightType == 0) {
47
- PointLight pointLight = lighting_getPointLight(0);
46
+ for (int i = 0; i < lighting.pointLightCount; i++) {
47
+ PointLight pointLight = lighting_getPointLight(i);
48
48
  vec3 light_position_worldspace = pointLight.position;
49
49
  vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
50
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
51
- } else if (lighting.lightType == 1) {
52
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
53
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
54
- }
55
-
56
- /*
57
- for (int i = 0; i < MAX_LIGHTS; i++) {
58
- if (i >= lighting.pointLightCount) {
59
- break;
60
- }
61
- PointLight pointLight = lighting.pointLight[i];
62
- vec3 light_position_worldspace = pointLight.position;
63
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
64
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
50
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
51
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
65
52
  }
66
53
 
67
- for (int i = 0; i < MAX_LIGHTS; i++) {
68
- if (i >= lighting.directionalLightCount) {
69
- break;
70
- }
71
- DirectionalLight directionalLight = lighting.directionalLight[i];
54
+ int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
55
+ for (int i = lighting.pointLightCount; i < totalLights; i++) {
56
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
72
57
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
73
58
  }
74
- */
59
+
75
60
  return lightColor;
76
61
  }
77
62
 
78
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
79
- vec3 lightColor = vec3(0, 0, 0);
80
- vec3 surfaceColor = vec3(0, 0, 0);
81
-
82
- if (lighting.enabled == 0) {
83
- return lightColor;
84
- }
85
-
86
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
87
-
88
- switch (lighting.lightType) {
89
- case 0:
90
- PointLight pointLight = lighting_getPointLight(0);
91
- vec3 light_position_worldspace = pointLight.position;
92
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
93
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
94
- break;
95
-
96
- case 1:
97
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
98
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
99
- break;
100
- }
101
- return lightColor;
102
- }
103
63
  `;
104
-
105
- // TODO - handle multiple lights
106
- /**
107
- for (int i = 0; i < MAX_LIGHTS; i++) {
108
- if (i >= lighting.pointLightCount) {
109
- break;
110
- }
111
- PointLight pointLight = lighting_getPointLight(i);
112
- vec3 light_position_worldspace = pointLight.position;
113
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
114
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
115
- }
116
-
117
- for (int i = 0; i < MAX_LIGHTS; i++) {
118
- if (i >= lighting.directionalLightCount) {
119
- break;
120
- }
121
- PointLight pointLight = lighting_getDirectionalLight(i);
122
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
123
- }
124
- }
125
- /**
126
- for (int i = 0; i < MAX_LIGHTS; i++) {
127
- if (i >= lighting.pointLightCount) {
128
- break;
129
- }
130
- PointLight pointLight = lighting_getPointLight(i);
131
- vec3 light_position_worldspace = pointLight.position;
132
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
133
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
134
- }
135
-
136
- for (int i = 0; i < MAX_LIGHTS; i++) {
137
- if (i >= lighting.directionalLightCount) {
138
- break;
139
- }
140
- PointLight pointLight = lighting_getDirectionalLight(i);
141
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
142
- }
143
- }
144
- */
@@ -1,42 +0,0 @@
1
- export declare const GOURAUD_VS: string;
2
- export declare const GOURAUD_FS: string;
3
- /**
4
- for (int i = 0; i < MAX_LIGHTS; i++) {
5
- if (i >= lighting.pointLightCount) {
6
- break;
7
- }
8
- PointLight pointLight = lighting_getPointLight(i);
9
- vec3 light_position_worldspace = pointLight.position;
10
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
11
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
12
- }
13
-
14
- for (int i = 0; i < MAX_LIGHTS; i++) {
15
- if (i >= lighting.directionalLightCount) {
16
- break;
17
- }
18
- PointLight pointLight = lighting_getDirectionalLight(i);
19
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
20
- }
21
- }
22
- /**
23
- for (int i = 0; i < MAX_LIGHTS; i++) {
24
- if (i >= lighting.pointLightCount) {
25
- break;
26
- }
27
- PointLight pointLight = lighting_getPointLight(i);
28
- vec3 light_position_worldspace = pointLight.position;
29
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
30
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
31
- }
32
-
33
- for (int i = 0; i < MAX_LIGHTS; i++) {
34
- if (i >= lighting.directionalLightCount) {
35
- break;
36
- }
37
- PointLight pointLight = lighting_getDirectionalLight(i);
38
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
39
- }
40
- }
41
- */
42
- //# sourceMappingURL=gouraud-shaders-glsl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gouraud-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,QAuFtB,CAAC;AAEF,eAAO,MAAM,UAAU,QAOtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
@@ -1,110 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { glsl } from "../../../lib/glsl-utils/highlight.js";
5
- export const GOURAUD_VS = `\
6
- uniform gouraudMaterialUniforms {
7
- uniform float ambient;
8
- uniform float diffuse;
9
- uniform float shininess;
10
- uniform vec3 specularColor;
11
- } material;
12
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
13
- vec3 halfway_direction = normalize(light_direction + view_direction);
14
- float lambertian = dot(light_direction, normal_worldspace);
15
- float specular = 0.0;
16
- if (lambertian > 0.0) {
17
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
18
- specular = pow(specular_angle, material.shininess);
19
- }
20
- lambertian = max(lambertian, 0.0);
21
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
22
- }
23
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
24
- vec3 lightColor = surfaceColor;
25
- if (lighting.enabled == 0) {
26
- return lightColor;
27
- }
28
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
29
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
30
- if (lighting.lightType == 0) {
31
- PointLight pointLight = lighting_getPointLight(0);
32
- vec3 light_position_worldspace = pointLight.position;
33
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
34
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
35
- } else if (lighting.lightType == 1) {
36
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
37
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
38
- }
39
- return lightColor;
40
- }
41
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
42
- vec3 lightColor = vec3(0, 0, 0);
43
- vec3 surfaceColor = vec3(0, 0, 0);
44
- if (lighting.enabled == 0) {
45
- return lightColor;
46
- }
47
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
48
- switch (lighting.lightType) {
49
- case 0:
50
- PointLight pointLight = lighting_getPointLight(0);
51
- vec3 light_position_worldspace = pointLight.position;
52
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
53
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
54
- break;
55
- case 1:
56
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
57
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
58
- break;
59
- }
60
- return lightColor;
61
- }
62
- `;
63
- export const GOURAUD_FS = `\
64
- uniform gouraudMaterialUniforms {
65
- uniform float ambient;
66
- uniform float diffuse;
67
- uniform float shininess;
68
- uniform vec3 specularColor;
69
- } material;
70
- `;
71
- // TODO - handle multiple lights
72
- /**
73
- for (int i = 0; i < MAX_LIGHTS; i++) {
74
- if (i >= lighting.pointLightCount) {
75
- break;
76
- }
77
- PointLight pointLight = lighting_getPointLight(i);
78
- vec3 light_position_worldspace = pointLight.position;
79
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
80
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
81
- }
82
-
83
- for (int i = 0; i < MAX_LIGHTS; i++) {
84
- if (i >= lighting.directionalLightCount) {
85
- break;
86
- }
87
- PointLight pointLight = lighting_getDirectionalLight(i);
88
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
89
- }
90
- }
91
- /**
92
- for (int i = 0; i < MAX_LIGHTS; i++) {
93
- if (i >= lighting.pointLightCount) {
94
- break;
95
- }
96
- PointLight pointLight = lighting_getPointLight(i);
97
- vec3 light_position_worldspace = pointLight.position;
98
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
99
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
100
- }
101
-
102
- for (int i = 0; i < MAX_LIGHTS; i++) {
103
- if (i >= lighting.directionalLightCount) {
104
- break;
105
- }
106
- PointLight pointLight = lighting_getDirectionalLight(i);
107
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
108
- }
109
- }
110
- */
@@ -1,144 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {glsl} from '../../../lib/glsl-utils/highlight';
6
-
7
- export const GOURAUD_VS = glsl`\
8
- uniform gouraudMaterialUniforms {
9
- uniform float ambient;
10
- uniform float diffuse;
11
- uniform float shininess;
12
- uniform vec3 specularColor;
13
- } material;
14
-
15
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
16
- vec3 halfway_direction = normalize(light_direction + view_direction);
17
- float lambertian = dot(light_direction, normal_worldspace);
18
- float specular = 0.0;
19
- if (lambertian > 0.0) {
20
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
21
- specular = pow(specular_angle, material.shininess);
22
- }
23
- lambertian = max(lambertian, 0.0);
24
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
25
- }
26
-
27
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
28
- vec3 lightColor = surfaceColor;
29
-
30
- if (lighting.enabled == 0) {
31
- return lightColor;
32
- }
33
-
34
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
35
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
36
-
37
- if (lighting.lightType == 0) {
38
- PointLight pointLight = lighting_getPointLight(0);
39
- vec3 light_position_worldspace = pointLight.position;
40
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
41
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
42
- } else if (lighting.lightType == 1) {
43
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
44
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
45
- }
46
- /*
47
- for (int i = 0; i < MAX_LIGHTS; i++) {
48
- if (i >= lighting.pointLightCount) {
49
- break;
50
- }
51
- PointLight pointLight = lighting.pointLight[i];
52
- vec3 light_position_worldspace = pointLight.position;
53
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
54
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
55
- }
56
-
57
- for (int i = 0; i < MAX_LIGHTS; i++) {
58
- if (i >= lighting.directionalLightCount) {
59
- break;
60
- }
61
- DirectionalLight directionalLight = lighting.directionalLight[i];
62
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
63
- }
64
- */
65
- return lightColor;
66
- }
67
-
68
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
69
- vec3 lightColor = vec3(0, 0, 0);
70
- vec3 surfaceColor = vec3(0, 0, 0);
71
-
72
- if (lighting.enabled == 0) {
73
- return lightColor;
74
- }
75
-
76
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
77
-
78
- switch (lighting.lightType) {
79
- case 0:
80
- PointLight pointLight = lighting_getPointLight(0);
81
- vec3 light_position_worldspace = pointLight.position;
82
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
83
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
84
- break;
85
-
86
- case 1:
87
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
88
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
89
- break;
90
- }
91
-
92
- return lightColor;
93
- }
94
- `;
95
-
96
- export const GOURAUD_FS = glsl`\
97
- uniform gouraudMaterialUniforms {
98
- uniform float ambient;
99
- uniform float diffuse;
100
- uniform float shininess;
101
- uniform vec3 specularColor;
102
- } material;
103
- `;
104
-
105
- // TODO - handle multiple lights
106
- /**
107
- for (int i = 0; i < MAX_LIGHTS; i++) {
108
- if (i >= lighting.pointLightCount) {
109
- break;
110
- }
111
- PointLight pointLight = lighting_getPointLight(i);
112
- vec3 light_position_worldspace = pointLight.position;
113
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
114
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
115
- }
116
-
117
- for (int i = 0; i < MAX_LIGHTS; i++) {
118
- if (i >= lighting.directionalLightCount) {
119
- break;
120
- }
121
- PointLight pointLight = lighting_getDirectionalLight(i);
122
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
123
- }
124
- }
125
- /**
126
- for (int i = 0; i < MAX_LIGHTS; i++) {
127
- if (i >= lighting.pointLightCount) {
128
- break;
129
- }
130
- PointLight pointLight = lighting_getPointLight(i);
131
- vec3 light_position_worldspace = pointLight.position;
132
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
133
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
134
- }
135
-
136
- for (int i = 0; i < MAX_LIGHTS; i++) {
137
- if (i >= lighting.directionalLightCount) {
138
- break;
139
- }
140
- PointLight pointLight = lighting_getDirectionalLight(i);
141
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
142
- }
143
- }
144
- */