@luma.gl/shadertools 9.0.17 → 9.0.19
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 +87 -75
- package/dist/dist.min.js +21 -18
- package/dist/index.cjs +31 -24
- package/dist/index.cjs.map +2 -2
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +15 -13
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +3 -3
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +2 -1
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +8 -5
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +2 -1
- package/package.json +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +57 -52
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +4 -3
- package/src/modules/lighting/lights/lighting-uniforms.ts +14 -6
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +16 -14
|
@@ -5,7 +5,7 @@ import { lighting } from "../lights/lighting-uniforms.js";
|
|
|
5
5
|
import { GOURAUD_VS, GOURAUD_FS } from "./gouraud-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
10
|
vs: GOURAUD_VS,
|
|
11
11
|
fs: GOURAUD_FS,
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -3,15 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
5
|
export const GOURAUD_VS = `\
|
|
6
|
-
uniform
|
|
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 {
|
|
6
|
+
uniform gouraudMaterialUniforms {
|
|
15
7
|
uniform float ambient;
|
|
16
8
|
uniform float diffuse;
|
|
17
9
|
uniform float shininess;
|
|
@@ -30,7 +22,9 @@ return (lambertian * material.diffuse * surfaceColor + specular * material.specu
|
|
|
30
22
|
}
|
|
31
23
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
32
24
|
vec3 lightColor = surfaceColor;
|
|
33
|
-
if (lighting.enabled) {
|
|
25
|
+
if (lighting.enabled == 0) {
|
|
26
|
+
return lightColor;
|
|
27
|
+
}
|
|
34
28
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
35
29
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
36
30
|
if (lighting.lightType == 0) {
|
|
@@ -42,13 +36,14 @@ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_directi
|
|
|
42
36
|
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
43
37
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
44
38
|
}
|
|
45
|
-
}
|
|
46
39
|
return lightColor;
|
|
47
40
|
}
|
|
48
41
|
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
49
42
|
vec3 lightColor = vec3(0, 0, 0);
|
|
50
43
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
51
|
-
if (lighting.enabled) {
|
|
44
|
+
if (lighting.enabled == 0) {
|
|
45
|
+
return lightColor;
|
|
46
|
+
}
|
|
52
47
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
53
48
|
switch (lighting.lightType) {
|
|
54
49
|
case 0:
|
|
@@ -62,10 +57,17 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
62
57
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
63
58
|
break;
|
|
64
59
|
}
|
|
65
|
-
}
|
|
66
60
|
return lightColor;
|
|
67
61
|
}
|
|
68
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
|
+
`;
|
|
69
71
|
// TODO - handle multiple lights
|
|
70
72
|
/**
|
|
71
73
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
@@ -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,QAqD5B,CAAC"}
|
|
@@ -18,13 +18,13 @@ 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
|
-
int lightType;
|
|
25
25
|
vec3 lightColor;
|
|
26
|
-
vec3 lightDirection;
|
|
27
26
|
vec3 lightPosition;
|
|
27
|
+
vec3 lightDirection;
|
|
28
28
|
vec3 lightAttenuation;
|
|
29
29
|
} lighting;
|
|
30
30
|
PointLight lighting_getPointLight(int index) {
|
|
@@ -34,7 +34,8 @@ export type LightingProps = {
|
|
|
34
34
|
export type LightingUniforms = {
|
|
35
35
|
enabled: number;
|
|
36
36
|
ambientLightColor: Readonly<NumberArray3>;
|
|
37
|
-
|
|
37
|
+
directionalLightCount: number;
|
|
38
|
+
pointLightCount: number;
|
|
38
39
|
lightType: number;
|
|
39
40
|
lightColor: Readonly<NumberArray3>;
|
|
40
41
|
lightPosition: Readonly<NumberArray3>;
|
|
@@ -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;AAcnE,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG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AAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACnC,aAAa,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACtC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,gBAAgB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CAC1C,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,aAAa,EAAE,gBAAgB,EAAE,EAAE,CA0CtE,CAAC"}
|
|
@@ -25,9 +25,10 @@ export const lighting = {
|
|
|
25
25
|
},
|
|
26
26
|
uniformTypes: {
|
|
27
27
|
enabled: 'i32',
|
|
28
|
-
ambientLightColor: 'vec3<f32>',
|
|
29
|
-
numberOfLights: 'i32', // , array: MAX_LIGHTS,
|
|
30
28
|
lightType: 'i32', // , array: MAX_LIGHTS,
|
|
29
|
+
directionalLightCount: 'i32', // , array: MAX_LIGHTS,
|
|
30
|
+
pointLightCount: 'i32', // , array: MAX_LIGHTS,
|
|
31
|
+
ambientLightColor: 'vec3<f32>',
|
|
31
32
|
lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,
|
|
32
33
|
lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,
|
|
33
34
|
// TODO - could combine direction and attenuation
|
|
@@ -36,9 +37,10 @@ export const lighting = {
|
|
|
36
37
|
},
|
|
37
38
|
defaultUniforms: {
|
|
38
39
|
enabled: 1,
|
|
39
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
40
|
-
numberOfLights: 0,
|
|
41
40
|
lightType: LIGHT_TYPE.POINT,
|
|
41
|
+
directionalLightCount: 0,
|
|
42
|
+
pointLightCount: 0,
|
|
43
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
42
44
|
lightColor: [1, 1, 1],
|
|
43
45
|
lightPosition: [1, 1, 2],
|
|
44
46
|
// TODO - could combine direction and attenuation
|
|
@@ -108,7 +110,8 @@ function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLig
|
|
|
108
110
|
lightSourceUniforms.lightDirection = directionalLight.direction;
|
|
109
111
|
currentLight++;
|
|
110
112
|
}
|
|
111
|
-
lightSourceUniforms.
|
|
113
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
114
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
112
115
|
return lightSourceUniforms;
|
|
113
116
|
}
|
|
114
117
|
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 +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,QAuFpB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|
|
@@ -50,6 +50,8 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
50
50
|
vec3 lightColor = vec3(0, 0, 0);
|
|
51
51
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
52
52
|
if (lighting.enabled == 0) {
|
|
53
|
+
return lightColor;
|
|
54
|
+
}
|
|
53
55
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
54
56
|
switch (lighting.lightType) {
|
|
55
57
|
case 0:
|
|
@@ -63,7 +65,6 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
63
65
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
64
66
|
break;
|
|
65
67
|
}
|
|
66
|
-
}
|
|
67
68
|
return lightColor;
|
|
68
69
|
}
|
|
69
70
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.19",
|
|
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": "5e1ede7bdaf2c9ccdbd167804601537e93dc4225"
|
|
57
57
|
}
|
|
@@ -18,7 +18,7 @@ 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
23
|
vs: GOURAUD_VS,
|
|
24
24
|
fs: GOURAUD_FS,
|
|
@@ -5,16 +5,7 @@
|
|
|
5
5
|
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
6
6
|
|
|
7
7
|
export const GOURAUD_VS = glsl`\
|
|
8
|
-
uniform
|
|
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 {
|
|
8
|
+
uniform gouraudMaterialUniforms {
|
|
18
9
|
uniform float ambient;
|
|
19
10
|
uniform float diffuse;
|
|
20
11
|
uniform float shininess;
|
|
@@ -36,39 +27,41 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
|
|
|
36
27
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
37
28
|
vec3 lightColor = surfaceColor;
|
|
38
29
|
|
|
39
|
-
if (lighting.enabled) {
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
if (lighting.enabled == 0) {
|
|
31
|
+
return lightColor;
|
|
32
|
+
}
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
60
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
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;
|
|
61
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
|
+
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
68
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
57
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
58
|
+
if (i >= lighting.directionalLightCount) {
|
|
59
|
+
break;
|
|
69
60
|
}
|
|
70
|
-
|
|
61
|
+
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
62
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
71
63
|
}
|
|
64
|
+
*/
|
|
72
65
|
return lightColor;
|
|
73
66
|
}
|
|
74
67
|
|
|
@@ -76,27 +69,39 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
76
69
|
vec3 lightColor = vec3(0, 0, 0);
|
|
77
70
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
78
71
|
|
|
79
|
-
if (lighting.enabled) {
|
|
80
|
-
|
|
72
|
+
if (lighting.enabled == 0) {
|
|
73
|
+
return lightColor;
|
|
74
|
+
}
|
|
81
75
|
|
|
82
|
-
|
|
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;
|
|
76
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
89
77
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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;
|
|
95
90
|
}
|
|
91
|
+
|
|
96
92
|
return lightColor;
|
|
97
93
|
}
|
|
98
94
|
`;
|
|
99
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
|
+
|
|
100
105
|
// TODO - handle multiple lights
|
|
101
106
|
/**
|
|
102
107
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
@@ -25,15 +25,16 @@ 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
|
-
int lightType;
|
|
34
35
|
vec3 lightColor;
|
|
35
|
-
vec3 lightDirection;
|
|
36
36
|
vec3 lightPosition;
|
|
37
|
+
vec3 lightDirection;
|
|
37
38
|
vec3 lightAttenuation;
|
|
38
39
|
|
|
39
40
|
// AmbientLight ambientLight;
|
|
@@ -58,7 +58,8 @@ 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
|
lightColor: Readonly<NumberArray3>; // [];
|
|
64
65
|
lightPosition: Readonly<NumberArray3>; // [];
|
|
@@ -82,9 +83,12 @@ export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
|
82
83
|
|
|
83
84
|
uniformTypes: {
|
|
84
85
|
enabled: 'i32',
|
|
85
|
-
ambientLightColor: 'vec3<f32>',
|
|
86
|
-
numberOfLights: 'i32', // , array: MAX_LIGHTS,
|
|
87
86
|
lightType: 'i32', // , array: MAX_LIGHTS,
|
|
87
|
+
|
|
88
|
+
directionalLightCount: 'i32', // , array: MAX_LIGHTS,
|
|
89
|
+
pointLightCount: 'i32', // , array: MAX_LIGHTS,
|
|
90
|
+
|
|
91
|
+
ambientLightColor: 'vec3<f32>',
|
|
88
92
|
lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,
|
|
89
93
|
lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,
|
|
90
94
|
// TODO - could combine direction and attenuation
|
|
@@ -94,9 +98,12 @@ export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
|
94
98
|
|
|
95
99
|
defaultUniforms: {
|
|
96
100
|
enabled: 1,
|
|
97
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
98
|
-
numberOfLights: 0,
|
|
99
101
|
lightType: LIGHT_TYPE.POINT,
|
|
102
|
+
|
|
103
|
+
directionalLightCount: 0,
|
|
104
|
+
pointLightCount: 0,
|
|
105
|
+
|
|
106
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
100
107
|
lightColor: [1, 1, 1],
|
|
101
108
|
lightPosition: [1, 1, 2],
|
|
102
109
|
// TODO - could combine direction and attenuation
|
|
@@ -187,7 +194,8 @@ function getLightSourceUniforms({
|
|
|
187
194
|
currentLight++;
|
|
188
195
|
}
|
|
189
196
|
|
|
190
|
-
lightSourceUniforms.
|
|
197
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
198
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
191
199
|
|
|
192
200
|
return lightSourceUniforms;
|
|
193
201
|
}
|
|
@@ -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,
|
|
@@ -80,21 +80,23 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
80
80
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
81
81
|
|
|
82
82
|
if (lighting.enabled == 0) {
|
|
83
|
-
|
|
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;
|
|
83
|
+
return lightColor;
|
|
84
|
+
}
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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;
|
|
98
100
|
}
|
|
99
101
|
return lightColor;
|
|
100
102
|
}
|