@luma.gl/shadertools 9.0.19 → 9.0.21
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 +107 -206
- package/dist/dist.min.js +92 -148
- package/dist/index.cjs +105 -148
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +2 -3
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +7 -3
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +30 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +13 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +41 -33
- package/dist/modules/lighting/phong-material/phong-material.d.ts +4 -4
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- 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 -65
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +11 -8
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +32 -10
- package/src/modules/lighting/lights/lighting-uniforms.ts +61 -40
- package/src/modules/lighting/phong-material/phong-material.ts +9 -6
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -89
- 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 -110
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -144
|
@@ -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;
|
|
@@ -33,12 +34,11 @@ export type PointLight = {
|
|
|
33
34
|
position: Readonly<NumberArray3>;
|
|
34
35
|
color?: Readonly<NumberArray3>;
|
|
35
36
|
intensity?: number;
|
|
36
|
-
attenuation?:
|
|
37
|
+
attenuation?: Readonly<NumberArray3>;
|
|
37
38
|
};
|
|
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;
|
|
@@ -61,10 +61,18 @@ export type LightingUniforms = {
|
|
|
61
61
|
directionalLightCount: number;
|
|
62
62
|
pointLightCount: number;
|
|
63
63
|
lightType: number; // [];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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>;
|
|
68
76
|
};
|
|
69
77
|
|
|
70
78
|
/** UBO ready lighting module */
|
|
@@ -83,17 +91,28 @@ export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
|
83
91
|
|
|
84
92
|
uniformTypes: {
|
|
85
93
|
enabled: 'i32',
|
|
86
|
-
lightType: 'i32',
|
|
94
|
+
lightType: 'i32',
|
|
87
95
|
|
|
88
|
-
directionalLightCount: 'i32',
|
|
89
|
-
pointLightCount: 'i32',
|
|
96
|
+
directionalLightCount: 'i32',
|
|
97
|
+
pointLightCount: 'i32',
|
|
90
98
|
|
|
91
99
|
ambientLightColor: 'vec3<f32>',
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
|
|
101
|
+
// TODO define as arrays once we have appropriate uniformTypes
|
|
102
|
+
lightColor0: 'vec3<f32>',
|
|
103
|
+
lightPosition0: 'vec3<f32>',
|
|
94
104
|
// TODO - could combine direction and attenuation
|
|
95
|
-
|
|
96
|
-
|
|
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>'
|
|
97
116
|
},
|
|
98
117
|
|
|
99
118
|
defaultUniforms: {
|
|
@@ -104,11 +123,20 @@ export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
|
104
123
|
pointLightCount: 0,
|
|
105
124
|
|
|
106
125
|
ambientLightColor: [0.1, 0.1, 0.1],
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
lightColor0: [1, 1, 1],
|
|
127
|
+
lightPosition0: [1, 1, 2],
|
|
109
128
|
// TODO - could combine direction and attenuation
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
lightDirection0: [1, 1, 1],
|
|
130
|
+
lightAttenuation0: [1, 0, 0],
|
|
131
|
+
|
|
132
|
+
lightColor1: [1, 1, 1],
|
|
133
|
+
lightPosition1: [1, 1, 2],
|
|
134
|
+
lightDirection1: [1, 1, 1],
|
|
135
|
+
lightAttenuation1: [1, 0, 0],
|
|
136
|
+
lightColor2: [1, 1, 1],
|
|
137
|
+
lightPosition2: [1, 1, 2],
|
|
138
|
+
lightDirection2: [1, 1, 1],
|
|
139
|
+
lightAttenuation2: [1, 0, 0]
|
|
112
140
|
}
|
|
113
141
|
};
|
|
114
142
|
|
|
@@ -158,42 +186,35 @@ function getLightSourceUniforms({
|
|
|
158
186
|
pointLights = [],
|
|
159
187
|
directionalLights = []
|
|
160
188
|
}: LightingProps): Partial<LightingUniforms> {
|
|
161
|
-
const lightSourceUniforms: Partial<LightingUniforms> = {
|
|
162
|
-
// lightType: new Array(MAX_LIGHTS).fill(0),
|
|
163
|
-
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
164
|
-
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
165
|
-
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
166
|
-
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
|
|
167
|
-
};
|
|
189
|
+
const lightSourceUniforms: Partial<LightingUniforms> = {};
|
|
168
190
|
|
|
169
191
|
lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
|
|
170
192
|
|
|
171
|
-
let currentLight = 0;
|
|
193
|
+
let currentLight: 0 | 1 | 2 = 0;
|
|
172
194
|
|
|
173
195
|
for (const pointLight of pointLights) {
|
|
174
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;
|
|
175
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);
|
|
176
|
-
// lightSourceUniforms.lightPosition[currentLight] = pointLight.position;
|
|
177
|
-
// lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];
|
|
178
196
|
lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
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];
|
|
182
202
|
currentLight++;
|
|
183
203
|
}
|
|
184
204
|
|
|
185
205
|
for (const directionalLight of directionalLights) {
|
|
186
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;
|
|
187
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);
|
|
188
|
-
// lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;
|
|
189
|
-
// lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;
|
|
190
206
|
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
lightSourceUniforms
|
|
207
|
+
|
|
208
|
+
const i = currentLight as 0 | 1 | 2;
|
|
209
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
210
|
+
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
194
211
|
currentLight++;
|
|
195
212
|
}
|
|
196
213
|
|
|
214
|
+
if (currentLight > MAX_LIGHTS) {
|
|
215
|
+
log.warn('MAX_LIGHTS exceeded')();
|
|
216
|
+
}
|
|
217
|
+
|
|
197
218
|
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
198
219
|
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
199
220
|
|
|
@@ -5,19 +5,18 @@
|
|
|
5
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
6
|
import {lighting} from '../lights/lighting-uniforms';
|
|
7
7
|
import {PHONG_VS, PHONG_FS} from './phong-shaders-glsl';
|
|
8
|
+
import type {NumberArray3} from '../../../lib/utils/uniform-types';
|
|
8
9
|
|
|
9
|
-
export type PhongMaterialProps =
|
|
10
|
-
|
|
11
|
-
export type PhongMaterialUniforms = {
|
|
10
|
+
export type PhongMaterialProps = {
|
|
12
11
|
ambient?: number;
|
|
13
12
|
diffuse?: number;
|
|
14
13
|
/** Specularity exponent */
|
|
15
14
|
shininess?: number;
|
|
16
|
-
specularColor?:
|
|
15
|
+
specularColor?: NumberArray3;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
/** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
|
|
20
|
-
export const phongMaterial: ShaderModule<PhongMaterialProps
|
|
19
|
+
export const phongMaterial: ShaderModule<PhongMaterialProps> = {
|
|
21
20
|
name: 'phongMaterial',
|
|
22
21
|
// Note these are switched between phong and gouraud
|
|
23
22
|
vs: PHONG_VS,
|
|
@@ -38,7 +37,11 @@ export const phongMaterial: ShaderModule<PhongMaterialProps, PhongMaterialUnifor
|
|
|
38
37
|
shininess: 32,
|
|
39
38
|
specularColor: [0.15, 0.15, 0.15]
|
|
40
39
|
},
|
|
41
|
-
getUniforms(props?: PhongMaterialProps)
|
|
40
|
+
getUniforms(props?: PhongMaterialProps) {
|
|
41
|
+
const uniforms = {...props};
|
|
42
|
+
if (uniforms.specularColor) {
|
|
43
|
+
uniforms.specularColor = uniforms.specularColor.map(x => x / 255) as NumberArray3;
|
|
44
|
+
}
|
|
42
45
|
return {...phongMaterial.defaultUniforms, ...props};
|
|
43
46
|
}
|
|
44
47
|
};
|
|
@@ -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
|
-
|
|
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
|
-
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
|
-
*/
|