@luma.gl/shadertools 9.1.0-alpha.16 → 9.1.0-alpha.18
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 +277 -344
- package/dist/dist.min.js +215 -314
- package/dist/index.cjs +276 -346
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/shader-module/shader-module.d.ts +24 -14
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +11 -15
- package/dist/lib/shader-module/shader-pass.d.ts +4 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -0
- package/dist/lib/utils/uniform-types.d.ts.map +1 -0
- package/dist/lib/utils/uniform-types.js +1 -0
- package/dist/modules/engine/picking/picking.d.ts +7 -7
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +2 -2
- package/dist/modules/engine/project/project.d.ts +9 -8
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +3 -57
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +9 -6
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +35 -12
- package/dist/modules/lighting/lights/lighting.d.ts +55 -29
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +46 -35
- package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +56 -60
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +56 -98
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +14 -22
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.js +24 -0
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +5 -59
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +6 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +8 -87
- package/dist/modules-webgl1/project/project.d.ts +6 -4
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.js +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +3 -0
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +3 -0
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +15 -11
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.js +24 -12
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +2 -2
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -3
- package/src/lib/shader-module/shader-module.ts +31 -20
- package/src/lib/shader-module/shader-pass.ts +7 -4
- package/src/lib/utils/uniform-types.ts +66 -0
- package/src/modules/engine/picking/picking.ts +9 -9
- package/src/modules/engine/project/project.ts +10 -9
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +14 -12
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
- package/src/modules/lighting/lights/lighting.ts +83 -54
- package/src/modules/lighting/no-material/dirlight.ts +3 -3
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
- package/src/modules/lighting/pbr-material/pbr-material.ts +40 -74
- package/src/modules/lighting/pbr-material/pbr-projection.ts +39 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
- package/src/modules/lighting/phong-material/phong-material.ts +12 -12
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -88
- package/src/modules-webgl1/project/project.ts +8 -7
- package/src/passes/postprocessing/fxaa/fxaa.ts +2 -2
- package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +0 -1
- package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +0 -1
- package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +3 -0
- package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +2 -2
- package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +1 -1
- package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/edgework.ts +26 -15
- package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/magnify.ts +2 -2
- package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +1 -1
- 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 -134
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -137
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/* eslint-disable camelcase */
|
|
6
|
+
|
|
7
|
+
import type {NumberArray3, NumberArray16} from '@math.gl/core';
|
|
8
|
+
|
|
9
|
+
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
10
|
+
|
|
11
|
+
const uniformBlock = /* glsl */ `\
|
|
12
|
+
uniform pbrProjectionUniforms {
|
|
13
|
+
mat4 modelViewProjectionMatrix;
|
|
14
|
+
mat4 modelMatrix;
|
|
15
|
+
mat4 normalMatrix;
|
|
16
|
+
vec3 camera;
|
|
17
|
+
} pbrProjection;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export type PBRProjectionProps = {
|
|
21
|
+
modelViewProjectionMatrix: NumberArray16;
|
|
22
|
+
modelMatrix: NumberArray16;
|
|
23
|
+
normalMatrix: NumberArray16;
|
|
24
|
+
camera: NumberArray3;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const pbrProjection: ShaderModule<PBRProjectionProps> = {
|
|
28
|
+
name: 'pbrProjection',
|
|
29
|
+
vs: uniformBlock,
|
|
30
|
+
fs: uniformBlock,
|
|
31
|
+
// TODO why is this needed?
|
|
32
|
+
getUniforms: props => props,
|
|
33
|
+
uniformTypes: {
|
|
34
|
+
modelViewProjectionMatrix: 'mat4x4<f32>',
|
|
35
|
+
modelMatrix: 'mat4x4<f32>',
|
|
36
|
+
normalMatrix: 'mat4x4<f32>',
|
|
37
|
+
camera: 'vec3<i32>'
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -3,38 +3,30 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
export const vs = /* glsl */ `\
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
mat4 u_ModelMatrix;
|
|
9
|
-
mat4 u_NormalMatrix;
|
|
10
|
-
// Projection
|
|
11
|
-
vec3 u_Camera;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
varying vec3 pbr_vPosition;
|
|
15
|
-
varying vec2 pbr_vUV;
|
|
6
|
+
out vec3 pbr_vPosition;
|
|
7
|
+
out vec2 pbr_vUV;
|
|
16
8
|
|
|
17
9
|
#ifdef HAS_NORMALS
|
|
18
10
|
# ifdef HAS_TANGENTS
|
|
19
|
-
|
|
11
|
+
out mat3 pbr_vTBN;
|
|
20
12
|
# else
|
|
21
|
-
|
|
13
|
+
out vec3 pbr_vNormal;
|
|
22
14
|
# endif
|
|
23
15
|
#endif
|
|
24
16
|
|
|
25
17
|
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
26
18
|
{
|
|
27
|
-
vec4 pos =
|
|
19
|
+
vec4 pos = pbrProjection.modelMatrix * position;
|
|
28
20
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
29
21
|
|
|
30
22
|
#ifdef HAS_NORMALS
|
|
31
23
|
#ifdef HAS_TANGENTS
|
|
32
|
-
vec3 normalW = normalize(vec3(
|
|
33
|
-
vec3 tangentW = normalize(vec3(
|
|
24
|
+
vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
25
|
+
vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
34
26
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
35
27
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
36
28
|
#else // HAS_TANGENTS != 1
|
|
37
|
-
pbr_vNormal = normalize(vec3(
|
|
29
|
+
pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
38
30
|
#endif
|
|
39
31
|
#endif
|
|
40
32
|
|
|
@@ -2,27 +2,23 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {NumberArray3} from '@math.gl/types';
|
|
5
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
7
|
import {lighting} from '../lights/lighting';
|
|
7
8
|
import {PHONG_WGSL} from './phong-shaders-wgsl';
|
|
8
9
|
import {PHONG_VS, PHONG_FS} from './phong-shaders-glsl';
|
|
9
10
|
|
|
10
|
-
export type PhongMaterialProps =
|
|
11
|
-
|
|
12
|
-
export type PhongMaterialUniforms = {
|
|
11
|
+
export type PhongMaterialProps = {
|
|
13
12
|
ambient?: number;
|
|
14
13
|
diffuse?: number;
|
|
15
14
|
/** Specularity exponent */
|
|
16
15
|
shininess?: number;
|
|
17
|
-
specularColor?:
|
|
16
|
+
specularColor?: NumberArray3;
|
|
18
17
|
};
|
|
19
18
|
|
|
20
19
|
/** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
|
|
21
|
-
export const phongMaterial = {
|
|
22
|
-
|
|
23
|
-
uniforms: {} as PhongMaterialUniforms,
|
|
24
|
-
|
|
25
|
-
name: 'phong-lighting',
|
|
20
|
+
export const phongMaterial: ShaderModule<PhongMaterialProps> = {
|
|
21
|
+
name: 'phongMaterial',
|
|
26
22
|
dependencies: [lighting],
|
|
27
23
|
// Note these are switched between phong and gouraud
|
|
28
24
|
source: PHONG_WGSL,
|
|
@@ -43,7 +39,11 @@ export const phongMaterial = {
|
|
|
43
39
|
shininess: 32,
|
|
44
40
|
specularColor: [0.15, 0.15, 0.15]
|
|
45
41
|
},
|
|
46
|
-
getUniforms(props?: PhongMaterialProps)
|
|
47
|
-
|
|
42
|
+
getUniforms(props?: PhongMaterialProps) {
|
|
43
|
+
const uniforms = {...props};
|
|
44
|
+
if (uniforms.specularColor) {
|
|
45
|
+
uniforms.specularColor = uniforms.specularColor.map(x => x / 255) as NumberArray3;
|
|
46
|
+
}
|
|
47
|
+
return {...phongMaterial.defaultUniforms, ...uniforms};
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
};
|
|
@@ -41,100 +41,20 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
41
41
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
42
42
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
PointLight pointLight = lighting_getPointLight(
|
|
44
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
45
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
46
46
|
vec3 light_position_worldspace = pointLight.position;
|
|
47
47
|
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
51
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
56
|
-
if (i >= lighting.pointLightCount) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
60
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
61
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
62
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
48
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
49
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
63
50
|
}
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
52
|
+
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
53
|
+
for (int i = lighting.pointLightCount; i < totalLights; i++) {
|
|
54
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
70
55
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
71
56
|
}
|
|
72
|
-
|
|
73
|
-
return lightColor;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
77
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
78
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
79
|
-
|
|
80
|
-
if (lighting.enabled == 0) {
|
|
81
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
82
|
-
|
|
83
|
-
switch (lighting.lightType) {
|
|
84
|
-
case 0:
|
|
85
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
86
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
87
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
88
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
89
|
-
break;
|
|
90
|
-
|
|
91
|
-
case 1:
|
|
92
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
93
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
57
|
+
|
|
97
58
|
return lightColor;
|
|
98
59
|
}
|
|
99
60
|
`;
|
|
100
|
-
|
|
101
|
-
// TODO - handle multiple lights
|
|
102
|
-
/**
|
|
103
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
104
|
-
if (i >= lighting.pointLightCount) {
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
108
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
109
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
110
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
114
|
-
if (i >= lighting.directionalLightCount) {
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
118
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
123
|
-
if (i >= lighting.pointLightCount) {
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
127
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
128
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
129
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
133
|
-
if (i >= lighting.directionalLightCount) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
137
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
*/
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Matrix4} from '@math.gl/core';
|
|
5
|
+
import {Vector3, Matrix4} from '@math.gl/core';
|
|
6
6
|
import {ShaderModule} from '../../lib/shader-module/shader-module';
|
|
7
|
+
import type {NumberArray3, NumberArray16} from '@math.gl/core';
|
|
7
8
|
|
|
8
9
|
type ProjectionProps = {
|
|
9
|
-
modelMatrix?:
|
|
10
|
-
viewMatrix?:
|
|
11
|
-
projectionMatrix?:
|
|
12
|
-
cameraPositionWorld?:
|
|
10
|
+
modelMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
11
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
12
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
13
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
16
|
+
const IDENTITY_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
16
17
|
|
|
17
|
-
const DEFAULT_MODULE_OPTIONS = {
|
|
18
|
+
const DEFAULT_MODULE_OPTIONS: ProjectionProps = {
|
|
18
19
|
modelMatrix: IDENTITY_MATRIX,
|
|
19
20
|
viewMatrix: IDENTITY_MATRIX,
|
|
20
21
|
projectionMatrix: IDENTITY_MATRIX,
|
|
@@ -97,7 +97,7 @@ import {ShaderPass} from '../../../lib/shader-module/shader-pass';
|
|
|
97
97
|
// _ = the highest digit is directly related to style
|
|
98
98
|
//
|
|
99
99
|
|
|
100
|
-
const fs = `
|
|
100
|
+
const fs = /* glsl */ `
|
|
101
101
|
#define FXAA_QUALITY_PRESET 29
|
|
102
102
|
|
|
103
103
|
#if (FXAA_QUALITY_PRESET == 10)
|
|
@@ -691,4 +691,4 @@ export const fxaa = {
|
|
|
691
691
|
fs,
|
|
692
692
|
passes: [{sampler: true}],
|
|
693
693
|
getUniforms: props => props
|
|
694
|
-
} as const satisfies ShaderPass<FXAAProps, FXAAUniforms>;
|
|
694
|
+
} as const satisfies ShaderPass<FXAAProps, FXAAUniforms, {}>;
|
|
@@ -57,9 +57,9 @@ vec4 tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
57
57
|
*/
|
|
58
58
|
export type TiltShiftProps = {
|
|
59
59
|
/** The x,y coordinate of the start of the line segment. */
|
|
60
|
-
start?: number
|
|
60
|
+
start?: [number, number];
|
|
61
61
|
/** The xm y coordinate of the end of the line segment. */
|
|
62
|
-
end?: number
|
|
62
|
+
end?: [number, number];
|
|
63
63
|
/** The maximum radius of the pyramid blur. */
|
|
64
64
|
blurRadius?: number;
|
|
65
65
|
/** The distance from the line at which the maximum blur radius is reached. */
|
|
@@ -51,7 +51,7 @@ export type TriangleBlurProps = {
|
|
|
51
51
|
/** The radius of the pyramid convolved with the image. */
|
|
52
52
|
radius?: number;
|
|
53
53
|
/** @deprecated internal property */
|
|
54
|
-
delta?: number
|
|
54
|
+
delta?: [number, number];
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
export type TriangleBlurUniforms = TriangleBlurProps;
|
|
@@ -45,7 +45,7 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
45
45
|
*/
|
|
46
46
|
export type ZoomBlurProps = {
|
|
47
47
|
/** - The x, y coordinate of the blur origin. */
|
|
48
|
-
center?: number
|
|
48
|
+
center?: [number, number];
|
|
49
49
|
/** - The strength of the blur. Values in the range 0 to 1 are usually sufficient, where 0 doesn't change the image and 1 creates a highly blurred image. */
|
|
50
50
|
strength?: number;
|
|
51
51
|
};
|
|
@@ -50,7 +50,7 @@ vec4 colorHalftone_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
|
50
50
|
*/
|
|
51
51
|
export type ColorHalftoneProps = {
|
|
52
52
|
/** The x,y coordinate of the pattern origin. */
|
|
53
|
-
center?: number
|
|
53
|
+
center?: [number, number];
|
|
54
54
|
/** The rotation of the pattern in radians. */
|
|
55
55
|
angle?: number;
|
|
56
56
|
/** The diameter of a dot in pixels. */
|
|
@@ -36,7 +36,7 @@ vec4 dotScreen_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
|
36
36
|
*/
|
|
37
37
|
export type DotScreenProps = {
|
|
38
38
|
/** The x, y coordinate of the pattern origin. */
|
|
39
|
-
center?: number
|
|
39
|
+
center?: [number, number];
|
|
40
40
|
/** The rotation of the pattern in radians. */
|
|
41
41
|
angle?: number;
|
|
42
42
|
/** The diameter of a dot in pixels. */
|
|
@@ -8,11 +8,11 @@ import {random} from '../../../modules/math/random/random';
|
|
|
8
8
|
const fs = /* glsl */ `\
|
|
9
9
|
uniform edgeWorkUniforms {
|
|
10
10
|
float radius;
|
|
11
|
-
|
|
11
|
+
int mode;
|
|
12
12
|
} edgeWork;
|
|
13
13
|
|
|
14
|
-
vec4
|
|
15
|
-
vec2 relativeDelta = edgeWork.radius *
|
|
14
|
+
vec4 edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
|
|
15
|
+
vec2 relativeDelta = edgeWork.radius * delta / texSize;
|
|
16
16
|
|
|
17
17
|
vec2 color = vec2(0.0);
|
|
18
18
|
vec2 total = vec2(0.0);
|
|
@@ -36,8 +36,8 @@ vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
36
36
|
return vec4(color / total, 0.0, 1.0);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
vec4
|
|
40
|
-
vec2 relativeDelta = edgeWork.radius *
|
|
39
|
+
vec4 edgeWork_sampleColorXY(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
|
|
40
|
+
vec2 relativeDelta = edgeWork.radius * delta / texSize;
|
|
41
41
|
|
|
42
42
|
vec2 color = vec2(0.0);
|
|
43
43
|
vec2 total = vec2(0.0);
|
|
@@ -60,6 +60,16 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
60
60
|
float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
|
|
61
61
|
return vec4(c, c, c, 1.0);
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
vec4 edgeWork_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
65
|
+
switch (edgeWork.mode) {
|
|
66
|
+
case 0:
|
|
67
|
+
return edgeWork_sampleColorRGB(source, texSize, texCoord, vec2(1., 0.));
|
|
68
|
+
case 1:
|
|
69
|
+
default:
|
|
70
|
+
return edgeWork_sampleColorXY(source, texSize, texCoord, vec2(0., 1.));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
63
73
|
`;
|
|
64
74
|
|
|
65
75
|
/**
|
|
@@ -70,8 +80,8 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
70
80
|
export type EdgeWorkProps = {
|
|
71
81
|
/** radius The radius of the effect in pixels. */
|
|
72
82
|
radius?: number;
|
|
73
|
-
/** @deprecated
|
|
74
|
-
|
|
83
|
+
/** @deprecated xy or RGB */
|
|
84
|
+
mode?: 0 | 1;
|
|
75
85
|
};
|
|
76
86
|
|
|
77
87
|
export type EdgeWorkUniforms = EdgeWorkProps;
|
|
@@ -88,22 +98,23 @@ export const edgeWork = {
|
|
|
88
98
|
name: 'edgeWork',
|
|
89
99
|
dependencies: [random],
|
|
90
100
|
fs,
|
|
91
|
-
|
|
101
|
+
uniformTypes: {
|
|
102
|
+
radius: 'f32',
|
|
103
|
+
mode: 'i32'
|
|
104
|
+
},
|
|
92
105
|
propTypes: {
|
|
93
106
|
radius: {value: 2, min: 1, softMax: 50},
|
|
94
|
-
|
|
107
|
+
mode: {value: 0, private: true}
|
|
95
108
|
},
|
|
96
109
|
|
|
97
110
|
passes: [
|
|
98
111
|
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
propTypes: {delta: [1, 0]}
|
|
112
|
+
sampler: true,
|
|
113
|
+
uniforms: {mode: 0}
|
|
102
114
|
},
|
|
103
115
|
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
propTypes: {delta: [0, 1]}
|
|
116
|
+
sampler: true,
|
|
117
|
+
uniforms: {mode: 1}
|
|
107
118
|
}
|
|
108
119
|
]
|
|
109
120
|
} as const satisfies ShaderPass<EdgeWorkProps, EdgeWorkProps>;
|
|
@@ -56,7 +56,7 @@ vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord
|
|
|
56
56
|
*/
|
|
57
57
|
export type HexagonalPixelateProps = {
|
|
58
58
|
/** The [x, y] coordinates of the pattern center. */
|
|
59
|
-
center?: number
|
|
59
|
+
center?: [number, number];
|
|
60
60
|
/** The width of an individual tile, in pixels. */
|
|
61
61
|
scale?: number;
|
|
62
62
|
};
|
|
@@ -32,7 +32,7 @@ vec4 magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
32
32
|
*/
|
|
33
33
|
export type MagnifyProps = {
|
|
34
34
|
/** x, y position in screen coords, both x and y is normalized and in range `[0, 1]`. `[0, 0]` is the up left corner, `[1, 1]` is the bottom right corner. Default value is `[0, 0]`. */
|
|
35
|
-
screenXY?: number
|
|
35
|
+
screenXY?: [number, number];
|
|
36
36
|
/** effect radius in pixels. Default value is `100`. */
|
|
37
37
|
radiusPixels?: number;
|
|
38
38
|
/** magnify level. Default value is `2`. */
|
|
@@ -40,7 +40,7 @@ export type MagnifyProps = {
|
|
|
40
40
|
/** border width of the effect circle, will not show border if value <= 0.0. Default value is `0`. */
|
|
41
41
|
borderWidthPixels?: number;
|
|
42
42
|
/** border color of the effect circle. Default value is `[255, 255, 255, 255]`. */
|
|
43
|
-
borderColor?: number
|
|
43
|
+
borderColor?: [number, number, number, number];
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export type MagnifyUniforms = MagnifyProps;
|
|
@@ -38,7 +38,7 @@ vec4 bulgePinch_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
38
38
|
/** Bulges or pinches the image in a circle. */
|
|
39
39
|
export type BulgePinchProps = {
|
|
40
40
|
/** The [x, y] coordinates of the center of the circle of effect. */
|
|
41
|
-
center?: number
|
|
41
|
+
center?: [number, number];
|
|
42
42
|
/** The radius of the circle of effect. */
|
|
43
43
|
radius?: number;
|
|
44
44
|
/** strength -1 to 1 (-1 is strong pinch, 0 is no effect, 1 is strong bulge) */
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export declare const GOURAUD_VS = "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
|
|
2
|
-
export declare const GOURAUD_FS = "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction);\n float lambertian = dot(light_direction, normal_worldspace);\n float specular = 0.0;\n if (lambertian > 0.0) {\n float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (lighting.enabled) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n }\n return lightColor;\n}\n\nvec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = vec3(0, 0, 0);\n vec3 surfaceColor = vec3(0, 0, 0);\n\n if (lighting.enabled) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0:\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n break;\n\n case 1:\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n break;\n }\n }\n return lightColor;\n}\n";
|
|
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":"AAIA,eAAO,MAAM,UAAU,8JAOtB,CAAC;AAEF,eAAO,MAAM,UAAU,ihHAkFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|