Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(post): light shafts run along the sun's direction on screen under an orthographic camera; oracle scenes for shafts

yhhce0c09d5d7d7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 20f43c5b3..06e42dd8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@ published separately; it ships inside the editor.
- **A terrain brush stroke no longer makes the ground vanish for a moment.** An edited page of the ground used to be thrown away at once and rebuilt over the next frames, so the touched area had no ground to draw until it was done; it now goes on being drawn as it was, and changes in place.
- **Voxel Ground compiles on WebGPU again.** The Model shader's new wet-ground map left the voxel ground one texture past what a shader has units for, so its last texture was dropped and the whole shader was refused (`unresolved value 'u_wetMask'`). Voxel ground takes no wet map.
- **Several editors open at once can be told apart by an agent, and each grants on its own.** An editor advertises itself in a file of its own (its process id, its project, its port, its permission) instead of the one file the last editor to start overwrote. An agent attached to more than one gets `list_editors` and `select_editor` (or `--instance` / `ESTELLA_MCP_INSTANCE`), and until it chooses it is refused with the list rather than sent to whichever window won. It then drives the editor it chose and no other. The Read only / Can edit permission belongs to the editor window it is switched in and every editor starts read-only; it is no longer a saved setting that a second editor inherited. The Connect AI Tools dialog shows which editor it is.
-- **Fog, water, sky, rain and depth of field work under an orthographic camera.** Distance Fog, Height Fog (and its volumetric pass), Underwater, Sky Atmosphere with its clouds, Rain and Depth of Field measured how far a surface is from the camera starting at depth 0, which for an orthographic eye is a plane as far behind the camera as the far plane is ahead (the projection runs from -far to far so 2D content behind the camera still draws). Distance Fog read every surface as past its end and fogged a scene to full colour at any near and far, Height Fog added a camera-length of extra air, Underwater took the camera for being above the water and drew nothing, the cloud layer, placed by that height, stood kilometres off, so a floor above the clouds was still in their shadow, Rain drew its streak layers in front of surfaces a few units from the eye, and Depth of Field blurred what stood exactly at its focus distance. They now start from the plane the camera stands in. Perspective cameras are unchanged. Found by the closed-form render checks in `tools/oracle`, which draw spheres, floors and patches whose answer is a formula.
+- **Fog, water, sky, rain, depth of field and light shafts work under an orthographic camera.** Distance Fog, Height Fog (and its volumetric pass), Underwater, Sky Atmosphere with its clouds, Rain and Depth of Field measured how far a surface is from the camera starting at depth 0, which for an orthographic eye is a plane as far behind the camera as the far plane is ahead (the projection runs from -far to far so 2D content behind the camera still draws). Distance Fog read every surface as past its end and fogged a scene to full colour at any near and far, Height Fog added a camera-length of extra air, Underwater took the camera for being above the water and drew nothing, the cloud layer, placed by that height, stood kilometres off, so a floor above the clouds was still in their shadow, Rain drew its streak layers in front of surfaces a few units from the eye, and Depth of Field blurred what stood exactly at its focus distance. Light Shafts projected the sun to a place on screen, which an orthographic camera does not have (the sun is at infinity), so the shafts were gone; they now run along the sun's direction on screen, as strong as a 60 degree perspective camera would have them for the angle the view makes with the sun. The rest now start from the plane the camera stands in. Perspective cameras are unchanged. Found by the closed-form render checks in `tools/oracle`, which draw spheres, floors and patches whose answer is a formula.
### Changed
diff --git a/fixtures/scenes/oracle-shafts-ortho-high.esscene b/fixtures/scenes/oracle-shafts-ortho-high.esscene
new file mode 100644
index 000000000..5d88a3ec6
--- /dev/null
+++ b/fixtures/scenes/oracle-shafts-ortho-high.esscene
@@ -0,0 +1,123 @@
+{
+ "version": 4,
+ "name": "oracle-shafts-ortho-high",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "x": 0,
+ "y": 0,
+ "z": 0,
+ "w": 1
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 100,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Wall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": -100,
+ "z": -300
+ },
+ "scale": {
+ "x": 8,
+ "y": 2,
+ "z": 0.1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.5,
+ "g": 0.5,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Look",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "lightShafts",
+ "enabled": true,
+ "uniforms": {
+ "u_sunAzimuth": 180,
+ "u_sunElevation": 40,
+ "u_followSun": 0,
+ "u_intensity": 0.8,
+ "u_decay": 0.96,
+ "u_reach": 0.6
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-shafts-ortho-low-sun.esscene b/fixtures/scenes/oracle-shafts-ortho-low-sun.esscene
new file mode 100644
index 000000000..0679a5fcf
--- /dev/null
+++ b/fixtures/scenes/oracle-shafts-ortho-low-sun.esscene
@@ -0,0 +1,131 @@
+{
+ "version": 4,
+ "name": "oracle-shafts-ortho-low-sun",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "x": 0,
+ "y": 0,
+ "z": 0,
+ "w": 1
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 100,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Wall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": -100,
+ "z": -300
+ },
+ "scale": {
+ "x": 8,
+ "y": 2,
+ "z": 0.1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.5,
+ "g": 0.5,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Look",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "lightShafts",
+ "enabled": true,
+ "uniforms": {
+ "u_sunAzimuth": 180,
+ "u_sunElevation": 12,
+ "u_followSun": 0,
+ "u_intensity": 0.8,
+ "u_decay": 0.96,
+ "u_reach": 0.6
+ },
+ "colors": {
+ "u_sunColor": {
+ "r": 0.9,
+ "g": 0.9,
+ "b": 1,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-shafts-ortho.esscene b/fixtures/scenes/oracle-shafts-ortho.esscene
new file mode 100644
index 000000000..3bcf53d1c
--- /dev/null
+++ b/fixtures/scenes/oracle-shafts-ortho.esscene
@@ -0,0 +1,131 @@
+{
+ "version": 4,
+ "name": "oracle-shafts-ortho",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "x": 0,
+ "y": 0,
+ "z": 0,
+ "w": 1
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 100,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Wall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": -100,
+ "z": -300
+ },
+ "scale": {
+ "x": 8,
+ "y": 2,
+ "z": 0.1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.5,
+ "g": 0.5,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Look",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "lightShafts",
+ "enabled": true,
+ "uniforms": {
+ "u_sunAzimuth": 180,
+ "u_sunElevation": 20,
+ "u_followSun": 0,
+ "u_intensity": 1,
+ "u_decay": 0.96,
+ "u_reach": 0.6
+ },
+ "colors": {
+ "u_sunColor": {
+ "r": 1,
+ "g": 0.85,
+ "b": 0.6,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-shafts-perspective.esscene b/fixtures/scenes/oracle-shafts-perspective.esscene
new file mode 100644
index 000000000..245b960ee
--- /dev/null
+++ b/fixtures/scenes/oracle-shafts-perspective.esscene
@@ -0,0 +1,132 @@
+{
+ "version": 4,
+ "name": "oracle-shafts-perspective",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "x": 0,
+ "y": 0,
+ "z": 0,
+ "w": 1
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "orthoSize": 100,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0,
+ "fov": 70
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Wall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": -100,
+ "z": -300
+ },
+ "scale": {
+ "x": 8,
+ "y": 2,
+ "z": 0.1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.5,
+ "g": 0.5,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Look",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "lightShafts",
+ "enabled": true,
+ "uniforms": {
+ "u_sunAzimuth": 180,
+ "u_sunElevation": 20,
+ "u_followSun": 0,
+ "u_intensity": 1,
+ "u_decay": 0.96,
+ "u_reach": 0.6
+ },
+ "colors": {
+ "u_sunColor": {
+ "r": 1,
+ "g": 0.85,
+ "b": 0.6,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/sdk/src/postprocess/sources/lighting.ts b/sdk/src/postprocess/sources/lighting.ts
index f96208903..657bd334c 100644
--- a/sdk/src/postprocess/sources/lighting.ts
+++ b/sdk/src/postprocess/sources/lighting.ts
@@ -1027,16 +1027,34 @@ void main() {
float az = radians(u_sunAzimuth);
float el = radians(u_sunElevation);
vec3 sun = follow ? lightDir.xyz : vec3(cos(el) * sin(az), sin(el), cos(el) * cos(az));
- vec3 eye = worldFromDepth(v_texCoord, 0.0);
- vec4 clip = u_projection * vec4(eye + sun * 10000.0, 1.0);
- // Behind the camera there is no screen position to march toward.
- if (clip.w <= 1e-4) { fragColor = src; return; }
- vec2 sunUv = clip.xy / clip.w * 0.5 + 0.5;
-
ivec2 size = textureSize(u_sceneDepth, 0);
- vec2 toSun = (sunUv - v_texCoord) * u_reach;
float aspect = float(size.x) / float(size.y);
- float dist = length(vec2((sunUv.x - v_texCoord.x) * aspect, sunUv.y - v_texCoord.y));
+ vec2 toSun;
+ float dist;
+ if (u_camera.w > 0.5) {
+ vec3 eye = worldFromDepth(v_texCoord, 0.0);
+ vec4 clip = u_projection * vec4(eye + sun * 10000.0, 1.0);
+ // Behind the camera there is no screen position to march toward.
+ if (clip.w <= 1e-4) { fragColor = src; return; }
+ vec2 sunUv = clip.xy / clip.w * 0.5 + 0.5;
+ toSun = (sunUv - v_texCoord) * u_reach;
+ dist = length(vec2((sunUv.x - v_texCoord.x) * aspect, sunUv.y - v_texCoord.y));
+ } else {
+ // An orthographic camera has no place on screen for the sun: it is at infinity, and every ray is parallel. It is taken as a
+ // perspective camera of 60 degrees would have it, so the shafts keep their strength by how near the view is to facing the sun
+ // (dist = tan(angle off the axis) / tan(30 degrees), one value for the whole frame) and run along the sun's direction on screen.
+ // The rows of the view-projection are the camera's axes in the world, scaled.
+ vec3 right = normalize(vec3(u_projection[0][0], u_projection[1][0], u_projection[2][0]));
+ vec3 upAxis = normalize(vec3(u_projection[0][1], u_projection[1][1], u_projection[2][1]));
+ // The depth row of an orthographic projection is negative (it maps the view's -z onto +z), so its direction is where the camera looks.
+ vec3 forward = normalize(vec3(u_projection[0][2], u_projection[1][2], u_projection[2][2]));
+ float front = dot(sun, forward);
+ if (front <= 0.05) { fragColor = src; return; }
+ vec2 across = vec2(dot(sun, right), dot(sun, upAxis));
+ float reach2 = length(across);
+ dist = (reach2 / front) / 0.57735;
+ toSun = (reach2 > 1e-4 ? normalize(vec2(across.x / aspect, across.y)) : vec2(0.0)) * 0.5 * u_reach;
+ }
vec2 stepUv = toSun / float(SAMPLES);
vec2 uv = v_texCoord + stepUv * ign(gl_FragCoord.xy);
float light = 0.0;
@@ -1076,16 +1094,35 @@ fn ign(p : vec2f) -> f32 {
let el = radians(mc.u_sunElevation);
var sun = vec3f(cos(el) * sin(az), sin(el), cos(el) * cos(az));
if (follow) { sun = found.dir.xyz; }
- let eye = worldFromDepth(v.v_texCoord, 0.0);
- let clip = frame.projection * vec4f(eye + sun * 10000.0, 1.0);
- if (clip.w <= 1e-4) { return src; }
- // This device's uv runs down the rows, so clip y is flipped on the way back.
- let sunUv = vec2f(clip.x / clip.w * 0.5 + 0.5, 0.5 - clip.y / clip.w * 0.5);
-
let size = vec2i(textureDimensions(t7, 0));
- let toSun = (sunUv - v.v_texCoord) * mc.u_reach;
let aspect = f32(size.x) / f32(size.y);
- let dist = length(vec2f((sunUv.x - v.v_texCoord.x) * aspect, sunUv.y - v.v_texCoord.y));
+ var toSun = vec2f(0.0);
+ var dist = 0.0;
+ if (frame.camera.w > 0.5) {
+ let eye = worldFromDepth(v.v_texCoord, 0.0);
+ let clip = frame.projection * vec4f(eye + sun * 10000.0, 1.0);
+ if (clip.w <= 1e-4) { return src; }
+ // This device's uv runs down the rows, so clip y is flipped on the way back.
+ let sunUv = vec2f(clip.x / clip.w * 0.5 + 0.5, 0.5 - clip.y / clip.w * 0.5);
+ toSun = (sunUv - v.v_texCoord) * mc.u_reach;
+ dist = length(vec2f((sunUv.x - v.v_texCoord.x) * aspect, sunUv.y - v.v_texCoord.y));
+ } else {
+ // See the GLSL twin: an orthographic camera has the sun in a direction on screen and no place there.
+ let m = frame.projection;
+ let right = normalize(vec3f(m[0][0], m[1][0], m[2][0]));
+ let upAxis = normalize(vec3f(m[0][1], m[1][1], m[2][1]));
+ let forward = normalize(vec3f(m[0][2], m[1][2], m[2][2]));
+ let front = dot(sun, forward);
+ if (front <= 0.05) { return src; }
+ let across = vec2f(dot(sun, right), dot(sun, upAxis));
+ let reach2 = length(across);
+ dist = (reach2 / front) / 0.57735;
+ // Rows run down this device's picture, so the direction's up is minus y.
+ if (reach2 > 1e-4) {
+ let d = normalize(vec2f(across.x / aspect, across.y));
+ toSun = vec2f(d.x, -d.y) * 0.5 * mc.u_reach;
+ }
+ }
let stepUv = toSun / f32(SAMPLES);
var uv = v.v_texCoord + stepUv * ign(v.pos.xy);
var light = 0.0;
diff --git a/tools/oracle/lens.mjs b/tools/oracle/lens.mjs
index c45bb2e1c..f0131a682 100644
--- a/tools/oracle/lens.mjs
+++ b/tools/oracle/lens.mjs
@@ -7,11 +7,11 @@
* each and the two have to agree about a surface that is plainly 100 (or 400, or 2000) units below the eye.
*/
import { scene, camera, mesh, volume, probe, probeFrom, SIZE } from './scene.mjs';
-import { encodeLinear8, clamp01 } from './formulas.mjs';
+import { encodeLinear8, clamp01, srgbDecode } from './formulas.mjs';
const FLOOR_TOP = 5;
const FLOOR = 0.8;
-const fx = (type, uniforms) => ({ type, enabled: true, uniforms });
+const fx = (type, uniforms, colors) => ({ type, enabled: true, uniforms, ...(colors ? { colors } : {}) });
const eye = (ortho, drop, extra = {}) => camera({ ...(ortho ? {} : { projectionType: 0, fov: 40, nearPlane: 1 }), farPlane: 8000, ...extra });
/** The camera that stands `drop` units over the floor top. */
function placeCamera(doc, drop) {
@@ -102,6 +102,50 @@ function depthOfField({ id, ortho }) {
return { id, doc, colorSpace: 'linear', expect, about: `Depth of field, ${ortho ? 'orthographic' : 'perspective'}: the in-focus edge is sharp, the far one is blurred by the circle of confusion` };
}
+
+// ---- light shafts ----------------------------------------------------------------------------------------------------------------
+
+/**
+ * Light shafts: from each pixel, 40 samples march toward the sun on screen and add up how much of the way is open sky, each sample worth
+ * `decay` times the one before. The whole frame is sky above the horizon and a wall below it, so a pixel high in the sky has every sample
+ * open (and the clamped edge of the frame is sky too): it gains tint x S x falloff x intensity, with S = (1 - decay^40) / (1 - decay) / 40.
+ * A wall pixel far enough below the horizon that the march never reaches the sky gains nothing.
+ *
+ * `falloff` is 1 - smoothstep(0, 1.2, d), d the screen distance from the pixel to the sun. A perspective camera has the sun at a place on
+ * screen. An orthographic camera has no such place (the sun is at infinity, every ray is parallel), so it is taken as a perspective one
+ * of 60 degrees would have it: d = tan(angle off the view axis) / tan(30 degrees), the same for every pixel, and the march runs along the
+ * sun's direction on screen. A sun behind the view throws no shafts.
+ */
+function lightShafts({ id, ortho, sunElevation, tint = [1, 0.85, 0.6], intensity = 1 }) {
+ const DECAY = 0.96, REACH = 0.6, N = 40, FOV = 70;
+ const doc = scene(id, () => [
+ camera(ortho ? {} : { projectionType: 0, fov: FOV, nearPlane: 1, farPlane: 2000 }),
+ mesh('Wall', 'cube', [0, -100, -300], [8, 2, 0.1], [0.5, 0.5, 0.5], { lit: false }),
+ volume([fx('lightShafts', { u_sunAzimuth: 180, u_sunElevation: sunElevation, u_followSun: 0, u_intensity: intensity, u_decay: DECAY, u_reach: REACH }, { u_sunColor: { r: tint[0], g: tint[1], b: tint[2], a: 1 } })]),
+ ]);
+ doc.entities.find((e) => e.name === 'Camera').components[0].data.position = { x: 0, y: 0, z: 0 };
+ doc.entities.find((e) => e.name === 'Camera').components[0].data.rotation = { x: 0, y: 0, z: 0, w: 1 };
+ const el = (sunElevation * Math.PI) / 180;
+ const full = (1 - Math.pow(DECAY, N)) / (1 - DECAY) / N;
+ const tintLinear = tint.map(srgbDecode);
+ // Where the sun is on screen (up from the middle, as a share of the frame height) and how far a pixel is from it.
+ const tanA = Math.tan(el);
+ const sunUp = ortho ? null : 0.5 + (tanA / Math.tan((FOV * Math.PI) / 360)) * 0.5;
+ const fall = (d) => { const t = clamp01(d / 1.2); return 1 - t * t * (3 - 2 * t); };
+ const expect = [];
+ // High in the sky (rows 0.55 to 0.9 up from the bottom), every sample open.
+ for (const up of [0.58, 0.66, 0.74, 0.82, 0.9]) {
+ for (const across of [0.2, 0.5, 0.8]) {
+ const d = ortho ? tanA / Math.tan(Math.PI / 6) : Math.hypot((across - 0.5) * 1, up - sunUp);
+ const add = tintLinear.map((c) => c * full * fall(d) * intensity);
+ expect.push({ x: across, y: 1 - up, rgb: encodeLinear8(add), tol: 3 });
+ }
+ }
+ // Deep in the wall (the whole march stays inside it): the wall's own colour, untouched.
+ for (const up of ortho ? [0.06, 0.15] : [0.04, 0.08]) expect.push({ x: 0.5, y: 1 - up, rgb: encodeLinear8([0.5, 0.5, 0.5]), tol: 2 });
+ return { id, doc, colorSpace: 'linear', expect, about: `Light shafts, ${ortho ? 'orthographic' : 'perspective'}: open sky adds the sun's tint x S x falloff` };
+}
+
export const LENS_SCENES = [
rainWet({ id: 'oracle-rain-wet-ortho', ortho: true }),
rainWet({ id: 'oracle-rain-wet-perspective', ortho: false }),
@@ -111,4 +155,7 @@ export const LENS_SCENES = [
rainLayers({ id: 'oracle-rain-layers-far-perspective', ortho: false, drop: 2000, streaks: true }),
depthOfField({ id: 'oracle-dof-ortho', ortho: true }),
depthOfField({ id: 'oracle-dof-perspective', ortho: false }),
+ lightShafts({ id: 'oracle-shafts-perspective', ortho: false, sunElevation: 20 }),
+ lightShafts({ id: 'oracle-shafts-ortho', ortho: true, sunElevation: 20 }),
+ lightShafts({ id: 'oracle-shafts-ortho-low-sun', ortho: true, sunElevation: 12, tint: [0.9, 0.9, 1], intensity: 0.8 }),
];