@arraypress/effects-astro 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.
- package/AGENTS.md +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +285 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ocean/presets
|
|
3
|
+
*
|
|
4
|
+
* The ocean's times of day: for each, where the sun (or the moon) sits,
|
|
5
|
+
* its light, the sky's colours and the water's. `oceanLook` resolves a
|
|
6
|
+
* time and tints it with the effect's `colors` or `palette`, keeping each
|
|
7
|
+
* colour's lightness so the light still reads as that time of day; and
|
|
8
|
+
* `oceanBackdrop` paints the scene as a CSS gradient for a browser
|
|
9
|
+
* without WebGL.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { fromOklab, mixOklab, parseColor, toHex, toOklab } from '../color.js';
|
|
13
|
+
import { pickColors } from '../palettes.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {'dawn' | 'noon' | 'sunset' | 'night'} OceanTime
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {object} OceanLook
|
|
21
|
+
* @property {OceanTime} time The time of day it is.
|
|
22
|
+
* @property {number} x Where the sun sits across the frame, 0–1 from the left (beyond it, off to the side).
|
|
23
|
+
* @property {number} elevation Its height above the horizon, degrees.
|
|
24
|
+
* @property {number} size Its apparent radius, radians (drawn larger than life, as a long lens shows it).
|
|
25
|
+
* @property {string} light The colour of its light on the water.
|
|
26
|
+
* @property {number} power How strong that light is.
|
|
27
|
+
* @property {string} zenith The sky overhead.
|
|
28
|
+
* @property {string} horizon The sky along the horizon, and the haze.
|
|
29
|
+
* @property {string} glow The glow round the sun.
|
|
30
|
+
* @property {string} deep The deep water's own colour, lit from above.
|
|
31
|
+
* @property {string} scatter The colour light takes through a thin crest.
|
|
32
|
+
* @property {string} cloud The clouds' shaded side.
|
|
33
|
+
* @property {number} haze How far, in metres, the air takes to hide the sea.
|
|
34
|
+
* @property {number} exposure The camera's exposure.
|
|
35
|
+
* @property {number} stars How bright the stars are, 0 for none.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** @type {Readonly<Record<OceanTime, OceanLook>>} */
|
|
39
|
+
export const OCEAN_TIMES = Object.freeze({
|
|
40
|
+
dawn: {
|
|
41
|
+
time: 'dawn',
|
|
42
|
+
x: 0.3,
|
|
43
|
+
elevation: 4,
|
|
44
|
+
size: 0.011,
|
|
45
|
+
light: '#ffcf9e',
|
|
46
|
+
power: 5,
|
|
47
|
+
zenith: '#5576a8',
|
|
48
|
+
horizon: '#f3c6aa',
|
|
49
|
+
glow: '#ffbb8c',
|
|
50
|
+
deep: '#18334f',
|
|
51
|
+
scatter: '#3c9f98',
|
|
52
|
+
cloud: '#8a86a6',
|
|
53
|
+
haze: 2200,
|
|
54
|
+
exposure: 0.95,
|
|
55
|
+
stars: 0,
|
|
56
|
+
},
|
|
57
|
+
noon: {
|
|
58
|
+
time: 'noon',
|
|
59
|
+
x: 1.45,
|
|
60
|
+
elevation: 50,
|
|
61
|
+
size: 0.009,
|
|
62
|
+
light: '#fff6e8',
|
|
63
|
+
power: 5.5,
|
|
64
|
+
zenith: '#2463b6',
|
|
65
|
+
horizon: '#b4d3ec',
|
|
66
|
+
glow: '#fffaf0',
|
|
67
|
+
deep: '#03324f',
|
|
68
|
+
scatter: '#14b2a4',
|
|
69
|
+
cloud: '#c1cad6',
|
|
70
|
+
haze: 5200,
|
|
71
|
+
exposure: 0.7,
|
|
72
|
+
stars: 0,
|
|
73
|
+
},
|
|
74
|
+
sunset: {
|
|
75
|
+
time: 'sunset',
|
|
76
|
+
x: 0.68,
|
|
77
|
+
elevation: 2.4,
|
|
78
|
+
size: 0.012,
|
|
79
|
+
light: '#ff9a52',
|
|
80
|
+
power: 6,
|
|
81
|
+
zenith: '#1a3772',
|
|
82
|
+
horizon: '#f79a5c',
|
|
83
|
+
glow: '#ff7a32',
|
|
84
|
+
deep: '#0b1828',
|
|
85
|
+
scatter: '#2b8a80',
|
|
86
|
+
cloud: '#3a3d5c',
|
|
87
|
+
haze: 9000,
|
|
88
|
+
exposure: 0.85,
|
|
89
|
+
stars: 0,
|
|
90
|
+
},
|
|
91
|
+
night: {
|
|
92
|
+
time: 'night',
|
|
93
|
+
x: 0.62,
|
|
94
|
+
elevation: 7,
|
|
95
|
+
size: 0.01,
|
|
96
|
+
light: '#c9d8f2',
|
|
97
|
+
power: 0.8,
|
|
98
|
+
zenith: '#03081a',
|
|
99
|
+
horizon: '#16253f',
|
|
100
|
+
glow: '#2c3c5c',
|
|
101
|
+
deep: '#01050c',
|
|
102
|
+
scatter: '#0e3a46',
|
|
103
|
+
cloud: '#141c2e',
|
|
104
|
+
haze: 3000,
|
|
105
|
+
exposure: 1.25,
|
|
106
|
+
stars: 1,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/** The default time of day: the most striking. */
|
|
111
|
+
export const OCEAN_TIME = 'sunset';
|
|
112
|
+
|
|
113
|
+
/** How far a tint moves each colour's hue and chroma towards the tint's, 0–1; its lightness is kept. */
|
|
114
|
+
const TINT = 0.6;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Moves a colour's hue and chroma towards another's, in Oklab, keeping
|
|
118
|
+
* its own lightness: the light keeps its strength and only its colour
|
|
119
|
+
* changes.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} color The colour, CSS hex.
|
|
122
|
+
* @param {string} tint The tint, CSS hex.
|
|
123
|
+
* @param {number} [amount=TINT] How far, 0–1.
|
|
124
|
+
* @returns {string} The tinted colour, CSS hex.
|
|
125
|
+
* @throws {TypeError} When either is not a hex colour.
|
|
126
|
+
*/
|
|
127
|
+
export function tintColor(color, tint, amount = TINT) {
|
|
128
|
+
const [L, a, b] = toOklab(parseColor(color));
|
|
129
|
+
const [, ta, tb] = toOklab(parseColor(tint));
|
|
130
|
+
return toHex(fromOklab([L, a + (ta - a) * amount, b + (tb - b) * amount]));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A time of day, tinted by the effect's colours: the first tints the sky,
|
|
135
|
+
* the second the water, the third the sun's light and glow. An unknown
|
|
136
|
+
* time is warned about and the default used.
|
|
137
|
+
*
|
|
138
|
+
* @param {{ time?: string, colors?: string[], palette?: string }} config The effect's settings.
|
|
139
|
+
* @returns {OceanLook} The look, its colours as CSS hex.
|
|
140
|
+
* @throws {TypeError} When a colour is not a hex colour.
|
|
141
|
+
*/
|
|
142
|
+
export function oceanLook(config) {
|
|
143
|
+
const name = config.time ?? OCEAN_TIME;
|
|
144
|
+
const known = Object.hasOwn(OCEAN_TIMES, name);
|
|
145
|
+
if (!known) console.warn('[effects-astro]', `No ocean time "${name}"`);
|
|
146
|
+
const look = { ...OCEAN_TIMES[known ? /** @type {OceanTime} */ (name) : OCEAN_TIME] };
|
|
147
|
+
const tints = pickColors(config, []);
|
|
148
|
+
if (!tints.length) return look;
|
|
149
|
+
/**
|
|
150
|
+
* The tint for a part of the scene: its colour, or the last one given.
|
|
151
|
+
*
|
|
152
|
+
* @param {number} i 0 the sky, 1 the water, 2 the light.
|
|
153
|
+
* @returns {string} The tint.
|
|
154
|
+
*/
|
|
155
|
+
const tint = (i) => tints[Math.min(i, tints.length - 1)];
|
|
156
|
+
look.zenith = tintColor(look.zenith, tint(0));
|
|
157
|
+
look.horizon = tintColor(look.horizon, tint(0));
|
|
158
|
+
look.cloud = tintColor(look.cloud, tint(0));
|
|
159
|
+
look.deep = tintColor(look.deep, tint(1));
|
|
160
|
+
look.scatter = tintColor(look.scatter, tint(1));
|
|
161
|
+
look.glow = tintColor(look.glow, tint(2));
|
|
162
|
+
look.light = tintColor(look.light, tint(2));
|
|
163
|
+
return look;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The scene as CSS backgrounds, for a browser without WebGL: the sky from
|
|
168
|
+
* its zenith down to the horizon, the sun's glow, and the sea from the
|
|
169
|
+
* sky it mirrors at the horizon down into its deep colour.
|
|
170
|
+
*
|
|
171
|
+
* @param {OceanLook} look The look.
|
|
172
|
+
* @param {number} [horizon=0.3] Where the horizon sits, 0–1 up the frame.
|
|
173
|
+
* @returns {string} A CSS `background` value.
|
|
174
|
+
*/
|
|
175
|
+
export function oceanBackdrop(look, horizon = 0.3) {
|
|
176
|
+
const line = ((1 - Math.min(1, Math.max(0, horizon))) * 100).toFixed(1);
|
|
177
|
+
const sunY = Math.max(4, Number(line) - Math.min(look.elevation, 20) * 1.5).toFixed(1);
|
|
178
|
+
// The far sea mirrors the sky above the horizon; the near sea is its own deep colour.
|
|
179
|
+
const sea = toHex(mixOklab(mixOklab(parseColor(look.zenith), parseColor(look.horizon), 0.4), parseColor(look.deep), 0.3));
|
|
180
|
+
return [
|
|
181
|
+
`radial-gradient(ellipse 36% 16% at ${(look.x * 100).toFixed(1)}% ${sunY}%, ${look.glow}cc, transparent 70%)`,
|
|
182
|
+
`linear-gradient(to bottom, ${look.zenith} 0%, ${look.horizon} ${line}%, ${sea} ${line}%, ${look.deep} 100%)`,
|
|
183
|
+
].join(', ');
|
|
184
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The budget a shader is compiled for. */
|
|
2
|
+
export interface OceanQuality {
|
|
3
|
+
/** How many waves in all. */
|
|
4
|
+
waves: number;
|
|
5
|
+
/** How many of the longest shape the surface the march finds. */
|
|
6
|
+
geometry: number;
|
|
7
|
+
/** March steps through the waves' band. */
|
|
8
|
+
steps: number;
|
|
9
|
+
/** False-position steps after the march. */
|
|
10
|
+
refine: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The ocean's fragment shader (GLSL ES 1.00) for a budget. */
|
|
14
|
+
export function oceanShader(quality: OceanQuality): string;
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ocean/shader
|
|
3
|
+
*
|
|
4
|
+
* The ocean's fragment shader (GLSL ES 1.00): open sea to the horizon
|
|
5
|
+
* under an analytic sky, one pass, every pixel its own ray.
|
|
6
|
+
*
|
|
7
|
+
* The sea is a heightfield: a sum of directional waves with sharp crests
|
|
8
|
+
* and long troughs (each `exp(S·(sin θ - 1))`, a trochoid's profile), the
|
|
9
|
+
* long ones drawn together at their crests as Gerstner waves are. A ray
|
|
10
|
+
* strides through the band the crests and troughs can reach, each stride
|
|
11
|
+
* as long as the sea could rise to meet it, then a few false-position
|
|
12
|
+
* steps refine the hit; the sea's mean surface curves away
|
|
13
|
+
* with the Earth, so the horizon is where it truly is, a few kilometres
|
|
14
|
+
* out. The normal comes from the waves' analytic slopes. Waves too small
|
|
15
|
+
* for a pixel's footprint are left out and their slopes become roughness
|
|
16
|
+
* instead, so the distance never shimmers and the sun's path broadens
|
|
17
|
+
* into the streaked glare real water has.
|
|
18
|
+
*
|
|
19
|
+
* Light: Schlick's Fresnel mixes the reflected sky (its clouds too) with
|
|
20
|
+
* the deep water's own colour; sunlight glows through thin crests turned
|
|
21
|
+
* from the sun; a sharp Beckmann lobe on the fine slopes makes the
|
|
22
|
+
* glittering path; whitecaps break on the steepest crests; air hazes the
|
|
23
|
+
* distance into the horizon's colour. Lit in linear light, tone mapped
|
|
24
|
+
* with Krzysztof Narkowicz's fit of the ACES filmic curve (2015), and
|
|
25
|
+
* dithered against banding.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { GLSL_OKLAB } from '../color.js';
|
|
29
|
+
import { GLSL_NOISE, GLSL_QUIET } from '../glsl.js';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {object} OceanQuality
|
|
33
|
+
* @property {number} waves How many waves in all.
|
|
34
|
+
* @property {number} geometry How many of the longest shape the surface the march finds.
|
|
35
|
+
* @property {number} steps March steps through the waves' band.
|
|
36
|
+
* @property {number} refine False-position steps after the march.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The fragment shader for a quality: the loops are fixed at compile time.
|
|
41
|
+
*
|
|
42
|
+
* @param {OceanQuality} quality The budget.
|
|
43
|
+
* @returns {string} The shader.
|
|
44
|
+
*/
|
|
45
|
+
export function oceanShader({ waves, geometry, steps, refine }) {
|
|
46
|
+
return `
|
|
47
|
+
precision highp float;
|
|
48
|
+
#define WAVES ${waves}
|
|
49
|
+
#define GEO ${geometry}
|
|
50
|
+
#define STEPS ${steps}
|
|
51
|
+
#define REFINE ${refine}
|
|
52
|
+
#define EARTH 6371000.0
|
|
53
|
+
#define DRAG 0.32
|
|
54
|
+
#define ANISO 6.0
|
|
55
|
+
#define SHARP 0.09
|
|
56
|
+
#define PI 3.14159265
|
|
57
|
+
uniform vec2 uRes;
|
|
58
|
+
uniform vec3 uEye;
|
|
59
|
+
uniform vec3 uRight;
|
|
60
|
+
uniform vec3 uUp;
|
|
61
|
+
uniform vec3 uFwd;
|
|
62
|
+
uniform vec2 uLens;
|
|
63
|
+
uniform vec4 uShape[WAVES];
|
|
64
|
+
uniform vec2 uMotion[WAVES];
|
|
65
|
+
uniform float uCrest;
|
|
66
|
+
uniform float uSlope;
|
|
67
|
+
uniform vec3 uSun;
|
|
68
|
+
uniform vec3 uLight;
|
|
69
|
+
uniform float uPower;
|
|
70
|
+
uniform float uSize;
|
|
71
|
+
uniform vec3 uZenith;
|
|
72
|
+
uniform vec3 uHorizon;
|
|
73
|
+
uniform vec3 uGlow;
|
|
74
|
+
uniform vec3 uDeep;
|
|
75
|
+
uniform vec3 uScatter;
|
|
76
|
+
uniform vec3 uCloud;
|
|
77
|
+
uniform float uHaze;
|
|
78
|
+
uniform float uExposure;
|
|
79
|
+
uniform float uStars;
|
|
80
|
+
uniform float uClouds;
|
|
81
|
+
uniform float uFoam;
|
|
82
|
+
uniform float uTime;
|
|
83
|
+
uniform vec2 uDrift;
|
|
84
|
+
uniform vec2 uWind;
|
|
85
|
+
${GLSL_OKLAB}
|
|
86
|
+
${GLSL_NOISE}
|
|
87
|
+
${GLSL_QUIET}
|
|
88
|
+
|
|
89
|
+
// The scene's colours in linear light, converted once a pixel in main().
|
|
90
|
+
vec3 cZenith, cHorizon, cGlow, cLight, cDeep, cScatter, cCloud;
|
|
91
|
+
|
|
92
|
+
// Krzysztof Narkowicz's fit of the ACES filmic tone curve (2015).
|
|
93
|
+
vec3 aces(vec3 x) {
|
|
94
|
+
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The sky without its clouds or sun disc: the horizon's haze rising into
|
|
98
|
+
// the zenith, and the sun's glow, wide and low along the horizon.
|
|
99
|
+
vec3 skyBase(vec3 rd) {
|
|
100
|
+
float y = max(rd.y, 0.0);
|
|
101
|
+
float mu = max(dot(rd, uSun), 0.0);
|
|
102
|
+
// The horizon's band is deeper towards the sun, thinner away from it.
|
|
103
|
+
vec3 col = mix(cHorizon, cZenith, 1.0 - exp(-y * mix(16.0, 7.0, mu * mu)));
|
|
104
|
+
float low = exp(-y * 9.0);
|
|
105
|
+
col += cGlow * (0.3 * pow(mu, 8.0) * (0.25 + low) + 0.5 * pow(mu, 90.0) + 0.06 * low * mu);
|
|
106
|
+
return col;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// High cloud along a ray going up, 0–1: a warped sheet at altitude seen in
|
|
110
|
+
// perspective, so it crowds into streaks towards the horizon, torn into
|
|
111
|
+
// wisps at its edges. Reflections, blurred by the waves, take a cheaper
|
|
112
|
+
// warp (fine 0).
|
|
113
|
+
float cloudAt(vec3 rd, float fine) {
|
|
114
|
+
if (uClouds <= 0.0 || rd.y <= 0.0) return 0.0;
|
|
115
|
+
vec2 q = rd.xz / (rd.y + 0.04) * 0.7 + uDrift;
|
|
116
|
+
q = vec2(dot(q, vec2(uWind.y, -uWind.x)), dot(q, uWind) * 1.8);
|
|
117
|
+
float n = fbm(q * 0.4 + (fine > 0.0 ? fbm(q * 0.25 + 7.0) : noise(q * 0.25 + 7.0)) * 1.6);
|
|
118
|
+
float cover = smoothstep(0.56 - 0.14 * uClouds, 0.8, n) * (0.5 + 0.5 * noise(q * 3.3));
|
|
119
|
+
return cover * smoothstep(0.0, 0.12, rd.y);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The clouds' colour along a ray: shaded underneath, their undersides lit
|
|
123
|
+
// warm low down, their edges bright towards the sun.
|
|
124
|
+
vec3 cloudColor(vec3 rd, float cover) {
|
|
125
|
+
float mu = max(dot(rd, uSun), 0.0);
|
|
126
|
+
float low = exp(-max(rd.y, 0.0) * 4.0);
|
|
127
|
+
return cCloud + cGlow * (0.45 * low * (0.3 + 0.7 * mu)) + cLight * uPower * 0.12 * pow(mu, 14.0) * (1.3 - cover);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Stars: a sparse grid of points, each a pixel or two across, twinkling.
|
|
131
|
+
float starsAt(vec3 rd, float pix) {
|
|
132
|
+
if (uStars <= 0.0 || rd.y <= 0.0) return 0.0;
|
|
133
|
+
vec2 sp = vec2(atan(rd.z, rd.x), rd.y) * 160.0;
|
|
134
|
+
vec2 cell = floor(sp);
|
|
135
|
+
float r = hash(cell);
|
|
136
|
+
if (r < 0.982) return 0.0;
|
|
137
|
+
vec2 at = vec2(hash(cell + 3.1), hash(cell + 7.7)) * 0.6 + 0.2;
|
|
138
|
+
float d = length(fract(sp) - at) / (pix * 160.0);
|
|
139
|
+
float twinkle = 0.7 + 0.3 * sin(uTime * (2.0 + 3.0 * r) + r * 40.0);
|
|
140
|
+
return smoothstep(1.4, 0.0, d) * (r - 0.982) * 55.0 * twinkle * smoothstep(0.02, 0.25, rd.y) * uStars;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The whole sky along a ray: gradient, glow, clouds, and the sun or moon.
|
|
144
|
+
vec3 skyColor(vec3 rd, float pix) {
|
|
145
|
+
vec3 col = skyBase(rd);
|
|
146
|
+
float cover = cloudAt(rd, 1.0);
|
|
147
|
+
col = mix(col, cloudColor(rd, cover), cover);
|
|
148
|
+
float mu = dot(rd, uSun);
|
|
149
|
+
float angle = sqrt(max(2.0 * (1.0 - mu), 0.0));
|
|
150
|
+
float disc = smoothstep(uSize, uSize * 0.8, angle);
|
|
151
|
+
if (disc > 0.0) {
|
|
152
|
+
float edge = angle / uSize;
|
|
153
|
+
float limb = 1.0 - 0.45 * (1.0 - sqrt(max(1.0 - edge * edge, 0.0)));
|
|
154
|
+
// The moon is mottled; the sun only darkens at its limb.
|
|
155
|
+
vec3 local = rd - uSun;
|
|
156
|
+
limb *= mix(1.0, 0.8 + 0.25 * noise(local.xy / uSize * 2.5 + 4.0), uStars);
|
|
157
|
+
col += cLight * uPower * 0.7 * disc * limb * (1.0 - 0.9 * cover);
|
|
158
|
+
}
|
|
159
|
+
// The bloom a lens sees round it.
|
|
160
|
+
float m = max(mu, 0.0);
|
|
161
|
+
col += cLight * uPower * (0.03 * pow(m, 700.0) + 0.12 * pow(m, 7000.0)) * (1.0 - 0.7 * cover);
|
|
162
|
+
col += vec3(0.8, 0.88, 1.0) * starsAt(rd, pix) * (1.0 - cover);
|
|
163
|
+
return col;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// How far along a ray it meets the sea's mean surface raised by level, a
|
|
167
|
+
// sphere the Earth's size; -1 when it misses. The stable root of
|
|
168
|
+
// above + rd.y·t + t²/(2R) = 0.
|
|
169
|
+
float toLevel(vec3 ro, vec3 rd, float level) {
|
|
170
|
+
float above = ro.y - level;
|
|
171
|
+
float disc = rd.y * rd.y - 2.0 * above / EARTH;
|
|
172
|
+
if (rd.y >= 0.0 || disc < 0.0) return -1.0;
|
|
173
|
+
return 2.0 * above / (-rd.y + sqrt(disc));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A pixel's footprint on the sea at distance t: the ray's heading on the
|
|
177
|
+
// water (xy), and the footprint across it (z) and along it (w), metres.
|
|
178
|
+
// Along it, the footprint stretches as the ray grazes the surface; the
|
|
179
|
+
// stretch is capped at ANISO times its width, or only the waves running
|
|
180
|
+
// across the view would survive into the distance, as a fan of stripes.
|
|
181
|
+
vec4 footprint(float t, vec3 rd, float pix, float grazing) {
|
|
182
|
+
vec2 along = normalize(rd.xz + vec2(0.0, 1e-6));
|
|
183
|
+
float stretch = t * pix / max(grazing, 0.015);
|
|
184
|
+
return vec4(along, max(t * pix, stretch / ANISO), stretch);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// How much of a wave a footprint keeps: all of it while the wave spans
|
|
188
|
+
// several footprints, none once it is shorter than about four.
|
|
189
|
+
float keep(vec4 w, vec4 foot) {
|
|
190
|
+
vec2 seen = vec2(dot(w.xy, vec2(-foot.y, foot.x)) * foot.z, dot(w.xy, foot.xy) * foot.w);
|
|
191
|
+
return 1.0 - smoothstep(0.6, 1.5, w.z * length(seen));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The long waves' height at p: the surface the march finds. Waves too
|
|
195
|
+
// small for the footprint fade out.
|
|
196
|
+
float seaHeight(vec2 p, vec4 foot) {
|
|
197
|
+
float h = 0.0;
|
|
198
|
+
for (int i = 0; i < GEO; i++) {
|
|
199
|
+
vec4 w = uShape[i];
|
|
200
|
+
float amp = w.w * keep(w, foot);
|
|
201
|
+
if (amp <= 0.0) continue;
|
|
202
|
+
vec2 m = uMotion[i];
|
|
203
|
+
float a = dot(w.xy, p) * w.z + m.x;
|
|
204
|
+
float e = exp(m.y * (sin(a) - 1.0));
|
|
205
|
+
h += amp * (2.0 * e - 1.0);
|
|
206
|
+
p -= w.xy * (m.y * cos(a) * e * amp * DRAG);
|
|
207
|
+
}
|
|
208
|
+
return h;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// The whole sea at p, seen along rd: height (x) and slope (y: dh/dx, z:
|
|
212
|
+
// dh/dz). The long waves come first; the short ones are then filtered by
|
|
213
|
+
// how the ray grazes the long waves' own slope there, so the backs of
|
|
214
|
+
// crests do not shimmer. The short waves swell and calm in patches, as
|
|
215
|
+
// gusts leave them; those too small for the footprint are left out, their
|
|
216
|
+
// slopes summed into rough instead. swell is the long waves alone.
|
|
217
|
+
vec3 seaDetail(vec2 p, vec3 rd, float t, float pix, out float rough, out vec3 swell) {
|
|
218
|
+
vec3 h = vec3(0.0);
|
|
219
|
+
rough = 0.0;
|
|
220
|
+
vec4 foot = footprint(t, rd, pix, -rd.y);
|
|
221
|
+
float gust = 0.55 + 0.9 * noise(p * 0.021 - uWind * uTime * 0.05);
|
|
222
|
+
for (int i = 0; i < WAVES; i++) {
|
|
223
|
+
if (i == GEO) {
|
|
224
|
+
swell = h;
|
|
225
|
+
foot = footprint(t, rd, pix, -dot(rd, normalize(vec3(-h.y, 1.0, -h.z))));
|
|
226
|
+
}
|
|
227
|
+
vec4 w = uShape[i];
|
|
228
|
+
vec2 m = uMotion[i];
|
|
229
|
+
float amp = w.w * (i < GEO ? 1.0 : gust);
|
|
230
|
+
float kept = keep(w, foot);
|
|
231
|
+
// The wave's mean square slope: (a·k)² · 0.4·S for this profile.
|
|
232
|
+
float slope = amp * w.z;
|
|
233
|
+
rough += slope * slope * 0.4 * m.y * (1.0 - kept);
|
|
234
|
+
if (kept <= 0.0) continue;
|
|
235
|
+
amp *= kept;
|
|
236
|
+
float a = dot(w.xy, p) * w.z + m.x;
|
|
237
|
+
float e = exp(m.y * (sin(a) - 1.0));
|
|
238
|
+
float c = cos(a);
|
|
239
|
+
h += vec3(amp * (2.0 * e - 1.0), (2.0 * amp * m.y * c * e * w.z) * w.xy);
|
|
240
|
+
if (i < GEO) p -= w.xy * (m.y * c * e * amp * DRAG);
|
|
241
|
+
}
|
|
242
|
+
return h;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// How far a point on a ray is above the sea (negative below it).
|
|
246
|
+
float gap(vec3 ro, vec3 rd, float t, float pix) {
|
|
247
|
+
vec3 p = ro + rd * t;
|
|
248
|
+
return p.y + t * t / (2.0 * EARTH) - seaHeight(p.xz, footprint(t, rd, pix, -rd.y));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Where a ray meets the sea, or -1 when it passes over to the sky: a march
|
|
252
|
+
// through the band the waves can reach, then false-position steps.
|
|
253
|
+
float marchSea(vec3 ro, vec3 rd, float pix) {
|
|
254
|
+
float t0 = toLevel(ro, rd, uCrest);
|
|
255
|
+
if (t0 < 0.0) return -1.0;
|
|
256
|
+
float t1 = toLevel(ro, rd, -uCrest);
|
|
257
|
+
// Grazing the far crests but no trough: it may pass over them to the sky.
|
|
258
|
+
bool grazing = t1 < 0.0;
|
|
259
|
+
if (grazing) t1 = -rd.y * EARTH;
|
|
260
|
+
// Each step goes as far as the sea could rise to meet the ray, given
|
|
261
|
+
// how steep the long waves get: long strides high above the water,
|
|
262
|
+
// short ones as it skims a crest, so crests are not stepped over. It
|
|
263
|
+
// never stalls (a share of the distance at least), and the last step is
|
|
264
|
+
// the far end.
|
|
265
|
+
float ta = t0;
|
|
266
|
+
float fa = gap(ro, rd, t0, pix);
|
|
267
|
+
float tb = t1;
|
|
268
|
+
float fb = -1.0;
|
|
269
|
+
bool hit = false;
|
|
270
|
+
for (int i = 0; i <= STEPS; i++) {
|
|
271
|
+
float t = i == STEPS ? t1 : min(ta + max(fa / (uSlope - rd.y), ta * 0.02), t1);
|
|
272
|
+
float f = gap(ro, rd, t, pix);
|
|
273
|
+
if (f < 0.0) {
|
|
274
|
+
tb = t;
|
|
275
|
+
fb = f;
|
|
276
|
+
hit = true;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
ta = t;
|
|
280
|
+
fa = f;
|
|
281
|
+
if (t >= t1) break;
|
|
282
|
+
}
|
|
283
|
+
if (!hit) return grazing ? -1.0 : t1;
|
|
284
|
+
// Regula falsi, Illinois style: an end kept twice has its gap halved, so it converges from both sides.
|
|
285
|
+
float side = 0.0;
|
|
286
|
+
for (int i = 0; i < REFINE; i++) {
|
|
287
|
+
float t = ta + (tb - ta) * fa / (fa - fb);
|
|
288
|
+
float f = gap(ro, rd, t, pix);
|
|
289
|
+
if (f < 0.0) {
|
|
290
|
+
tb = t;
|
|
291
|
+
fb = f;
|
|
292
|
+
if (side < 0.0) fa *= 0.5;
|
|
293
|
+
side = -1.0;
|
|
294
|
+
} else {
|
|
295
|
+
ta = t;
|
|
296
|
+
fa = f;
|
|
297
|
+
if (side > 0.0) fb *= 0.5;
|
|
298
|
+
side = 1.0;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return ta + (tb - ta) * fa / (fa - fb);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// The sea's colour where a ray meets it, t along.
|
|
305
|
+
vec3 seaColor(vec3 ro, vec3 rd, float t, float pix) {
|
|
306
|
+
vec3 p = ro + rd * t;
|
|
307
|
+
float rough;
|
|
308
|
+
vec3 swell;
|
|
309
|
+
vec3 h = seaDetail(p.xz, rd, t, pix, rough, swell);
|
|
310
|
+
vec3 n = normalize(vec3(-h.y, 1.0, -h.z));
|
|
311
|
+
vec3 v = -rd;
|
|
312
|
+
// A ripple's back, turned from the eye, is hidden behind its own crest:
|
|
313
|
+
// what the pixel sees leans towards the eye, and catches no sun.
|
|
314
|
+
float facing = dot(n, v);
|
|
315
|
+
n = normalize(n + v * max(0.0, 0.02 - facing));
|
|
316
|
+
float nv = max(dot(n, v), 0.0);
|
|
317
|
+
|
|
318
|
+
// Fresnel: the sky the water mirrors, against its own deep colour.
|
|
319
|
+
float fresnel = 0.02 + 0.98 * pow(1.0 - nv, 5.0);
|
|
320
|
+
// Rough water mirrors the sky over a spread of heights, higher on average than a smooth sea.
|
|
321
|
+
vec3 r = reflect(rd, n);
|
|
322
|
+
r.y = abs(r.y) + sqrt(rough) * 0.7;
|
|
323
|
+
r = normalize(r);
|
|
324
|
+
float cover = cloudAt(r, 0.0);
|
|
325
|
+
vec3 sky = mix(skyBase(r), cloudColor(r, cover), cover);
|
|
326
|
+
|
|
327
|
+
// Light through the crests: thin water turned from the sun, seen against it, glows.
|
|
328
|
+
float crest = clamp(swell.x / uCrest + 0.5, 0.0, 1.0);
|
|
329
|
+
vec3 level = normalize(vec3(uSun.x, 0.0, uSun.z) + 1e-5);
|
|
330
|
+
float against = pow(max(dot(rd, level), 0.0), 3.0);
|
|
331
|
+
float thin = pow(clamp(0.5 - 0.5 * dot(uSun, n), 0.0, 1.0), 3.0);
|
|
332
|
+
vec3 ambient = cZenith * 0.6 + cHorizon * 0.4;
|
|
333
|
+
vec3 body = cDeep + cScatter * (ambient * (0.08 + 0.35 * crest * crest) * 0.6);
|
|
334
|
+
body += cScatter * cLight * uPower * (0.4 * crest * crest * crest * crest * against * thin + 0.015 * crest * nv * nv) * smoothstep(-0.05, 0.15, uSun.y);
|
|
335
|
+
|
|
336
|
+
// The sun's glitter: a sharp lobe on the fine slopes, broadened by those too small to see.
|
|
337
|
+
vec3 hv = normalize(uSun + v);
|
|
338
|
+
float nh = max(dot(n, hv), 1e-3);
|
|
339
|
+
float m2 = SHARP * SHARP + rough * 0.5;
|
|
340
|
+
float nh2 = nh * nh;
|
|
341
|
+
float lobe = exp((nh2 - 1.0) / (m2 * nh2)) / (PI * m2 * nh2 * nh2);
|
|
342
|
+
float shine = 0.02 + 0.98 * pow(1.0 - max(dot(hv, v), 0.0), 5.0);
|
|
343
|
+
float nl = max(dot(n, uSun), 0.0);
|
|
344
|
+
// Smith-Schlick masking, by the unresolved ripples: at grazing angles they hide one another.
|
|
345
|
+
float k = SHARP * 0.8;
|
|
346
|
+
float masked = nl / (nl * (1.0 - k) + k) / (nv * (1.0 - k) + k);
|
|
347
|
+
vec3 glitter = cLight * uPower * lobe * shine * masked * 0.25 * smoothstep(-0.01, 0.02, facing);
|
|
348
|
+
|
|
349
|
+
vec3 col = mix(body, sky, fresnel) + glitter;
|
|
350
|
+
|
|
351
|
+
// Whitecaps on the steepest crests of a rough sea, torn by noise, fading as they shrink below a pixel.
|
|
352
|
+
if (uFoam > 0.0) {
|
|
353
|
+
float steep = swell.x / uCrest + length(swell.yz) * 0.6;
|
|
354
|
+
float cap = smoothstep(0.42 - 0.14 * uFoam, 0.62 - 0.14 * uFoam, steep);
|
|
355
|
+
vec2 q = p.xz - uWind * uTime * 0.6;
|
|
356
|
+
float torn = noise(q * 0.3) * 0.55 + noise(q * 1.3) * 0.3 + noise(q * 4.1) * 0.15;
|
|
357
|
+
// Whitecaps come and go in groups: most crests carry none.
|
|
358
|
+
cap *= smoothstep(0.45, 0.72, torn) * smoothstep(0.45, 0.7, noise(q * 0.045 + 3.0)) * (1.0 - smoothstep(0.06, 0.4, t * pix));
|
|
359
|
+
vec3 white = ambient * 1.1 + cLight * uPower * max(uSun.y, 0.05) * 0.35;
|
|
360
|
+
col = mix(col, white, cap * 0.85);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Haze: the air between hides the sea in the horizon's colour.
|
|
364
|
+
float air = 1.0 - exp(-t / uHaze);
|
|
365
|
+
return mix(col, skyBase(normalize(vec3(rd.x, 0.0, rd.z))), air);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
void main() {
|
|
369
|
+
cZenith = oklabToLinear(uZenith);
|
|
370
|
+
cHorizon = oklabToLinear(uHorizon);
|
|
371
|
+
cGlow = oklabToLinear(uGlow);
|
|
372
|
+
cLight = oklabToLinear(uLight);
|
|
373
|
+
cDeep = oklabToLinear(uDeep);
|
|
374
|
+
cScatter = oklabToLinear(uScatter);
|
|
375
|
+
cCloud = oklabToLinear(uCloud);
|
|
376
|
+
|
|
377
|
+
vec2 uv = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
|
|
378
|
+
vec3 rd = normalize(uRight * uv.x + uUp * (uv.y - uLens.y) + uFwd * uLens.x);
|
|
379
|
+
float pix = 1.0 / (uLens.x * uRes.y);
|
|
380
|
+
float t = marchSea(uEye, rd, pix);
|
|
381
|
+
vec3 col = t < 0.0 ? skyColor(rd, pix) : seaColor(uEye, rd, t, pix);
|
|
382
|
+
|
|
383
|
+
col = oklabToSrgb(aces(col * uExposure));
|
|
384
|
+
col *= mix(1.0 - uQuiet.w, 1.0, quietOpen(uv));
|
|
385
|
+
col += (hash(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) / 255.0;
|
|
386
|
+
gl_FragColor = vec4(col, 1.0);
|
|
387
|
+
}
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Vec3 = [number, number, number];
|
|
2
|
+
|
|
3
|
+
/** The camera over the sea: world space x right, y up, z ahead, metres. */
|
|
4
|
+
export interface OceanView {
|
|
5
|
+
eye: Vec3;
|
|
6
|
+
right: Vec3;
|
|
7
|
+
up: Vec3;
|
|
8
|
+
forward: Vec3;
|
|
9
|
+
/** Focal length, in units of the frame's height. */
|
|
10
|
+
focal: number;
|
|
11
|
+
/** How far the lens is shifted, in units of the frame's height, to put the horizon in place. */
|
|
12
|
+
shift: number;
|
|
13
|
+
/** The frame's width over its height. */
|
|
14
|
+
aspect: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The camera `height` metres above the sea, looking slightly down, its lens shifted so the horizon sits at `horizon` (0–1 up the frame). `x` and `lift` move it, in metres. */
|
|
18
|
+
export function oceanView(options: { height: number; horizon: number; aspect: number; x?: number; lift?: number }): OceanView;
|
|
19
|
+
|
|
20
|
+
/** Where a point on the frame (x 0–1 from the left, y 0–1 from the bottom) looks: a unit vector. */
|
|
21
|
+
export function viewRay(view: OceanView, x: number, y: number): Vec3;
|
|
22
|
+
|
|
23
|
+
/** The direction towards the sun: the look's place (`x` across, `elevation` degrees), or an override's point on the frame; kept just clear of the horizon. */
|
|
24
|
+
export function sunDirection(view: OceanView, horizon: number, look: { x: number; elevation: number }, override?: { x?: number; y?: number } | null): Vec3;
|