@luma.gl/shadertools 9.0.17 → 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.
- package/dist/dist.dev.js +115 -210
- package/dist/dist.min.js +94 -147
- package/dist/index.cjs +106 -150
- package/dist/index.cjs.map +4 -4
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +4 -4
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +32 -8
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +14 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +46 -35
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +0 -39
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +7 -64
- package/package.json +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -4
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
- package/src/modules/lighting/lights/lighting-uniforms.ts +71 -42
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -87
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -108
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -139
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
6
|
import {lightingUniforms} from './lighting-uniforms-glsl';
|
|
7
7
|
import type {NumberArray3} from '../../../lib/utils/uniform-types';
|
|
8
|
+
import {log} from '@luma.gl/core';
|
|
8
9
|
|
|
9
10
|
/** Max number of supported lights (in addition to ambient light */
|
|
10
|
-
const MAX_LIGHTS =
|
|
11
|
+
const MAX_LIGHTS = 3;
|
|
11
12
|
|
|
12
13
|
/** Whether to divide */
|
|
13
14
|
const COLOR_FACTOR = 255.0;
|
|
@@ -38,7 +39,6 @@ export type PointLight = {
|
|
|
38
39
|
|
|
39
40
|
export type DirectionalLight = {
|
|
40
41
|
type: 'directional';
|
|
41
|
-
position: Readonly<NumberArray3>;
|
|
42
42
|
direction: Readonly<NumberArray3>;
|
|
43
43
|
color?: Readonly<NumberArray3>;
|
|
44
44
|
intensity?: number;
|
|
@@ -58,12 +58,21 @@ export type LightingProps = {
|
|
|
58
58
|
export type LightingUniforms = {
|
|
59
59
|
enabled: number;
|
|
60
60
|
ambientLightColor: Readonly<NumberArray3>;
|
|
61
|
-
|
|
61
|
+
directionalLightCount: number;
|
|
62
|
+
pointLightCount: number;
|
|
62
63
|
lightType: number; // [];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
lightColor0: Readonly<NumberArray3>;
|
|
65
|
+
lightPosition0: Readonly<NumberArray3>;
|
|
66
|
+
lightDirection0: Readonly<NumberArray3>;
|
|
67
|
+
lightAttenuation0: Readonly<NumberArray3>;
|
|
68
|
+
lightColor1: Readonly<NumberArray3>;
|
|
69
|
+
lightPosition1: Readonly<NumberArray3>;
|
|
70
|
+
lightDirection1: Readonly<NumberArray3>;
|
|
71
|
+
lightAttenuation1: Readonly<NumberArray3>;
|
|
72
|
+
lightColor2: Readonly<NumberArray3>;
|
|
73
|
+
lightPosition2: Readonly<NumberArray3>;
|
|
74
|
+
lightDirection2: Readonly<NumberArray3>;
|
|
75
|
+
lightAttenuation2: Readonly<NumberArray3>;
|
|
67
76
|
};
|
|
68
77
|
|
|
69
78
|
/** UBO ready lighting module */
|
|
@@ -82,26 +91,52 @@ export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
|
82
91
|
|
|
83
92
|
uniformTypes: {
|
|
84
93
|
enabled: 'i32',
|
|
94
|
+
lightType: 'i32',
|
|
95
|
+
|
|
96
|
+
directionalLightCount: 'i32',
|
|
97
|
+
pointLightCount: 'i32',
|
|
98
|
+
|
|
85
99
|
ambientLightColor: 'vec3<f32>',
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
|
|
101
|
+
// TODO define as arrays once we have appropriate uniformTypes
|
|
102
|
+
lightColor0: 'vec3<f32>',
|
|
103
|
+
lightPosition0: 'vec3<f32>',
|
|
90
104
|
// TODO - could combine direction and attenuation
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
lightDirection0: 'vec3<f32>',
|
|
106
|
+
lightAttenuation0: 'vec3<f32>',
|
|
107
|
+
|
|
108
|
+
lightColor1: 'vec3<f32>',
|
|
109
|
+
lightPosition1: 'vec3<f32>',
|
|
110
|
+
lightDirection1: 'vec3<f32>',
|
|
111
|
+
lightAttenuation1: 'vec3<f32>',
|
|
112
|
+
lightColor2: 'vec3<f32>',
|
|
113
|
+
lightPosition2: 'vec3<f32>',
|
|
114
|
+
lightDirection2: 'vec3<f32>',
|
|
115
|
+
lightAttenuation2: 'vec3<f32>'
|
|
93
116
|
},
|
|
94
117
|
|
|
95
118
|
defaultUniforms: {
|
|
96
119
|
enabled: 1,
|
|
97
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
98
|
-
numberOfLights: 0,
|
|
99
120
|
lightType: LIGHT_TYPE.POINT,
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
|
|
122
|
+
directionalLightCount: 0,
|
|
123
|
+
pointLightCount: 0,
|
|
124
|
+
|
|
125
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
126
|
+
lightColor0: [1, 1, 1],
|
|
127
|
+
lightPosition0: [1, 1, 2],
|
|
102
128
|
// TODO - could combine direction and attenuation
|
|
103
|
-
|
|
104
|
-
|
|
129
|
+
lightDirection0: [1, 1, 1],
|
|
130
|
+
lightAttenuation0: [1, 1, 1],
|
|
131
|
+
|
|
132
|
+
lightColor1: [1, 1, 1],
|
|
133
|
+
lightPosition1: [1, 1, 2],
|
|
134
|
+
lightDirection1: [1, 1, 1],
|
|
135
|
+
lightAttenuation1: [1, 1, 1],
|
|
136
|
+
lightColor2: [1, 1, 1],
|
|
137
|
+
lightPosition2: [1, 1, 2],
|
|
138
|
+
lightDirection2: [1, 1, 1],
|
|
139
|
+
lightAttenuation2: [1, 1, 1]
|
|
105
140
|
}
|
|
106
141
|
};
|
|
107
142
|
|
|
@@ -151,43 +186,37 @@ function getLightSourceUniforms({
|
|
|
151
186
|
pointLights = [],
|
|
152
187
|
directionalLights = []
|
|
153
188
|
}: LightingProps): Partial<LightingUniforms> {
|
|
154
|
-
const lightSourceUniforms: Partial<LightingUniforms> = {
|
|
155
|
-
// lightType: new Array(MAX_LIGHTS).fill(0),
|
|
156
|
-
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
157
|
-
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
158
|
-
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
159
|
-
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
|
|
160
|
-
};
|
|
189
|
+
const lightSourceUniforms: Partial<LightingUniforms> = {};
|
|
161
190
|
|
|
162
191
|
lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
|
|
163
192
|
|
|
164
|
-
let currentLight = 0;
|
|
193
|
+
let currentLight: 0 | 1 | 2 = 0;
|
|
165
194
|
|
|
166
195
|
for (const pointLight of pointLights) {
|
|
167
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;
|
|
168
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);
|
|
169
|
-
// lightSourceUniforms.lightPosition[currentLight] = pointLight.position;
|
|
170
|
-
// lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];
|
|
171
196
|
lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
lightSourceUniforms
|
|
197
|
+
|
|
198
|
+
const i = currentLight as 0 | 1 | 2;
|
|
199
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
|
|
200
|
+
lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
|
|
201
|
+
lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0];
|
|
175
202
|
currentLight++;
|
|
176
203
|
}
|
|
177
204
|
|
|
178
205
|
for (const directionalLight of directionalLights) {
|
|
179
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;
|
|
180
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);
|
|
181
|
-
// lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;
|
|
182
|
-
// lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;
|
|
183
206
|
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
lightSourceUniforms
|
|
207
|
+
|
|
208
|
+
const i = currentLight as 0 | 1 | 2;
|
|
209
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
210
|
+
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
187
211
|
currentLight++;
|
|
188
212
|
}
|
|
189
213
|
|
|
190
|
-
|
|
214
|
+
if (currentLight > MAX_LIGHTS) {
|
|
215
|
+
log.warn('MAX_LIGHTS exceeded')();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
219
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
191
220
|
|
|
192
221
|
return lightSourceUniforms;
|
|
193
222
|
}
|
|
@@ -18,7 +18,7 @@ export type PhongMaterialUniforms = {
|
|
|
18
18
|
|
|
19
19
|
/** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
|
|
20
20
|
export const phongMaterial: ShaderModule<PhongMaterialProps, PhongMaterialUniforms> = {
|
|
21
|
-
name: '
|
|
21
|
+
name: 'phongMaterial',
|
|
22
22
|
// Note these are switched between phong and gouraud
|
|
23
23
|
vs: PHONG_VS,
|
|
24
24
|
fs: PHONG_FS,
|
|
@@ -43,100 +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
|
-
|
|
47
|
-
PointLight pointLight = lighting_getPointLight(
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
84
|
-
|
|
85
|
-
switch (lighting.lightType) {
|
|
86
|
-
case 0:
|
|
87
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
88
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
89
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
90
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
91
|
-
break;
|
|
92
|
-
|
|
93
|
-
case 1:
|
|
94
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
95
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return lightColor;
|
|
100
|
-
}
|
|
101
63
|
`;
|
|
102
|
-
|
|
103
|
-
// TODO - handle multiple lights
|
|
104
|
-
/**
|
|
105
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
106
|
-
if (i >= lighting.pointLightCount) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
110
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
111
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
112
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
116
|
-
if (i >= lighting.directionalLightCount) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
120
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
125
|
-
if (i >= lighting.pointLightCount) {
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
129
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
130
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
131
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
135
|
-
if (i >= lighting.directionalLightCount) {
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
139
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
*/
|
|
@@ -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,QAOtB,CAAC;AAEF,eAAO,MAAM,UAAU,QAkFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|
|
@@ -1,108 +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 materialUniforms {
|
|
7
|
-
uniform float ambient;
|
|
8
|
-
uniform float diffuse;
|
|
9
|
-
uniform float shininess;
|
|
10
|
-
uniform vec3 specularColor;
|
|
11
|
-
} material;
|
|
12
|
-
`;
|
|
13
|
-
export const GOURAUD_FS = `\
|
|
14
|
-
uniform materialUniforms {
|
|
15
|
-
uniform float ambient;
|
|
16
|
-
uniform float diffuse;
|
|
17
|
-
uniform float shininess;
|
|
18
|
-
uniform vec3 specularColor;
|
|
19
|
-
} material;
|
|
20
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
21
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
22
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
23
|
-
float specular = 0.0;
|
|
24
|
-
if (lambertian > 0.0) {
|
|
25
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
26
|
-
specular = pow(specular_angle, material.shininess);
|
|
27
|
-
}
|
|
28
|
-
lambertian = max(lambertian, 0.0);
|
|
29
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
30
|
-
}
|
|
31
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
32
|
-
vec3 lightColor = surfaceColor;
|
|
33
|
-
if (lighting.enabled) {
|
|
34
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
35
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
36
|
-
if (lighting.lightType == 0) {
|
|
37
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
38
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
39
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
40
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
41
|
-
} else if (lighting.lightType == 1) {
|
|
42
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
43
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return lightColor;
|
|
47
|
-
}
|
|
48
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
49
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
50
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
51
|
-
if (lighting.enabled) {
|
|
52
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
53
|
-
switch (lighting.lightType) {
|
|
54
|
-
case 0:
|
|
55
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
56
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
57
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
58
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
59
|
-
break;
|
|
60
|
-
case 1:
|
|
61
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
62
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return lightColor;
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
// TODO - handle multiple lights
|
|
70
|
-
/**
|
|
71
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
72
|
-
if (i >= lighting.pointLightCount) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
76
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
77
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
78
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
82
|
-
if (i >= lighting.directionalLightCount) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
86
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
91
|
-
if (i >= lighting.pointLightCount) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
95
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
96
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
97
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
101
|
-
if (i >= lighting.directionalLightCount) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
105
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
*/
|
|
@@ -1,139 +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 materialUniforms {
|
|
9
|
-
uniform float ambient;
|
|
10
|
-
uniform float diffuse;
|
|
11
|
-
uniform float shininess;
|
|
12
|
-
uniform vec3 specularColor;
|
|
13
|
-
} material;
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
export const GOURAUD_FS = glsl`\
|
|
17
|
-
uniform materialUniforms {
|
|
18
|
-
uniform float ambient;
|
|
19
|
-
uniform float diffuse;
|
|
20
|
-
uniform float shininess;
|
|
21
|
-
uniform vec3 specularColor;
|
|
22
|
-
} material;
|
|
23
|
-
|
|
24
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
25
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
26
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
27
|
-
float specular = 0.0;
|
|
28
|
-
if (lambertian > 0.0) {
|
|
29
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
30
|
-
specular = pow(specular_angle, material.shininess);
|
|
31
|
-
}
|
|
32
|
-
lambertian = max(lambertian, 0.0);
|
|
33
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
37
|
-
vec3 lightColor = surfaceColor;
|
|
38
|
-
|
|
39
|
-
if (lighting.enabled) {
|
|
40
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
41
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
42
|
-
|
|
43
|
-
if (lighting.lightType == 0) {
|
|
44
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
45
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
46
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
47
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
48
|
-
} else if (lighting.lightType == 1) {
|
|
49
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
50
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
51
|
-
}
|
|
52
|
-
/*
|
|
53
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
54
|
-
if (i >= lighting.pointLightCount) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
58
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
59
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
60
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
64
|
-
if (i >= lighting.directionalLightCount) {
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
68
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
69
|
-
}
|
|
70
|
-
*/
|
|
71
|
-
}
|
|
72
|
-
return lightColor;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
76
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
77
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
78
|
-
|
|
79
|
-
if (lighting.enabled) {
|
|
80
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
81
|
-
|
|
82
|
-
switch (lighting.lightType) {
|
|
83
|
-
case 0:
|
|
84
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
85
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
86
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
87
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
88
|
-
break;
|
|
89
|
-
|
|
90
|
-
case 1:
|
|
91
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
92
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return lightColor;
|
|
97
|
-
}
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
// TODO - handle multiple lights
|
|
101
|
-
/**
|
|
102
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
103
|
-
if (i >= lighting.pointLightCount) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
107
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
108
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
109
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
113
|
-
if (i >= lighting.directionalLightCount) {
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
117
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
122
|
-
if (i >= lighting.pointLightCount) {
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
126
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
127
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
128
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
132
|
-
if (i >= lighting.directionalLightCount) {
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
136
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
*/
|