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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
test(render): oracle scenes for SSAO, GTAO and SSR - flat floors stay clean, the radius is a world edge, a mirror shows the box times fresnel and gloss
yhhff2ebdffbc30
diff --git a/fixtures/scenes/oracle-gtao-flat.esscene b/fixtures/scenes/oracle-gtao-flat.esscenenew file mode 100644index 000000000..265eb4a59--- /dev/null+++ b/fixtures/scenes/oracle-gtao-flat.esscene@@ -0,0 +1,122 @@+{+ "version": 4,+ "name": "oracle-gtao-flat",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 250,+ "z": 300+ },+ "rotation": {+ "x": -0.27563735581699916,+ "y": 0,+ "z": 0,+ "w": 0.9612616959383189+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "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": "gtao",+ "enabled": true,+ "uniforms": {+ "u_radius": 40,+ "u_intensity": 1,+ "u_power": 1.4,+ "u_thickness": 0.5+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-gtao-radius-small.esscene b/fixtures/scenes/oracle-gtao-radius-small.esscenenew file mode 100644index 000000000..c4711b845--- /dev/null+++ b/fixtures/scenes/oracle-gtao-radius-small.esscene@@ -0,0 +1,161 @@+{+ "version": 4,+ "name": "oracle-gtao-radius-small",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 6.8,+ "z": 0+ },+ "scale": {+ "x": 0.4,+ "y": 0.036,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "gtao",+ "enabled": true,+ "uniforms": {+ "u_radius": 12,+ "u_intensity": 1,+ "u_power": 1.4,+ "u_thickness": 0.5+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-gtao-radius.esscene b/fixtures/scenes/oracle-gtao-radius.esscenenew file mode 100644index 000000000..04972d0b2--- /dev/null+++ b/fixtures/scenes/oracle-gtao-radius.esscene@@ -0,0 +1,161 @@+{+ "version": 4,+ "name": "oracle-gtao-radius",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 9.5,+ "z": 0+ },+ "scale": {+ "x": 0.4,+ "y": 0.09,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "gtao",+ "enabled": true,+ "uniforms": {+ "u_radius": 30,+ "u_intensity": 1,+ "u_power": 1.4,+ "u_thickness": 0.5+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssao-flat.esscene b/fixtures/scenes/oracle-ssao-flat.esscenenew file mode 100644index 000000000..b1472f0ca--- /dev/null+++ b/fixtures/scenes/oracle-ssao-flat.esscene@@ -0,0 +1,122 @@+{+ "version": 4,+ "name": "oracle-ssao-flat",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 250,+ "z": 300+ },+ "rotation": {+ "x": -0.27563735581699916,+ "y": 0,+ "z": 0,+ "w": 0.9612616959383189+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "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": "ssao",+ "enabled": true,+ "uniforms": {+ "u_radius": 40,+ "u_intensity": 1,+ "u_bias": 0.12,+ "u_power": 1.6+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssao-radius-small.esscene b/fixtures/scenes/oracle-ssao-radius-small.esscenenew file mode 100644index 000000000..6a06f73ea--- /dev/null+++ b/fixtures/scenes/oracle-ssao-radius-small.esscene@@ -0,0 +1,161 @@+{+ "version": 4,+ "name": "oracle-ssao-radius-small",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 6.8,+ "z": 0+ },+ "scale": {+ "x": 0.4,+ "y": 0.036,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssao",+ "enabled": true,+ "uniforms": {+ "u_radius": 12,+ "u_intensity": 1,+ "u_bias": 0.12,+ "u_power": 1.6+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssao-radius.esscene b/fixtures/scenes/oracle-ssao-radius.esscenenew file mode 100644index 000000000..0ce986d09--- /dev/null+++ b/fixtures/scenes/oracle-ssao-radius.esscene@@ -0,0 +1,161 @@+{+ "version": 4,+ "name": "oracle-ssao-radius",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 9.5,+ "z": 0+ },+ "scale": {+ "x": 0.4,+ "y": 0.09,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssao",+ "enabled": true,+ "uniforms": {+ "u_radius": 30,+ "u_intensity": 1,+ "u_bias": 0.12,+ "u_power": 1.6+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-dielectric.esscene b/fixtures/scenes/oracle-ssr-dielectric.esscenenew file mode 100644index 000000000..fa1d84ccb--- /dev/null+++ b/fixtures/scenes/oracle-ssr-dielectric.esscene@@ -0,0 +1,164 @@+{+ "version": 4,+ "name": "oracle-ssr-dielectric",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 230,+ "z": 280+ },+ "rotation": {+ "x": -0.3007057995042731,+ "y": 0,+ "z": 0,+ "w": 0.9537169507482269+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/oracle-ssr-dielectric_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 50,+ "z": -160+ },+ "scale": {+ "x": 1.2,+ "y": 0.9,+ "z": 0.2+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.35,+ "b": 0.2,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssr",+ "enabled": true,+ "uniforms": {+ "u_intensity": 1,+ "u_maxDistance": 700,+ "u_thickness": 12,+ "u_floorBias": 0,+ "u_skyReflection": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-dielectric_m0.esmaterial b/fixtures/scenes/oracle-ssr-dielectric_m0.esmaterialnew file mode 100644index 000000000..438117c45--- /dev/null+++ b/fixtures/scenes/oracle-ssr-dielectric_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 0,+ "u_roughness": 0.05+ }+}diff --git a/fixtures/scenes/oracle-ssr-glossy.esscene b/fixtures/scenes/oracle-ssr-glossy.esscenenew file mode 100644index 000000000..b1ffc09a8--- /dev/null+++ b/fixtures/scenes/oracle-ssr-glossy.esscene@@ -0,0 +1,164 @@+{+ "version": 4,+ "name": "oracle-ssr-glossy",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 230,+ "z": 280+ },+ "rotation": {+ "x": -0.3007057995042731,+ "y": 0,+ "z": 0,+ "w": 0.9537169507482269+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/oracle-ssr-glossy_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 50,+ "z": -160+ },+ "scale": {+ "x": 1.2,+ "y": 0.9,+ "z": 0.2+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.35,+ "b": 0.2,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssr",+ "enabled": true,+ "uniforms": {+ "u_intensity": 1,+ "u_maxDistance": 700,+ "u_thickness": 12,+ "u_floorBias": 0,+ "u_skyReflection": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-glossy_m0.esmaterial b/fixtures/scenes/oracle-ssr-glossy_m0.esmaterialnew file mode 100644index 000000000..e49215be1--- /dev/null+++ b/fixtures/scenes/oracle-ssr-glossy_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 1,+ "u_roughness": 0.4+ }+}diff --git a/fixtures/scenes/oracle-ssr-half.esscene b/fixtures/scenes/oracle-ssr-half.esscenenew file mode 100644index 000000000..f26fd1213--- /dev/null+++ b/fixtures/scenes/oracle-ssr-half.esscene@@ -0,0 +1,164 @@+{+ "version": 4,+ "name": "oracle-ssr-half",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 230,+ "z": 280+ },+ "rotation": {+ "x": -0.3007057995042731,+ "y": 0,+ "z": 0,+ "w": 0.9537169507482269+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/oracle-ssr-half_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 50,+ "z": -160+ },+ "scale": {+ "x": 1.2,+ "y": 0.9,+ "z": 0.2+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.35,+ "b": 0.2,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssr",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0.5,+ "u_maxDistance": 700,+ "u_thickness": 12,+ "u_floorBias": 0,+ "u_skyReflection": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-half_m0.esmaterial b/fixtures/scenes/oracle-ssr-half_m0.esmaterialnew file mode 100644index 000000000..7d9185b86--- /dev/null+++ b/fixtures/scenes/oracle-ssr-half_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 1,+ "u_roughness": 0.05+ }+}diff --git a/fixtures/scenes/oracle-ssr-mirror.esscene b/fixtures/scenes/oracle-ssr-mirror.esscenenew file mode 100644index 000000000..2c02eba13--- /dev/null+++ b/fixtures/scenes/oracle-ssr-mirror.esscene@@ -0,0 +1,164 @@+{+ "version": 4,+ "name": "oracle-ssr-mirror",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 230,+ "z": 280+ },+ "rotation": {+ "x": -0.3007057995042731,+ "y": 0,+ "z": 0,+ "w": 0.9537169507482269+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/oracle-ssr-mirror_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 50,+ "z": -160+ },+ "scale": {+ "x": 1.2,+ "y": 0.9,+ "z": 0.2+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.35,+ "b": 0.2,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssr",+ "enabled": true,+ "uniforms": {+ "u_intensity": 1,+ "u_maxDistance": 700,+ "u_thickness": 12,+ "u_floorBias": 0,+ "u_skyReflection": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-mirror_m0.esmaterial b/fixtures/scenes/oracle-ssr-mirror_m0.esmaterialnew file mode 100644index 000000000..7d9185b86--- /dev/null+++ b/fixtures/scenes/oracle-ssr-mirror_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 1,+ "u_roughness": 0.05+ }+}diff --git a/fixtures/scenes/oracle-ssr-rough.esscene b/fixtures/scenes/oracle-ssr-rough.esscenenew file mode 100644index 000000000..45bb1227a--- /dev/null+++ b/fixtures/scenes/oracle-ssr-rough.esscene@@ -0,0 +1,164 @@+{+ "version": 4,+ "name": "oracle-ssr-rough",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 230,+ "z": 280+ },+ "rotation": {+ "x": -0.3007057995042731,+ "y": 0,+ "z": 0,+ "w": 0.9537169507482269+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0,+ "fov": 50+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 8,+ "y": 0.1,+ "z": 8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/oracle-ssr-rough_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Box",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 50,+ "z": -160+ },+ "scale": {+ "x": 1.2,+ "y": 0.9,+ "z": 0.2+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.35,+ "b": 0.2,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "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": "ssr",+ "enabled": true,+ "uniforms": {+ "u_intensity": 1,+ "u_maxDistance": 700,+ "u_thickness": 12,+ "u_floorBias": 0,+ "u_skyReflection": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-ssr-rough_m0.esmaterial b/fixtures/scenes/oracle-ssr-rough_m0.esmaterialnew file mode 100644index 000000000..c61ba2f9a--- /dev/null+++ b/fixtures/scenes/oracle-ssr-rough_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 1,+ "u_roughness": 0.9+ }+}diff --git a/tools/check-render-scenes.mjs b/tools/check-render-scenes.mjsindex cc9e9232c..fc661c6c1 100644--- a/tools/check-render-scenes.mjs+++ b/tools/check-render-scenes.mjs@@ -68,6 +68,12 @@ for (const s of SCENES) {if (!existsSync(file) || readFileSync(file, 'utf8').split(String.fromCharCode(13)).join('') !== want) {fail(`"${o.id}" is not what tools/oracle generates — run node tools/make-oracle-scenes.mjs`);}+ for (const [name, body] of Object.entries(o.files ?? {})) {+ const extra = path.join(FIXTURES, 'scenes', name), content = JSON.stringify(body, null, 2) + String.fromCharCode(10);+ if (!existsSync(extra) || readFileSync(extra, 'utf8').split(String.fromCharCode(13)).join('') !== content) {+ fail(`"${name}" is not what tools/oracle generates — run node tools/make-oracle-scenes.mjs`);+ }+ }if (!o.expect?.length && !o.twins?.pairs?.length && !o.count?.length) fail(`"${o.id}" has no probes`);}}diff --git a/tools/make-oracle-scenes.mjs b/tools/make-oracle-scenes.mjsindex 840ed19cc..9e0ef9301 100644--- a/tools/make-oracle-scenes.mjs+++ b/tools/make-oracle-scenes.mjs@@ -20,6 +20,13 @@ for (const o of ORACLE) {if (check) {if (!existsSync(file) || readFileSync(file, 'utf8').replace(/\r\n/g, '\n') !== text) { console.error(`stale: ${o.id}`); stale++; }} else writeFileSync(file, text);+ // Files a scene loads beside it (a material), written the same way.+ for (const [name, body] of Object.entries(o.files ?? {})) {+ const extra = path.join(OUT, name), content = JSON.stringify(body, null, 2) + String.fromCharCode(10);+ if (check) {+ if (!existsSync(extra) || readFileSync(extra, 'utf8').split(String.fromCharCode(13)).join('') !== content) { console.error(`stale: ${name}`); stale++; }+ } else writeFileSync(extra, content);+ }}if (check && stale) { console.error('make-oracle-scenes: run `node tools/make-oracle-scenes.mjs`'); process.exit(1); }console.log(`make-oracle-scenes: ${ORACLE.length} scene(s) ${check ? 'up to date' : 'written'}`);diff --git a/tools/oracle/index.mjs b/tools/oracle/index.mjsindex 9366a5916..4e7227fdb 100644--- a/tools/oracle/index.mjs+++ b/tools/oracle/index.mjs@@ -11,8 +11,10 @@ import { SKY_SCENES } from './sky.mjs';import { LENS_SCENES } from './lens.mjs';import { VOLUMETRIC_SCENES } from './volumetric.mjs';import { EXPOSURE_SCENES } from './exposure.mjs';+import { OCCLUSION_SCENES } from './occlusion.mjs';+import { REFLECTION_SCENES } from './reflection.mjs';-export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES, ...LENS_SCENES, ...VOLUMETRIC_SCENES, ...EXPOSURE_SCENES];+export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES, ...LENS_SCENES, ...VOLUMETRIC_SCENES, ...EXPOSURE_SCENES, ...OCCLUSION_SCENES, ...REFLECTION_SCENES];/** The renderScenes.mjs entry for one oracle scene. */export const oracleEntry = (o) => ({@@ -22,8 +24,10 @@ export const oracleEntry = (o) => ({ESTELLA_VERIFY_W: String(SIZE), ESTELLA_VERIFY_H: String(SIZE), ESTELLA_VERIFY_STEPS: '3',...(o.colorSpace === 'linear' ? { ESTELLA_VERIFY_COLORSPACE: 'linear' } : {}),...(o.outputTransform ? { ESTELLA_VERIFY_OUTPUT_TRANSFORM: o.outputTransform } : {}),- ...(o.expect ? { ESTELLA_VERIFY_EXPECT: JSON.stringify(o.expect) } : {}),- ...(o.count ? { ESTELLA_VERIFY_COUNT: JSON.stringify(o.count) } : {}),+ // ORACLE_PROBES='[[x,y],...]' (frame fractions from the top-left) reads those pixels too, as failing probes, so their values print.+ ...(o.expect || process.env.ORACLE_PROBES ? { ESTELLA_VERIFY_EXPECT: JSON.stringify([...(o.expect ?? []), ...JSON.parse(process.env.ORACLE_PROBES ?? '[]').map(([x, y]) => ({ x, y, rgb: [1, 2, 3], tol: 0 }))]) } : {}),+ // ORACLE_DUMP=1 adds a count that cannot hold, so the run fails and prints what every count measured (and every probe read).+ ...(o.count || process.env.ORACLE_DUMP ? { ESTELLA_VERIFY_COUNT: JSON.stringify([...(o.count ?? []), ...(process.env.ORACLE_DUMP ? [{ rgb: [1, 2, 3], tol: 0, atLeast: SIZE * SIZE + 1 }] : [])]) } : {}),...(o.uniform ? { ESTELLA_VERIFY_UNIFORM: '1' } : {}),...(o.play ? { ESTELLA_VERIFY_PLAY: '1' } : {}),...(o.twins ? { ESTELLA_VERIFY_TWINS: JSON.stringify(o.twins) } : {}),diff --git a/tools/oracle/occlusion.mjs b/tools/oracle/occlusion.mjsnew file mode 100644index 000000000..b157756c2--- /dev/null+++ b/tools/oracle/occlusion.mjs@@ -0,0 +1,93 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file occlusion.mjs — oracle scenes for SSAO and GTAO.+ *+ * Both estimate how closed-in a point is from the depth buffer, with a few rotated samples per pixel, so a pixel's exact value is the+ * estimator's noise and not a formula. What they promise is not noise, and that is what is checked:+ *+ * - An open flat surface is not occluded by itself: the floor stays exactly its own colour, at a steep angle and at a grazing one.+ * - The radius is a WORLD length and a hard edge to what counts as an occluder: a floor farther from a tall box than the radius is+ * exactly its own colour, and a floor well inside the radius is darker. Counted over the whole frame by the pixels' distance to the+ * box, which is geometry.+ *+ * The box is brighter than the floor (code 255 against 231), so the pixels that are neither are the floor's darkened ones.+ */+import { scene, camera, mesh, volume, SIZE, HALF } from './scene.mjs';+import { encodeLinear8, axisAngle, norm, rotate, dot } from './formulas.mjs';++const FLOOR = 0.8;+const fx = (type, uniforms) => ({ type, enabled: true, uniforms });+const PX_PER_UNIT = SIZE / (2 * HALF);++/**+ * Radius test. A 40 x 40 box, a third of the radius tall, in the middle of a floor seen from straight above. Its height is what+ * matters: a sample counts as an occluder only inside the radius in THREE dimensions, so a box taller than the radius occludes nothing+ * from above, and one a third of it casts its shade out to about the radius.+ */+function radiusTest({ id, effect, radius }) {+ const BOX_HALF = 20, BOX_HEIGHT = radius * 0.3;+ const doc = scene(id, () => [+ camera(), mesh('Floor', 'cube', [0, 0, 0], [4, 0.1, 4], [FLOOR, FLOOR, FLOOR], { lit: false }),+ mesh('Box', 'cube', [0, 5 + BOX_HEIGHT / 2, 0], [0.4, BOX_HEIGHT / 100, 0.4], [1, 1, 1], { lit: false }),+ volume([fx(effect, effect === 'ssao' ? { u_radius: radius, u_intensity: 1, u_bias: 0.12, u_power: 1.6 } : { u_radius: radius, u_intensity: 1, u_power: 1.4, u_thickness: 0.5 })]),+ ]);+ // The distance, in world units, from each pixel's centre to the box's square on the floor.+ let far = 0, near = 0, inside = 0, mid = 0;+ for (let j = 0; j < SIZE; j++) {+ for (let i = 0; i < SIZE; i++) {+ const x = ((i + 0.5) / SIZE - 0.5) * 2 * HALF, z = ((j + 0.5) / SIZE - 0.5) * 2 * HALF;+ const dx = Math.max(Math.abs(x) - BOX_HALF, 0), dz = Math.max(Math.abs(z) - BOX_HALF, 0), d = Math.hypot(dx, dz);+ if (d === 0) continue; // the box's own top+ const texel = 1 / PX_PER_UNIT;+ if (d > radius * 1.15 + 3 * texel) far++; // beyond the radius, with a few texels for the blur and the upsample+ if (d > radius * 0.35) mid++; // anything nearer than this must have been darkened+ if (d < radius * 0.12) near++; // at the foot of the box+ if (d < radius * 1.15 + 3 * texel) inside++; // nothing outside the radius is darkened+ }+ }+ const floor = encodeLinear8([FLOOR, FLOOR, FLOOR])[0];+ const count = [+ // The floor's own colour: all of what lies beyond the radius, and none of what lies well inside it.+ { rgb: [floor, floor, floor], tol: 0, atLeast: far, atMost: mid },+ // Darker than the floor by more than the tolerance (the box top, 255, is above the window): at least the foot of the box, and no more+ // than what is within reach. A box a third of the radius high shades its foot by 3 to 9 percent, so the window is a couple of codes wide.+ { rgb: [115, 115, 115], tol: 114, atLeast: near, atMost: inside },+ ];+ return { id, doc, colorSpace: 'linear', count, about: `${effect.toUpperCase()} radius ${radius}: untouched beyond it (${far} px at least), darkened well inside it (${near} px at least)` };+}++/** Flatness test: a camera 32 degrees down over a big floor; no pixel of it may be darkened. */+function flatFloor({ id, effect }) {+ const FOV = 50, PITCH = -32, EYE = [0, 250, 300], FLOOR_TOP = 5;+ const doc = scene(id, () => [+ camera({ projectionType: 0, fov: FOV, nearPlane: 1, farPlane: 4000 }), mesh('Floor', 'cube', [0, 0, 0], [8, 0.1, 8], [FLOOR, FLOOR, FLOOR], { lit: false }),+ volume([fx(effect, effect === 'ssao' ? { u_radius: 40, u_intensity: 1, u_bias: 0.12, u_power: 1.6 } : { u_radius: 40, u_intensity: 1, u_power: 1.4, u_thickness: 0.5 })]),+ ]);+ const cam = doc.entities.find((e) => e.name === 'Camera');+ cam.components[0].data.position = { x: EYE[0], y: EYE[1], z: EYE[2] };+ const q = axisAngle([1, 0, 0], PITCH);+ cam.components[0].data.rotation = q;+ const t = Math.tan((FOV * Math.PI) / 360);+ const rgb = encodeLinear8([FLOOR, FLOOR, FLOOR]);+ const expect = [];+ for (let j = 140; j <= 250; j += 14) {+ for (let i = 20; i <= 236; i += 36) {+ const nx = (2 * (i + 0.5)) / SIZE - 1, ny = 1 - (2 * (j + 0.5)) / SIZE;+ const dir = norm(rotate(q, norm([nx * t, ny * t, -1])));+ if (dir[1] >= -0.05) continue;+ const s = (FLOOR_TOP - EYE[1]) / dir[1], hx = EYE[0] + dir[0] * s, hz = EYE[2] + dir[2] * s;+ if (Math.abs(hx) < 380 && Math.abs(hz) < 380) expect.push({ x: i / (SIZE - 1), y: j / (SIZE - 1), rgb, tol: 2 });+ }+ }+ return { id, doc, colorSpace: 'linear', expect, about: `${effect.toUpperCase()}: an open floor seen 32 degrees down is not darkened` };+}++export const OCCLUSION_SCENES = [+ flatFloor({ id: 'oracle-ssao-flat', effect: 'ssao' }),+ flatFloor({ id: 'oracle-gtao-flat', effect: 'gtao' }),+ radiusTest({ id: 'oracle-ssao-radius', effect: 'ssao', radius: 30 }),+ radiusTest({ id: 'oracle-ssao-radius-small', effect: 'ssao', radius: 12 }),+ radiusTest({ id: 'oracle-gtao-radius', effect: 'gtao', radius: 30 }),+ radiusTest({ id: 'oracle-gtao-radius-small', effect: 'gtao', radius: 12 }),+];diff --git a/tools/oracle/reflection.mjs b/tools/oracle/reflection.mjsnew file mode 100644index 000000000..1198fd884--- /dev/null+++ b/tools/oracle/reflection.mjs@@ -0,0 +1,96 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file reflection.mjs — oracle scenes for Screen Space Reflections.+ *+ * A mirror floor and a box standing on it, seen from a camera that looks down at both. A pixel of the floor shows what its reflected ray+ * meets, and that is geometry: the view ray meets the floor, reflects about its up normal, and meets the box or not. Where it does, the+ * pixel is mix(floor, box, w x hit) with+ *+ * w = fresnel x gloss x intensity, fresnel = f0 + (1 - f0)(1 - cos)^5 (Schlick; f0 = 0.9 for a metal, 0.04 for an insulator),+ * cos = the angle between the floor's normal and the way back to the eye, gloss = (1 - roughness)^2,+ * hit = how far the hit is from the picture's edge (a ramp over the outer tenth) x how far the ray went (a ramp from 0.6 to 1 of+ * the search distance).+ *+ * The box is unlit and one colour, and the floor is lit by nothing, so the floor itself is black and the reflection is the box's colour+ * times that weight. Probes are taken where the ray meets the middle of the box's near face, clear of its edges (the reflection is a+ * five-tap blur of the picture there).+ */+import { scene, camera, mesh, volume, SIZE } from './scene.mjs';+import { encodeLinear8, axisAngle, rotate, norm, dot, sub, smoothstep, clamp01 } from './formulas.mjs';++const FOV = 50, PITCH = -35, EYE = [0, 230, 280], FLOOR_TOP = 5;+const BOX = { min: [-60, FLOOR_TOP, -170], max: [60, FLOOR_TOP + 90, -150] };+const BOX_COLOUR = [0.9, 0.35, 0.2];+const MAX_DISTANCE = 700;++const material = (metallic, roughness) => ({ version: '1.0', type: 'material', shader: 'builtin:model', blendMode: 0, depthTest: true, depthWrite: true, cull: 0, properties: { u_metallic: metallic, u_roughness: roughness } });++function mirrorFloor({ id, metallic, roughness, intensity = 1, floorBias = 0, ssrIntensity = intensity }) {+ const materialName = `${id}_m0.esmaterial`;+ const doc = scene(id, () => [+ camera({ projectionType: 0, fov: FOV, nearPlane: 1, farPlane: 4000 }),+ mesh('Floor', 'cube', [0, 0, 0], [8, 0.1, 8], [0.5, 0.5, 0.5], { lit: true, material: `/scenes/${materialName}` }),+ mesh('Box', 'cube', [0, (BOX.min[1] + BOX.max[1]) / 2, (BOX.min[2] + BOX.max[2]) / 2], [1.2, 0.9, 0.2], BOX_COLOUR, { lit: false }),+ volume([{ type: 'ssr', enabled: true, uniforms: { u_intensity: ssrIntensity, u_maxDistance: MAX_DISTANCE, u_thickness: 12, u_floorBias: floorBias, u_skyReflection: 0 } }]),+ ]);+ const cam = doc.entities.find((e) => e.name === 'Camera');+ cam.components[0].data.position = { x: EYE[0], y: EYE[1], z: EYE[2] };+ const q = axisAngle([1, 0, 0], PITCH);+ cam.components[0].data.rotation = q;+ const t = Math.tan((FOV * Math.PI) / 360);+ const f0 = 0.04 + (0.9 - 0.04) * metallic, gloss = (1 - roughness) ** 2;+ const slab = (origin, dir) => {+ 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 null; 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 null;+ }+ return t0;+ };+ const right = rotate(q, [1, 0, 0]), up = rotate(q, [0, 1, 0]), forward = rotate(q, [0, 0, -1]);+ const project = (p) => { const rel = sub(p, EYE); const cz = dot(rel, forward); return [0.5 + 0.5 * dot(rel, right) / (cz * t), 0.5 + 0.5 * dot(rel, up) / (cz * t)]; };++ const reflected = [], clear = [];+ for (let j = 10; j < SIZE - 6; j += 4) {+ for (let i = 6; i < SIZE - 6; i += 4) {+ const nx = (2 * (i + 0.5)) / SIZE - 1, ny = 1 - (2 * (j + 0.5)) / SIZE;+ const dir = norm([forward[0] + nx * t * right[0] + ny * t * up[0], forward[1] + nx * t * right[1] + ny * t * up[1], forward[2] + nx * t * right[2] + ny * t * up[2]]);+ if (dir[1] >= -0.02) continue;+ const s = (FLOOR_TOP - EYE[1]) / dir[1], P = [EYE[0] + dir[0] * s, FLOOR_TOP, EYE[2] + dir[2] * s];+ if (Math.abs(P[0]) > 380 || Math.abs(P[2]) > 380) continue; // off the floor+ if (slab(EYE, dir) !== null && slab(EYE, dir) < s) continue; // the box stands in front of this floor point+ const R = [dir[0], -dir[1], dir[2]], tHit = slab(P, R);+ const cosT = clamp01(-dir[1]);+ const fresnel = f0 + (1 - f0) * Math.pow(1 - cosT, 5);+ const w = roughness > 0.75 ? 0 : fresnel * gloss * ssrIntensity; // a surface rougher than Max Roughness (0.75) is not marched at all+ if (tHit === null) { clear.push({ i, j, near: false }); continue; }+ const H = [P[0] + R[0] * tHit, P[1] + R[1] * tHit, P[2] + R[2] * tHit];+ // Well inside the box's near face (z = -150): clear of its edges, where the blur reads the background.+ const insideFace = Math.abs(H[2] - BOX.max[2]) < 0.5 && H[0] > BOX.min[0] + 22 && H[0] < BOX.max[0] - 22 && H[1] > BOX.min[1] + 18 && H[1] < BOX.max[1] - 18;+ if (!insideFace) continue;+ const [u, v] = project(H), edge = smoothstep(0, 0.1, Math.min(u, 1 - u, v, 1 - v));+ const hit = edge * (1 - smoothstep(0.6, 1, tHit / MAX_DISTANCE));+ reflected.push({ i, j, k: clamp01(w * hit) });+ }+ }+ const pick = (list, n) => list.filter((_, idx) => idx % Math.max(1, Math.floor(list.length / n)) === 0).slice(0, n);+ const expect = [+ ...pick(reflected, 14).map(({ i, j, k }) => ({ x: i / (SIZE - 1), y: j / (SIZE - 1), rgb: encodeLinear8(BOX_COLOUR.map((c) => c * k)), tol: 5 })),+ // Where the reflected ray misses the box there is nothing on screen to find: the floor is what lit it, which is nothing.+ ...pick(clear.filter((c) => c.j > 150), 6).map(({ i, j }) => ({ x: i / (SIZE - 1), y: j / (SIZE - 1), rgb: [0, 0, 0], tol: 2 })),+ ];+ return { id, doc, colorSpace: 'linear', expect, files: { [materialName]: material(metallic, roughness) }, reflectedCount: reflected.length,+ about: `SSR on a floor of metallic ${metallic}, roughness ${roughness}: the box's reflection is its colour x fresnel x gloss` };+}++export const REFLECTION_SCENES = [+ mirrorFloor({ id: 'oracle-ssr-mirror', metallic: 1, roughness: 0.05 }),+ mirrorFloor({ id: 'oracle-ssr-glossy', metallic: 1, roughness: 0.4 }),+ mirrorFloor({ id: 'oracle-ssr-dielectric', metallic: 0, roughness: 0.05 }),+ mirrorFloor({ id: 'oracle-ssr-half', metallic: 1, roughness: 0.05, ssrIntensity: 0.5 }),+ mirrorFloor({ id: 'oracle-ssr-rough', metallic: 1, roughness: 0.9 }),+];