@geoblocks/cesium-post-process 0.0.0-stage → 0.1.0

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.
Files changed (83) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +235 -2
  3. package/analog-video.js +138 -0
  4. package/blur.js +39 -0
  5. package/cesium-post-process.js +23 -0
  6. package/color-isolation.js +69 -0
  7. package/depth-test.js +37 -0
  8. package/digital-video.js +108 -0
  9. package/drone-display.js +170 -0
  10. package/focus.js +25 -0
  11. package/frame-clock.js +61 -0
  12. package/height.js +23 -0
  13. package/infrared.js +40 -0
  14. package/jello.js +146 -0
  15. package/lens-distortion.js +68 -0
  16. package/lightning.js +321 -0
  17. package/motion-blur.js +117 -0
  18. package/package.json +49 -4
  19. package/precipitation.js +493 -0
  20. package/shaders/Alpenglow.js +2 -0
  21. package/shaders/AnalogVideo.js +2 -0
  22. package/shaders/Beam.js +2 -0
  23. package/shaders/CloudsBlur.js +2 -0
  24. package/shaders/CloudsComposite.js +2 -0
  25. package/shaders/CloudsDensity.js +2 -0
  26. package/shaders/CloudsDepth.js +2 -0
  27. package/shaders/CloudsMarch.js +2 -0
  28. package/shaders/CloudsResolve.js +2 -0
  29. package/shaders/CloudsShadow.js +2 -0
  30. package/shaders/CloudsShadowMap.js +2 -0
  31. package/shaders/CloudsSlab.js +2 -0
  32. package/shaders/ColorIsolation.js +2 -0
  33. package/shaders/DepthEdges.js +2 -0
  34. package/shaders/DigitalVideo.js +2 -0
  35. package/shaders/DroneDisplay.js +2 -0
  36. package/shaders/EyeFromDepth.js +2 -0
  37. package/shaders/Filmic.js +2 -0
  38. package/shaders/Flashlight.js +2 -0
  39. package/shaders/Fog.js +2 -0
  40. package/shaders/Frame.js +2 -0
  41. package/shaders/Hash.js +2 -0
  42. package/shaders/Height.js +2 -0
  43. package/shaders/Hsl.js +2 -0
  44. package/shaders/Infrared.js +2 -0
  45. package/shaders/Jello.js +2 -0
  46. package/shaders/LensDistortion.js +2 -0
  47. package/shaders/Lightning.js +2 -0
  48. package/shaders/MotionBlur.js +2 -0
  49. package/shaders/MotionBlurVelocity.js +2 -0
  50. package/shaders/Noise.js +2 -0
  51. package/shaders/Normal.js +2 -0
  52. package/shaders/Phase.js +2 -0
  53. package/shaders/Precipitation.js +2 -0
  54. package/shaders/PrecipitationShaftBlur.js +2 -0
  55. package/shaders/PrecipitationShafts.js +2 -0
  56. package/shaders/PrecipitationWind.js +2 -0
  57. package/shaders/RainHaze.js +2 -0
  58. package/shaders/Shockwave.js +2 -0
  59. package/shaders/SkyTable.js +2 -0
  60. package/shaders/SnowLine.js +2 -0
  61. package/shaders/SpeedLines.js +2 -0
  62. package/shaders/Spotlight.js +2 -0
  63. package/shaders/SpotlightBeam.js +2 -0
  64. package/shaders/SpotlightBeamBlur.js +2 -0
  65. package/shaders/SpotlightCone.js +2 -0
  66. package/shaders/Super8.js +2 -0
  67. package/shaders/Technicolor.js +2 -0
  68. package/shaders/TiltShift.js +2 -0
  69. package/shaders/Toy.js +2 -0
  70. package/shaders/Trails.js +2 -0
  71. package/shaders/ValleyFog.js +2 -0
  72. package/shaders/WeatherMap.js +2 -0
  73. package/shaders/WhiteModel.js +2 -0
  74. package/snow-line.js +108 -0
  75. package/speed-lines.js +71 -0
  76. package/spotlight.js +193 -0
  77. package/strikes.js +30 -0
  78. package/super8.js +164 -0
  79. package/technicolor.js +56 -0
  80. package/tilt-shift.js +124 -0
  81. package/toy.js +192 -0
  82. package/valley-fog.js +105 -0
  83. package/white-model.js +105 -0
