@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
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { lighting } from "../lights/lighting-uniforms.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PHONG_VS, PHONG_FS } from "../phong-material/phong-shaders-glsl.js";
|
|
6
6
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
7
7
|
export const gouraudMaterial = {
|
|
8
|
-
name: '
|
|
8
|
+
name: 'gouraudMaterial',
|
|
9
9
|
// Note these are switched between phong and gouraud
|
|
10
|
-
vs:
|
|
11
|
-
fs:
|
|
10
|
+
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
11
|
+
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
12
12
|
defines: {
|
|
13
13
|
LIGHTING_VERTEX: 1
|
|
14
14
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,QA2E5B,CAAC"}
|
|
@@ -18,20 +18,44 @@ vec3 direction;
|
|
|
18
18
|
};
|
|
19
19
|
uniform lightingUniforms {
|
|
20
20
|
int enabled;
|
|
21
|
-
int
|
|
21
|
+
int lightType;
|
|
22
22
|
int directionalLightCount;
|
|
23
|
+
int pointLightCount;
|
|
23
24
|
vec3 ambientColor;
|
|
24
|
-
|
|
25
|
-
vec3
|
|
26
|
-
vec3
|
|
27
|
-
vec3
|
|
28
|
-
vec3
|
|
25
|
+
vec3 lightColor0;
|
|
26
|
+
vec3 lightPosition0;
|
|
27
|
+
vec3 lightDirection0;
|
|
28
|
+
vec3 lightAttenuation0;
|
|
29
|
+
vec3 lightColor1;
|
|
30
|
+
vec3 lightPosition1;
|
|
31
|
+
vec3 lightDirection1;
|
|
32
|
+
vec3 lightAttenuation1;
|
|
33
|
+
vec3 lightColor2;
|
|
34
|
+
vec3 lightPosition2;
|
|
35
|
+
vec3 lightDirection2;
|
|
36
|
+
vec3 lightAttenuation2;
|
|
29
37
|
} lighting;
|
|
30
38
|
PointLight lighting_getPointLight(int index) {
|
|
31
|
-
|
|
39
|
+
switch (index) {
|
|
40
|
+
case 0:
|
|
41
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
42
|
+
case 1:
|
|
43
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
44
|
+
case 2:
|
|
45
|
+
default:
|
|
46
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
47
|
+
}
|
|
32
48
|
}
|
|
33
49
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
34
|
-
|
|
50
|
+
switch (index) {
|
|
51
|
+
case 0:
|
|
52
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
53
|
+
case 1:
|
|
54
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
55
|
+
case 2:
|
|
56
|
+
default:
|
|
57
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
58
|
+
}
|
|
35
59
|
}
|
|
36
60
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
37
61
|
return pointLight.attenuation.x
|
|
@@ -16,7 +16,6 @@ export type PointLight = {
|
|
|
16
16
|
};
|
|
17
17
|
export type DirectionalLight = {
|
|
18
18
|
type: 'directional';
|
|
19
|
-
position: Readonly<NumberArray3>;
|
|
20
19
|
direction: Readonly<NumberArray3>;
|
|
21
20
|
color?: Readonly<NumberArray3>;
|
|
22
21
|
intensity?: number;
|
|
@@ -34,12 +33,21 @@ export type LightingProps = {
|
|
|
34
33
|
export type LightingUniforms = {
|
|
35
34
|
enabled: number;
|
|
36
35
|
ambientLightColor: Readonly<NumberArray3>;
|
|
37
|
-
|
|
36
|
+
directionalLightCount: number;
|
|
37
|
+
pointLightCount: number;
|
|
38
38
|
lightType: number;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
lightColor0: Readonly<NumberArray3>;
|
|
40
|
+
lightPosition0: Readonly<NumberArray3>;
|
|
41
|
+
lightDirection0: Readonly<NumberArray3>;
|
|
42
|
+
lightAttenuation0: Readonly<NumberArray3>;
|
|
43
|
+
lightColor1: Readonly<NumberArray3>;
|
|
44
|
+
lightPosition1: Readonly<NumberArray3>;
|
|
45
|
+
lightDirection1: Readonly<NumberArray3>;
|
|
46
|
+
lightAttenuation1: Readonly<NumberArray3>;
|
|
47
|
+
lightColor2: Readonly<NumberArray3>;
|
|
48
|
+
lightPosition2: Readonly<NumberArray3>;
|
|
49
|
+
lightDirection2: Readonly<NumberArray3>;
|
|
50
|
+
lightAttenuation2: Readonly<NumberArray3>;
|
|
43
51
|
};
|
|
44
52
|
/** UBO ready lighting module */
|
|
45
53
|
export declare const lighting: ShaderModule<LightingProps, LightingUniforms, {}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-uniforms.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,KAAK,EAAC,YAAY,EAAC,4CAAyC;
|
|
1
|
+
{"version":3,"file":"lighting-uniforms.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,KAAK,EAAC,YAAY,EAAC,4CAAyC;AAenE,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,kBAAkB;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,aAAa,EAAE,gBAAgB,EAAE,EAAE,CA8DtE,CAAC"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { lightingUniforms } from "./lighting-uniforms-glsl.js";
|
|
5
|
+
import { log } from '@luma.gl/core';
|
|
5
6
|
/** Max number of supported lights (in addition to ambient light */
|
|
6
|
-
const MAX_LIGHTS =
|
|
7
|
+
const MAX_LIGHTS = 3;
|
|
7
8
|
/** Whether to divide */
|
|
8
9
|
const COLOR_FACTOR = 255.0;
|
|
9
10
|
/** Shader type field for lights */
|
|
@@ -25,25 +26,44 @@ export const lighting = {
|
|
|
25
26
|
},
|
|
26
27
|
uniformTypes: {
|
|
27
28
|
enabled: 'i32',
|
|
29
|
+
lightType: 'i32',
|
|
30
|
+
directionalLightCount: 'i32',
|
|
31
|
+
pointLightCount: 'i32',
|
|
28
32
|
ambientLightColor: 'vec3<f32>',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,
|
|
33
|
+
// TODO define as arrays once we have appropriate uniformTypes
|
|
34
|
+
lightColor0: 'vec3<f32>',
|
|
35
|
+
lightPosition0: 'vec3<f32>',
|
|
33
36
|
// TODO - could combine direction and attenuation
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
lightDirection0: 'vec3<f32>',
|
|
38
|
+
lightAttenuation0: 'vec3<f32>',
|
|
39
|
+
lightColor1: 'vec3<f32>',
|
|
40
|
+
lightPosition1: 'vec3<f32>',
|
|
41
|
+
lightDirection1: 'vec3<f32>',
|
|
42
|
+
lightAttenuation1: 'vec3<f32>',
|
|
43
|
+
lightColor2: 'vec3<f32>',
|
|
44
|
+
lightPosition2: 'vec3<f32>',
|
|
45
|
+
lightDirection2: 'vec3<f32>',
|
|
46
|
+
lightAttenuation2: 'vec3<f32>'
|
|
36
47
|
},
|
|
37
48
|
defaultUniforms: {
|
|
38
49
|
enabled: 1,
|
|
39
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
40
|
-
numberOfLights: 0,
|
|
41
50
|
lightType: LIGHT_TYPE.POINT,
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
directionalLightCount: 0,
|
|
52
|
+
pointLightCount: 0,
|
|
53
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
54
|
+
lightColor0: [1, 1, 1],
|
|
55
|
+
lightPosition0: [1, 1, 2],
|
|
44
56
|
// TODO - could combine direction and attenuation
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
lightDirection0: [1, 1, 1],
|
|
58
|
+
lightAttenuation0: [1, 1, 1],
|
|
59
|
+
lightColor1: [1, 1, 1],
|
|
60
|
+
lightPosition1: [1, 1, 2],
|
|
61
|
+
lightDirection1: [1, 1, 1],
|
|
62
|
+
lightAttenuation1: [1, 1, 1],
|
|
63
|
+
lightColor2: [1, 1, 1],
|
|
64
|
+
lightPosition2: [1, 1, 2],
|
|
65
|
+
lightDirection2: [1, 1, 1],
|
|
66
|
+
lightAttenuation2: [1, 1, 1]
|
|
47
67
|
}
|
|
48
68
|
};
|
|
49
69
|
function getUniforms(props, prevUniforms = {}) {
|
|
@@ -77,38 +97,29 @@ function getUniforms(props, prevUniforms = {}) {
|
|
|
77
97
|
return uniforms;
|
|
78
98
|
}
|
|
79
99
|
function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
|
|
80
|
-
const lightSourceUniforms = {
|
|
81
|
-
// lightType: new Array(MAX_LIGHTS).fill(0),
|
|
82
|
-
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
83
|
-
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
84
|
-
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
85
|
-
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
|
|
86
|
-
};
|
|
100
|
+
const lightSourceUniforms = {};
|
|
87
101
|
lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
|
|
88
102
|
let currentLight = 0;
|
|
89
103
|
for (const pointLight of pointLights) {
|
|
90
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;
|
|
91
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);
|
|
92
|
-
// lightSourceUniforms.lightPosition[currentLight] = pointLight.position;
|
|
93
|
-
// lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];
|
|
94
104
|
lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
|
|
95
|
-
|
|
96
|
-
lightSourceUniforms
|
|
97
|
-
lightSourceUniforms
|
|
105
|
+
const i = currentLight;
|
|
106
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
|
|
107
|
+
lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
|
|
108
|
+
lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0];
|
|
98
109
|
currentLight++;
|
|
99
110
|
}
|
|
100
111
|
for (const directionalLight of directionalLights) {
|
|
101
|
-
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;
|
|
102
|
-
// lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);
|
|
103
|
-
// lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;
|
|
104
|
-
// lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;
|
|
105
112
|
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
|
|
106
|
-
|
|
107
|
-
lightSourceUniforms
|
|
108
|
-
lightSourceUniforms
|
|
113
|
+
const i = currentLight;
|
|
114
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
115
|
+
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
109
116
|
currentLight++;
|
|
110
117
|
}
|
|
111
|
-
|
|
118
|
+
if (currentLight > MAX_LIGHTS) {
|
|
119
|
+
log.warn('MAX_LIGHTS exceeded')();
|
|
120
|
+
}
|
|
121
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
122
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
112
123
|
return lightSourceUniforms;
|
|
113
124
|
}
|
|
114
125
|
function extractLightTypes(lights) {
|
|
@@ -5,7 +5,7 @@ import { lighting } from "../lights/lighting-uniforms.js";
|
|
|
5
5
|
import { PHONG_VS, PHONG_FS } from "./phong-shaders-glsl.js";
|
|
6
6
|
/** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
|
|
7
7
|
export const phongMaterial = {
|
|
8
|
-
name: '
|
|
8
|
+
name: 'phongMaterial',
|
|
9
9
|
// Note these are switched between phong and gouraud
|
|
10
10
|
vs: PHONG_VS,
|
|
11
11
|
fs: PHONG_FS,
|
|
@@ -1,42 +1,3 @@
|
|
|
1
1
|
export declare const PHONG_VS: string;
|
|
2
2
|
export declare const PHONG_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
3
|
//# sourceMappingURL=phong-shaders-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,QA+CpB,CAAC"}
|
|
@@ -35,75 +35,18 @@ return lightColor;
|
|
|
35
35
|
}
|
|
36
36
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
37
37
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
38
|
-
|
|
39
|
-
PointLight pointLight = lighting_getPointLight(
|
|
38
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
39
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
40
40
|
vec3 light_position_worldspace = pointLight.position;
|
|
41
41
|
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
45
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
46
|
-
}
|
|
47
|
-
return lightColor;
|
|
42
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
43
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (lighting.enabled == 0) {
|
|
53
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
54
|
-
switch (lighting.lightType) {
|
|
55
|
-
case 0:
|
|
56
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
57
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
58
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
59
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
60
|
-
break;
|
|
61
|
-
case 1:
|
|
62
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
45
|
+
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
46
|
+
for (int i = lighting.pointLightCount; i < totalLights; i++) {
|
|
47
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
63
48
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
49
|
}
|
|
67
50
|
return lightColor;
|
|
68
51
|
}
|
|
69
52
|
`;
|
|
70
|
-
// TODO - handle multiple lights
|
|
71
|
-
/**
|
|
72
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
73
|
-
if (i >= lighting.pointLightCount) {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
77
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
78
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
79
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
83
|
-
if (i >= lighting.directionalLightCount) {
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
87
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
92
|
-
if (i >= lighting.pointLightCount) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
96
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
97
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
98
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
102
|
-
if (i >= lighting.directionalLightCount) {
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
106
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.20",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"@math.gl/types": "^4.0.0",
|
|
54
54
|
"wgsl_reflect": "^1.0.1"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "fa850b5d4b398f7168529543a24662bf9df4c68e"
|
|
57
57
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
6
|
import {lighting} from '../lights/lighting-uniforms';
|
|
7
|
-
import {
|
|
7
|
+
import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl';
|
|
8
8
|
|
|
9
9
|
export type GouraudMaterialProps = GouraudMaterialUniforms;
|
|
10
10
|
|
|
@@ -18,10 +18,10 @@ export type GouraudMaterialUniforms = {
|
|
|
18
18
|
|
|
19
19
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
20
20
|
export const gouraudMaterial: ShaderModule<GouraudMaterialProps, GouraudMaterialUniforms> = {
|
|
21
|
-
name: '
|
|
21
|
+
name: 'gouraudMaterial',
|
|
22
22
|
// Note these are switched between phong and gouraud
|
|
23
|
-
vs:
|
|
24
|
-
fs:
|
|
23
|
+
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
24
|
+
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
25
25
|
defines: {
|
|
26
26
|
LIGHTING_VERTEX: 1
|
|
27
27
|
},
|
|
@@ -25,28 +25,51 @@ struct DirectionalLight {
|
|
|
25
25
|
|
|
26
26
|
uniform lightingUniforms {
|
|
27
27
|
int enabled;
|
|
28
|
-
int
|
|
28
|
+
int lightType;
|
|
29
|
+
|
|
29
30
|
int directionalLightCount;
|
|
31
|
+
int pointLightCount;
|
|
30
32
|
|
|
31
33
|
vec3 ambientColor;
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
vec3
|
|
35
|
-
vec3
|
|
36
|
-
vec3
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
vec3 lightColor0;
|
|
36
|
+
vec3 lightPosition0;
|
|
37
|
+
vec3 lightDirection0;
|
|
38
|
+
vec3 lightAttenuation0;
|
|
39
|
+
|
|
40
|
+
vec3 lightColor1;
|
|
41
|
+
vec3 lightPosition1;
|
|
42
|
+
vec3 lightDirection1;
|
|
43
|
+
vec3 lightAttenuation1;
|
|
44
|
+
|
|
45
|
+
vec3 lightColor2;
|
|
46
|
+
vec3 lightPosition2;
|
|
47
|
+
vec3 lightDirection2;
|
|
48
|
+
vec3 lightAttenuation2;
|
|
42
49
|
} lighting;
|
|
43
50
|
|
|
44
51
|
PointLight lighting_getPointLight(int index) {
|
|
45
|
-
|
|
52
|
+
switch (index) {
|
|
53
|
+
case 0:
|
|
54
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
55
|
+
case 1:
|
|
56
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
57
|
+
case 2:
|
|
58
|
+
default:
|
|
59
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
60
|
+
}
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
49
|
-
|
|
64
|
+
switch (index) {
|
|
65
|
+
case 0:
|
|
66
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
67
|
+
case 1:
|
|
68
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
69
|
+
case 2:
|
|
70
|
+
default:
|
|
71
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
72
|
+
}
|
|
50
73
|
}
|
|
51
74
|
|
|
52
75
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|