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.

test(render): closed-form oracle scenes for volumetric height fog, with and without a shadowing ceiling

yhhbb580a1db7b9
diff --git a/fixtures/scenes/oracle-shafts-ortho-high.esscene b/fixtures/scenes/oracle-shafts-ortho-high.esscene
deleted file mode 100644
index 5d88a3ec6..000000000
--- a/fixtures/scenes/oracle-shafts-ortho-high.esscene
+++ /dev/null
@@ -1,123 +0,0 @@
-{
- "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-volumetric-ortho.esscene b/fixtures/scenes/oracle-volumetric-ortho.esscene
new file mode 100644
index 000000000..20e144b00
--- /dev/null
+++ b/fixtures/scenes/oracle-volumetric-ortho.esscene
@@ -0,0 +1,373 @@
+{
+ "version": 4,
+ "name": "oracle-volumetric-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": "Patch0",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -72,
+ "y": 0,
+ "z": -101
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": "Patch1",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -48,
+ "y": 0,
+ "z": -201
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 3,
+ "name": "Patch2",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -24,
+ "y": 0,
+ "z": -301
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 4,
+ "name": "Patch3",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -401
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 5,
+ "name": "Patch4",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 24,
+ "y": 0,
+ "z": -501
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 6,
+ "name": "Patch5",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 48,
+ "y": 0,
+ "z": -601
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 7,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 5.657130561438501e-17,
+ "x": -2.3432602026631493e-17,
+ "y": 0.9238795325112867,
+ "z": 0.3826834323650898
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 0.9,
+ "b": 0.8,
+ "a": 1
+ },
+ "intensity": 2,
+ "meshShadows": false,
+ "shadowExtent": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 8,
+ "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": "heightFog",
+ "enabled": true,
+ "uniforms": {
+ "u_density": 0.0033,
+ "u_heightFalloff": 0,
+ "u_baseHeight": 0,
+ "u_inscatter": 1,
+ "u_volumetric": 0.8,
+ "u_sunExponent": 8,
+ "u_followSun": 1,
+ "u_volumeRange": 3000
+ },
+ "colors": {
+ "u_fogColor": {
+ "r": 0.5,
+ "g": 0.6,
+ "b": 0.8,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-volumetric-perspective.esscene b/fixtures/scenes/oracle-volumetric-perspective.esscene
new file mode 100644
index 000000000..9bee6af25
--- /dev/null
+++ b/fixtures/scenes/oracle-volumetric-perspective.esscene
@@ -0,0 +1,374 @@
+{
+ "version": 4,
+ "name": "oracle-volumetric-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": 40
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Patch0",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -26.20585686716657,
+ "y": 0,
+ "z": -101
+ },
+ "scale": {
+ "x": 0.06551464216791643,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": "Patch1",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -34.941142489555425,
+ "y": 0,
+ "z": -201
+ },
+ "scale": {
+ "x": 0.13102928433583286,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 3,
+ "name": "Patch2",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -26.205856867166567,
+ "y": 0,
+ "z": -301
+ },
+ "scale": {
+ "x": 0.19654392650374927,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 4,
+ "name": "Patch3",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -401
+ },
+ "scale": {
+ "x": 0.2620585686716657,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 5,
+ "name": "Patch4",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 43.676428111944276,
+ "y": 0,
+ "z": -501
+ },
+ "scale": {
+ "x": 0.327573210839582,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 6,
+ "name": "Patch5",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 104.82342746866627,
+ "y": 0,
+ "z": -601
+ },
+ "scale": {
+ "x": 0.3930878530074983,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 7,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 5.657130561438501e-17,
+ "x": -2.3432602026631493e-17,
+ "y": 0.9238795325112867,
+ "z": 0.3826834323650898
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 0.9,
+ "b": 0.8,
+ "a": 1
+ },
+ "intensity": 2,
+ "meshShadows": false,
+ "shadowExtent": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 8,
+ "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": "heightFog",
+ "enabled": true,
+ "uniforms": {
+ "u_density": 0.0033,
+ "u_heightFalloff": 0,
+ "u_baseHeight": 0,
+ "u_inscatter": 1,
+ "u_volumetric": 0.8,
+ "u_sunExponent": 8,
+ "u_followSun": 1,
+ "u_volumeRange": 3000
+ },
+ "colors": {
+ "u_fogColor": {
+ "r": 0.5,
+ "g": 0.6,
+ "b": 0.8,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-volumetric-shadow-ortho.esscene b/fixtures/scenes/oracle-volumetric-shadow-ortho.esscene
new file mode 100644
index 000000000..119317e18
--- /dev/null
+++ b/fixtures/scenes/oracle-volumetric-shadow-ortho.esscene
@@ -0,0 +1,413 @@
+{
+ "version": 4,
+ "name": "oracle-volumetric-shadow-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": "Patch0",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -72,
+ "y": 0,
+ "z": -101
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": "Patch1",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -48,
+ "y": 0,
+ "z": -201
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 3,
+ "name": "Patch2",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -24,
+ "y": 0,
+ "z": -301
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 4,
+ "name": "Patch3",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -401
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 5,
+ "name": "Patch4",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 24,
+ "y": 0,
+ "z": -501
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 6,
+ "name": "Patch5",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 48,
+ "y": 0,
+ "z": -601
+ },
+ "scale": {
+ "x": 0.18,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 7,
+ "name": "Ceiling",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 52.5,
+ "z": -225
+ },
+ "scale": {
+ "x": 4,
+ "y": 0.05,
+ "z": 1.5
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.3,
+ "g": 0.3,
+ "b": 0.3,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 8,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 5.657130561438501e-17,
+ "x": -2.3432602026631493e-17,
+ "y": 0.9238795325112867,
+ "z": 0.3826834323650898
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 0.9,
+ "b": 0.8,
+ "a": 1
+ },
+ "intensity": 2,
+ "meshShadows": true,
+ "shadowExtent": 700
+ }
+ }
+ ]
+ },
+ {
+ "id": 9,
+ "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": "heightFog",
+ "enabled": true,
+ "uniforms": {
+ "u_density": 0.0033,
+ "u_heightFalloff": 0,
+ "u_baseHeight": 0,
+ "u_inscatter": 1,
+ "u_volumetric": 0.8,
+ "u_sunExponent": 8,
+ "u_followSun": 1,
+ "u_volumeRange": 3000
+ },
+ "colors": {
+ "u_fogColor": {
+ "r": 0.5,
+ "g": 0.6,
+ "b": 0.8,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/oracle-volumetric-shadow-perspective.esscene b/fixtures/scenes/oracle-volumetric-shadow-perspective.esscene
new file mode 100644
index 000000000..f6be34ba5
--- /dev/null
+++ b/fixtures/scenes/oracle-volumetric-shadow-perspective.esscene
@@ -0,0 +1,414 @@
+{
+ "version": 4,
+ "name": "oracle-volumetric-shadow-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": 40
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Patch0",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -26.20585686716657,
+ "y": 0,
+ "z": -101
+ },
+ "scale": {
+ "x": 0.06551464216791643,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": "Patch1",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -34.941142489555425,
+ "y": 0,
+ "z": -201
+ },
+ "scale": {
+ "x": 0.13102928433583286,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 3,
+ "name": "Patch2",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -26.205856867166567,
+ "y": 0,
+ "z": -301
+ },
+ "scale": {
+ "x": 0.19654392650374927,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 4,
+ "name": "Patch3",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -401
+ },
+ "scale": {
+ "x": 0.2620585686716657,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 5,
+ "name": "Patch4",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 43.676428111944276,
+ "y": 0,
+ "z": -501
+ },
+ "scale": {
+ "x": 0.327573210839582,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 6,
+ "name": "Patch5",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 104.82342746866627,
+ "y": 0,
+ "z": -601
+ },
+ "scale": {
+ "x": 0.3930878530074983,
+ "y": 0.4,
+ "z": 0.02
+ }
+ }
+ },
+ {
+ "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": 7,
+ "name": "Ceiling",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 52.5,
+ "z": -225
+ },
+ "scale": {
+ "x": 4,
+ "y": 0.05,
+ "z": 1.5
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.3,
+ "g": 0.3,
+ "b": 0.3,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 8,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 5.657130561438501e-17,
+ "x": -2.3432602026631493e-17,
+ "y": 0.9238795325112867,
+ "z": 0.3826834323650898
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 0.9,
+ "b": 0.8,
+ "a": 1
+ },
+ "intensity": 2,
+ "meshShadows": true,
+ "shadowExtent": 700
+ }
+ }
+ ]
+ },
+ {
+ "id": 9,
+ "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": "heightFog",
+ "enabled": true,
+ "uniforms": {
+ "u_density": 0.0033,
+ "u_heightFalloff": 0,
+ "u_baseHeight": 0,
+ "u_inscatter": 1,
+ "u_volumetric": 0.8,
+ "u_sunExponent": 8,
+ "u_followSun": 1,
+ "u_volumeRange": 3000
+ },
+ "colors": {
+ "u_fogColor": {
+ "r": 0.5,
+ "g": 0.6,
+ "b": 0.8,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tools/oracle/index.mjs b/tools/oracle/index.mjs
index 12599b232..849cf9819 100644
--- a/tools/oracle/index.mjs
+++ b/tools/oracle/index.mjs
@@ -9,8 +9,9 @@ import { SHADOW_SCENES } from './shadows.mjs';
import { POST_SCENES } from './post.mjs';
import { SKY_SCENES } from './sky.mjs';
import { LENS_SCENES } from './lens.mjs';
+import { VOLUMETRIC_SCENES } from './volumetric.mjs';
-export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES, ...LENS_SCENES];
+export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES, ...LENS_SCENES, ...VOLUMETRIC_SCENES];
/** The renderScenes.mjs entry for one oracle scene. */
export const oracleEntry = (o) => ({
diff --git a/tools/oracle/volumetric.mjs b/tools/oracle/volumetric.mjs
new file mode 100644
index 000000000..65c52f9c7
--- /dev/null
+++ b/tools/oracle/volumetric.mjs
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file volumetric.mjs — oracle scenes for the sun's light through height fog (Height Fog with Volumetric above 0).
+ *
+ * The camera looks along -Z at six flat patches standing at different distances, through a fog of constant density. For a ray of
+ * length L the fog covers 1 - exp(-density x L) of the patch, and with the sun's light scattered toward the eye by the air that it
+ * reaches, the frame adds tint x lit x phase x inscatter x volumetric x strength , where
+ * lit = the integral over the ray of visible(p) x density x exp(-density x s) ds (visible: 1 where the sun reaches the air),
+ * phase = Henyey-Greenstein, g = 0.55, of the angle between the ray and the sun,
+ * strength = the light's intensity / 2.
+ * With no shadow in the scene `visible` is 1 and lit = 1 - exp(-tau): the whole of what the fog scatters. With a ceiling that casts a
+ * shadow over part of the ray, `visible` is a ray from the air toward the sun that meets a box or does not.
+ */
+import { scene, camera, mesh, sun, volume, SIZE, HALF } from './scene.mjs';
+import { sunAim, dot, norm, sub, encodeLinear8, clamp01, srgbDecode } from './formulas.mjs';
+
+const DENSITY = 0.0033, INSCATTER = 1.0, VOLUMETRIC = 0.8, SUN_EXPONENT = 8, FOV = 40, NEAR = 1;
+const FOG = [0.5, 0.6, 0.8];
+const LIGHT_COLOUR = [1, 0.9, 0.8], LIGHT_INTENSITY = 2;
+const PATCH = 0.5;
+const DISTANCES = [100, 200, 300, 400, 500, 600];
+
+const slab = (origin, dir, box) => {
+ let t0 = 0, t1 = Infinity;
+ for (let a = 0; a < 3; a++) {
+ if (Math.abs(dir[a]) < 1e-9) { if (origin[a] < box.min[a] || origin[a] > box.max[a]) return false; continue; }
+ let ta = (box.min[a] - origin[a]) / dir[a], tb = (box.max[a] - origin[a]) / dir[a];
+ if (ta > tb) [ta, tb] = [tb, ta];
+ t0 = Math.max(t0, ta); t1 = Math.min(t1, tb);
+ if (t0 > t1) return false;
+ }
+ return true;
+};
+const phaseHG = (c) => { const g = 0.55; return ((1 - g * g) / Math.pow(Math.max(1 + g * g - 2 * g * c, 1e-3), 1.5)) * 0.25; };
+
+function volumetricFog({ id, ortho, shadows }) {
+ const aim = sunAim(45, 180); // the sun is ahead of the camera and 45 degrees up: toLight = (0, 0.707, -0.707)
+ const tanHalf = Math.tan((FOV * Math.PI) / 360);
+ // Where each patch stands: a column of the frame, at its own distance. A perspective camera sees a patch of width w at distance d as
+ // w / (2 d tan(fov/2)) of the frame, so the columns and widths scale with d to keep the same shares.
+ const columns = [0.14, 0.26, 0.38, 0.5, 0.62, 0.74];
+ const patches = DISTANCES.map((d, i) => {
+ const half = ortho ? HALF : d * tanHalf;
+ const cx = (columns[i] - 0.5) * 2 * half, w = 0.09 * 2 * half;
+ return { d, x: cx, box: { min: [cx - w / 2, -20, -d - 2], max: [cx + w / 2, 20, -d] } };
+ });
+ const ceiling = { min: [-200, 50, -300], max: [200, 55, -150] };
+ const boxes = [...patches.map((p) => p.box), ...(shadows ? [ceiling] : [])];
+ const doc = scene(id, () => [
+ camera(ortho ? {} : { projectionType: 0, fov: FOV, nearPlane: NEAR, farPlane: 2000 }),
+ ...patches.map((p, i) => mesh(`Patch${i}`, 'cube', [p.x, 0, -p.d - 1], [(p.box.max[0] - p.box.min[0]) / 100, 0.4, 0.02], [PATCH, PATCH, PATCH], { lit: false })),
+ ...(shadows ? [mesh('Ceiling', 'cube', [0, 52.5, -225], [4, 0.05, 1.5], [0.3, 0.3, 0.3], { lit: false })] : []),
+ sun(aim, LIGHT_INTENSITY, LIGHT_COLOUR, { meshShadows: shadows, shadowExtent: shadows ? 700 : 0 }),
+ volume([{ type: 'heightFog', enabled: true, uniforms: { u_density: DENSITY, u_heightFalloff: 0, u_baseHeight: 0, u_inscatter: INSCATTER, u_volumetric: VOLUMETRIC, u_sunExponent: SUN_EXPONENT, u_followSun: 1, u_volumeRange: 3000 },
+ colors: { u_fogColor: { r: FOG[0], g: FOG[1], b: FOG[2], a: 1 } } }]),
+ ]);
+ const cam = doc.entities.find((e) => e.name === 'Camera');
+ cam.components[0].data.position = { x: 0, y: 0, z: 0 };
+ cam.components[0].data.rotation = { x: 0, y: 0, z: 0, w: 1 };
+
+ const lightLinear = LIGHT_COLOUR.map(srgbDecode), top = Math.max(...lightLinear);
+ const tint = lightLinear.map((c) => c / top), fog = FOG.map(srgbDecode);
+ const strength = Math.min(Math.max(LIGHT_INTENSITY, 0), 8) * 0.5;
+ const visible = (p) => (shadows ? !boxes.some((b) => slab(p, aim.toLight, b)) : true);
+
+ const expect = patches.map((patch, i) => {
+ const target = [patch.x, 0, -patch.d], eye = [0, 0, 0];
+ let dir, entry, len;
+ if (ortho) { dir = [0, 0, -1]; entry = [patch.x, 0, 0]; len = patch.d; }
+ else {
+ const toP = sub(target, eye), full = Math.hypot(...toP), s = NEAR / patch.d;
+ dir = toP.map((v) => v / full); entry = toP.map((v) => v * s); len = (1 - s) * full;
+ }
+ const tau = DENSITY * len, amount = 1 - Math.exp(-tau);
+ const glow = Math.pow(Math.max(dot(dir, aim.toLight), 0), SUN_EXPONENT), shaped = glow * (1 - VOLUMETRIC);
+ const k = clamp01(shaped * INSCATTER);
+ const colour = fog.map((f, c) => f + (tint[c] - f) * k);
+ const base = colour.map((c) => PATCH + (c - PATCH) * clamp01(amount));
+ // The scattered sun: the air's density x the light that reaches it, summed along the ray with the fog already in front of it.
+ const N = 1500, ds = len / N;
+ let lit = 0;
+ for (let n = 0; n < N; n++) {
+ const sdist = (n + 0.5) * ds, p = [entry[0] + dir[0] * sdist, entry[1] + dir[1] * sdist, entry[2] + dir[2] * sdist];
+ if (visible(p)) lit += DENSITY * Math.exp(-DENSITY * sdist) * ds;
+ }
+ const add = tint.map((t) => t * lit * phaseHG(dot(dir, aim.toLight)) * INSCATTER * VOLUMETRIC * strength);
+ const rgb = base.map((b, c) => b + add[c]);
+ // The patch's column, at its middle row; a perspective patch is seen at its own scale.
+ const half = ortho ? HALF : patch.d * tanHalf;
+ const fx = Math.min(SIZE - 1, Math.floor((patch.x / (2 * half) + 0.5) * SIZE));
+ return { x: fx / (SIZE - 1), y: 0.5, rgb: encodeLinear8(rgb.map(clamp01)), tol: shadows ? 8 : 5 };
+ });
+ return { id, doc, colorSpace: 'linear', expect,
+ about: `Volumetric height fog, ${ortho ? 'orthographic' : 'perspective'}${shadows ? ', a ceiling shadowing part of the ray' : ''}: the sun scattered by the air, closed form` };
+}
+
+export const VOLUMETRIC_SCENES = [
+ volumetricFog({ id: 'oracle-volumetric-ortho', ortho: true, shadows: false }),
+ volumetricFog({ id: 'oracle-volumetric-perspective', ortho: false, shadows: false }),
+ volumetricFog({ id: 'oracle-volumetric-shadow-ortho', ortho: true, shadows: true }),
+ volumetricFog({ id: 'oracle-volumetric-shadow-perspective', ortho: false, shadows: true }),
+];