package/toy.js ADDED
@@ -0,0 +1,192 @@
1
+ import {Cartesian3, Cartesian4} from '@cesium/core';
2
+ import {PostProcessStage} from '@cesium/engine';
3
+ import {acquireTerrainDepth, releaseTerrainDepth} from './depth-test.js';
4
+ import Effect from './effect.js';
5
+ import DepthEdges from './shaders/DepthEdges.js';
6
+ import EyeFromDepth from './shaders/EyeFromDepth.js';
7
+ import ToyShader from './shaders/Toy.js';
8
+
9
+ const NO_SKY = new Cartesian4(0, 0, 0, 0);
10
+ const warmScratch = new Cartesian3();
11
+ const skyTopScratch = new Cartesian4();
12
+ const skyBottomScratch = new Cartesian4();
13
+
14
+ /**
15
+ * A toy's look, as an isometric game's: the edges lit where the surface bends
16
+ * outward and shaded where it bends inward, rounded close up, the silhouettes
17
+ * outlined in a darker shade of their color, the colors a little richer and
18
+ * warmer, the sky a soft gradient if asked.
19
+ */
20
+ export default class Toy extends Effect {
21
+ /**
22
+ * @param {import('@cesium/engine').CesiumWidget} viewer
23
+ * @param {{light?: number, shade?: number, bevel?: number, outline?: number, jump?: number, saturation?: number, warm?: [number, number, number], sky?: [import('@cesium/core').Color, import('@cesium/core').Color]}} [options]
24
+ */
25
+ constructor(viewer, options = {}) {
26
+ super(viewer);
27
+ this.light_ = options.light ?? 0.22;
28
+ this.shade_ = options.shade ?? 0.18;
29
+ this.bevel_ = options.bevel ?? 0;
30
+ this.outline_ = options.outline ?? 0.4;
31
+ this.jump_ = options.jump ?? 20;
32
+ this.saturation_ = options.saturation ?? 1.04;
33
+ this.warm_ = options.warm ?? [1.03, 1, 0.95];
34
+ this.sky_ = options.sky;
35
+ }
36
+
37
+ /**
38
+ * @override
39
+ * @param {import('@cesium/engine').Scene} _scene
40
+ */
41
+ createStage_(_scene) {
42
+ return new PostProcessStage({fragmentShader: EyeFromDepth + DepthEdges + this.shader_(), uniforms: this.uniforms_()});
43
+ }
44
+
45
+ /**
46
+ * The look's shader, after DepthEdges.
47
+ * @protected
48
+ * @return {string}
49
+ */
50
+ shader_() {
51
+ return ToyShader;
52
+ }
53
+
54
+ /**
55
+ * The shader's uniforms.
56
+ * @protected
57
+ * @return {Object<string, () => any>}
58
+ */
59
+ uniforms_() {
60
+ const color = (/** @type {import('@cesium/core').Color} */ c, /** @type {Cartesian4} */ result) => Cartesian4.fromElements(c.red, c.green, c.blue, 1, result);
61
+ return {
62
+ light: () => this.light_,
63
+ shade: () => this.shade_,
64
+ bevel: () => this.bevel_,
65
+ outline: () => this.outline_,
66
+ jump: () => this.jump_,
67
+ saturation: () => this.saturation_,
68
+ warm: () => Cartesian3.fromArray(this.warm_, 0, warmScratch),
69
+ skyTop: () => this.sky_ ? color(this.sky_[0], skyTopScratch) : NO_SKY,
70
+ skyBottom: () => this.sky_ ? color(this.sky_[1], skyBottomScratch) : NO_SKY,
71
+ };
72
+ }
73
+
74
+ /**
75
+ * @override
76
+ * @param {import('@cesium/engine').Scene} scene
77
+ */
78
+ activated_(scene) {
79
+ acquireTerrainDepth(scene);
80
+ }
81
+
82
+ /**
83
+ * @override
84
+ * @param {import('@cesium/engine').Scene} scene
85
+ */
86
+ deactivating_(scene) {
87
+ releaseTerrainDepth(scene);
88
+ }
89
+
90
+ /**
91
+ * How much brighter a convex edge gets, 0 for none.
92
+ */
93
+ get light() {
94
+ return this.light_;
95
+ }
96
+
97
+ set light(value) {
98
+ this.light_ = value;
99
+ this.viewer.scene.requestRender();
100
+ }
101
+
102
+ /**
103
+ * How much darker a concave edge gets, 0 for none.
104
+ */
105
+ get shade() {
106
+ return this.shade_;
107
+ }
108
+
109
+ set shade(value) {
110
+ this.shade_ = value;
111
+ this.viewer.scene.requestRender();
112
+ }
113
+
114
+ /**
115
+ * The edges' bevel, in meters: close up, their light and shade fade over that width, as a molded
116
+ * plastic edge's; a pixel at the least, 8 at the most; 0, the default, for a pixel. Next to a small
117
+ * step (a frame proud of a wall), which it cannot tell from a fold, it lights a patch of the face
118
+ * behind.
119
+ */
120
+ get bevel() {
121
+ return this.bevel_;
122
+ }
123
+
124
+ set bevel(value) {
125
+ this.bevel_ = value;
126
+ this.viewer.scene.requestRender();
127
+ }
128
+
129
+ /**
130
+ * How much darker the outline along the silhouettes gets, a pixel wide, a darker shade of their
131
+ * color; 0 for none.
132
+ */
133
+ get outline() {
134
+ return this.outline_;
135
+ }
136
+
137
+ set outline(value) {
138
+ this.outline_ = value;
139
+ this.viewer.scene.requestRender();
140
+ }
141
+
142
+ /**
143
+ * How far the depth jumps, in pixels' sizes, to be a silhouette, outlined, rather than a crease,
144
+ * lit or shaded: 20 by default, for a city's buildings, their eaves lit; lower close up, where a
145
+ * thin thing standing on the ground (a chair's leg) would light its foot.
146
+ */
147
+ get jump() {
148
+ return this.jump_;
149
+ }
150
+
151
+ set jump(value) {
152
+ this.jump_ = value;
153
+ this.viewer.scene.requestRender();
154
+ }
155
+
156
+ /**
157
+ * The colors' saturation, 1 to keep it.
158
+ */
159
+ get saturation() {
160
+ return this.saturation_;
161
+ }
162
+
163
+ set saturation(value) {
164
+ this.saturation_ = value;
165
+ this.viewer.scene.requestRender();
166
+ }
167
+
168
+ /**
169
+ * A factor each of red, green and blue; [1, 1, 1] to keep the colors.
170
+ */
171
+ get warm() {
172
+ return this.warm_;
173
+ }
174
+
175
+ set warm(value) {
176
+ this.warm_ = value;
177
+ this.viewer.scene.requestRender();
178
+ }
179
+
180
+ /**
181
+ * The sky's gradient, its color at the top of the screen and at its bottom;
182
+ * undefined to keep the sky.
183
+ */
184
+ get sky() {
185
+ return this.sky_;
186
+ }
187
+
188
+ set sky(value) {
189
+ this.sky_ = value;
190
+ this.viewer.scene.requestRender();
191
+ }
192
+ }
package/valley-fog.js ADDED
@@ -0,0 +1,105 @@
1
+ import {Color} from '@cesium/core';
2
+ import {PostProcessStage} from '@cesium/engine';
3
+ import {acquireTerrainDepth, releaseTerrainDepth} from './depth-test.js';
4
+ import Effect from './effect.js';
5
+ import {heightUniforms} from './height.js';
6
+ import EyeFromDepth from './shaders/EyeFromDepth.js';
7
+ import Fog from './shaders/Fog.js';
8
+ import Height from './shaders/Height.js';
9
+ import ValleyFogShader from './shaders/ValleyFog.js';
10
+
11
+ /**
12
+ * Fog filling the valleys below an altitude: from above, a sea of fog with the
13
+ * peaks standing out; from inside, the visibility drops with the distance.
14
+ */
15
+ export default class ValleyFog extends Effect {
16
+ /**
17
+ * @param {import('@cesium/engine').CesiumWidget} viewer
18
+ * @param {{top?: number, density?: number, softness?: number, color?: Color}} [options]
19
+ */
20
+ constructor(viewer, options = {}) {
21
+ super(viewer);
22
+ this.top_ = options.top ?? 1500;
23
+ this.density_ = options.density ?? 0.005;
24
+ this.softness_ = options.softness ?? 100;
25
+ this.color_ = options.color ?? new Color(0.85, 0.88, 0.92, 1);
26
+ }
27
+
28
+ /**
29
+ * @override
30
+ * @param {import('@cesium/engine').Scene} scene
31
+ */
32
+ createStage_(scene) {
33
+ return new PostProcessStage({
34
+ fragmentShader: EyeFromDepth + Height + Fog + ValleyFogShader,
35
+ uniforms: {
36
+ ...heightUniforms(scene),
37
+ top: () => this.top_,
38
+ density: () => this.density_,
39
+ softness: () => this.softness_,
40
+ color: () => this.color_,
41
+ },
42
+ });
43
+ }
44
+
45
+ /**
46
+ * @override
47
+ * @param {import('@cesium/engine').Scene} scene
48
+ */
49
+ activated_(scene) {
50
+ acquireTerrainDepth(scene);
51
+ }
52
+
53
+ /**
54
+ * @override
55
+ * @param {import('@cesium/engine').Scene} scene
56
+ */
57
+ deactivating_(scene) {
58
+ releaseTerrainDepth(scene);
59
+ }
60
+
61
+ /**
62
+ * Altitude of the top of the fog, in meters above the ellipsoid.
63
+ */
64
+ get top() {
65
+ return this.top_;
66
+ }
67
+
68
+ set top(value) {
69
+ this.top_ = value;
70
+ this.viewer.scene.requestRender();
71
+ }
72
+
73
+ /**
74
+ * Density of the fog, per meter: about 1 / visibility.
75
+ */
76
+ get density() {
77
+ return this.density_;
78
+ }
79
+
80
+ set density(value) {
81
+ this.density_ = value;
82
+ this.viewer.scene.requestRender();
83
+ }
84
+
85
+ /**
86
+ * Height of the band under the top over which the fog thins out, in meters.
87
+ */
88
+ get softness() {
89
+ return this.softness_;
90
+ }
91
+
92
+ set softness(value) {
93
+ this.softness_ = value;
94
+ this.viewer.scene.requestRender();
95
+ }
96
+
97
+ get color() {
98
+ return this.color_;
99
+ }
100
+
101
+ set color(value) {
102
+ this.color_ = value;
103
+ this.viewer.scene.requestRender();
104
+ }
105
+ }
package/white-model.js ADDED
@@ -0,0 +1,105 @@
1
+ import {Cartesian2} from '@cesium/core';
2
+ import Toy from './toy.js';
3
+ import WhiteModelShader from './shaders/WhiteModel.js';
4
+
5
+ const valuesScratch = new Cartesian2();
6
+
7
+ /**
8
+ * A white model's look, as an architect's plaster model or clay render: every color turned to its
9
+ * value, the values pressed into a narrow range of whites (the darkest left black: a section's
10
+ * poché), darker where surfaces meet, the edges lit and shaded and finely outlined as the toy's,
11
+ * the sky a pale gradient if asked. A `Toy` with another grading: its options and properties,
12
+ * `saturation` 0 (an accent's hue kept above it), `warm` the plaster's tint.
13
+ */
14
+ export default class WhiteModel extends Toy {
15
+ /**
16
+ * @param {import('@cesium/engine').CesiumWidget} viewer
17
+ * @param {{light?: number, shade?: number, bevel?: number, outline?: number, jump?: number, saturation?: number, warm?: [number, number, number], values?: [number, number], poche?: number, occlusion?: number, radius?: number, sky?: [import('@cesium/core').Color, import('@cesium/core').Color]}} [options]
18
+ */
19
+ constructor(viewer, options = {}) {
20
+ // the toy's options, each the white model's default when not given, or given as undefined
21
+ super(viewer, {
22
+ ...options,
23
+ light: options.light ?? 0.08,
24
+ shade: options.shade ?? 0.12,
25
+ outline: options.outline ?? 0.25,
26
+ saturation: options.saturation ?? 0,
27
+ warm: options.warm ?? [1, 0.995, 0.985],
28
+ });
29
+ this.values_ = options.values ?? [0.35, 0.97];
30
+ this.poche_ = options.poche ?? 0.1;
31
+ this.occlusion_ = options.occlusion ?? 0.35;
32
+ this.radius_ = options.radius ?? 1.5;
33
+ }
34
+
35
+ /**
36
+ * @override
37
+ * @protected
38
+ */
39
+ shader_() {
40
+ return WhiteModelShader;
41
+ }
42
+
43
+ /**
44
+ * @override
45
+ * @protected
46
+ */
47
+ uniforms_() {
48
+ return {
49
+ ...super.uniforms_(),
50
+ values: () => Cartesian2.fromArray(this.values_, 0, valuesScratch),
51
+ poche: () => this.poche_,
52
+ occlusion: () => this.occlusion_,
53
+ radius: () => this.radius_,
54
+ };
55
+ }
56
+
57
+ /**
58
+ * The darkest and the lightest values, from 0 to 1: the scene's black and its white.
59
+ */
60
+ get values() {
61
+ return this.values_;
62
+ }
63
+
64
+ set values(value) {
65
+ this.values_ = value;
66
+ this.viewer.scene.requestRender();
67
+ }
68
+
69
+ /**
70
+ * The value under which a color keeps it rather than being pressed into the whites, fading into
71
+ * them about it: a section's poché, solid black; 0 to press every color.
72
+ */
73
+ get poche() {
74
+ return this.poche_;
75
+ }
76
+
77
+ set poche(value) {
78
+ this.poche_ = value;
79
+ this.viewer.scene.requestRender();
80
+ }
81
+
82
+ /**
83
+ * How much darker the surfaces get where they meet, in a corner or at a wall's foot, 0 for none.
84
+ */
85
+ get occlusion() {
86
+ return this.occlusion_;
87
+ }
88
+
89
+ set occlusion(value) {
90
+ this.occlusion_ = value;
91
+ this.viewer.scene.requestRender();
92
+ }
93
+
94
+ /**
95
+ * How wide the corners' shadow is, in meters, 48 pixels at the most.
96
+ */
97
+ get radius() {
98
+ return this.radius_;
99
+ }
100
+
101
+ set radius(value) {
102
+ this.radius_ = value;
103
+ this.viewer.scene.requestRender();
104
+ }
105
+ }