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.

feat(render): an Ambient light can be two colours, sky and ground, without baking a panorama

yhh886a8694f223
diff --git a/desktop b/desktop
index 7f69480a7..2dfa140ab 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 7f69480a7128470408f256532b9c162234b4b39d
+Subproject commit 2dfa140ab55b31cd61f4cffa585660d93f7afa65
diff --git a/docs/astro/src/content/docs/graphics/lighting.mdx b/docs/astro/src/content/docs/graphics/lighting.mdx
index d3b5d5732..ae8b1f878 100644
--- a/docs/astro/src/content/docs/graphics/lighting.mdx
+++ b/docs/astro/src/content/docs/graphics/lighting.mdx
@@ -61,7 +61,9 @@ const addSun = defineSystem([Commands()], (cmds) => {
| `shadowExtent` | `0` | Directional only: radius the mesh shadow map covers, centred on the camera; `0` fits the view. |
| `followEnvironmentSun` | `false` | Directional only: take direction and strength from the environment's sun, and light the sky without it. |
| `aimFollowedSun` | `false` | With `followEnvironmentSun`: aim by this light's `Transform` instead of the panorama's sun. |
-| `environment` | — | Ambient only: a baked `.esenv` environment. |
+| `hemisphere` | `false` | Ambient only: light from above in `color`, from below in `groundColor`, blended by which way a surface faces. |
+| `groundColor` | `#5a4d40` | Ambient only: what a surface facing straight down receives with `hemisphere` on. Scaled by `intensity`. |
+| `environment` | — | Ambient only: a baked `.esenv` environment. It replaces the flat term, `hemisphere` included. |
| `environmentRotation` | `0` | Ambient only: turn the environment about the up axis, in degrees. |
| `drawEnvironment` | `false` | Ambient only: also draw the environment as the sky behind the scene. |
| `reflectionScale` | `1` | Ambient only: scale what baked reflection probes show (`1` = as baked). |
@@ -541,6 +543,12 @@ WeChat, playable — boot the same pipeline. Code-first projects pass it at app
const app = createWebApp(module, { colorSpace: 'linear' });
```
+The colour pickers show what the screen shows either way. In a linear project a `Sprite`'s or a `Light`'s colour is stored as sRGB and decoded by the engine, while a resident mesh's `MeshRenderer.color` and a material's colours reach the shader as they are, so those are stored linear: `0.25` in a scene file is what the picker shows as `#89`. Writing a mesh's colour from code takes the linear value.
+
+### Coming from three.js
+
+`intensity` has no factor of pi in it: a directional light of `1` facing a surface gives it its full colour, where three.js (r155 and later) divides diffuse light by pi. Numbers carried over from a three.js scene are therefore about three times too bright. Divide its light intensities by pi. Its `HemisphereLight` is an `Ambient` light with `hemisphere` on.
+
## Dynamic planar reflections
Add `PlanarReflection` to a flat entity with a resident `MeshRenderer` mesh and a
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx
index 52608ea12..d4e470cbf 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx
@@ -59,7 +59,9 @@ const addSun = defineSystem([Commands()], (cmds) => {
| `shadowExtent` | `0` | 仅 Directional:mesh 阴影图覆盖的半径,以相机为中心;`0` 表示贴合视野。 |
| `followEnvironmentSun` | `false` | 仅 Directional:方向和强度取自环境里的太阳,天空光则不再带太阳。 |
| `aimFollowedSun` | `false` | 配合 `followEnvironmentSun`:按这盏灯自己的 `Transform` 定向,而不是全景图里的太阳。 |
-| `environment` | — | 仅 Ambient:烘焙好的 `.esenv` 环境。 |
+| `hemisphere` | `false` | 仅 Ambient:上方来的光用 `color`,下方来的光用 `groundColor`,按表面朝向混合。 |
+| `groundColor` | `#5a4d40` | 仅 Ambient:打开 `hemisphere` 时,正对下方的表面受到的颜色。受 `intensity` 缩放。 |
+| `environment` | — | 仅 Ambient:烘焙好的 `.esenv` 环境。它会取代平坦环境光项,包括 `hemisphere`。 |
| `environmentRotation` | `0` | 仅 Ambient:绕向上轴转动环境,度。 |
| `drawEnvironment` | `false` | 仅 Ambient:同时把环境画成场景背后的天空。 |
| `reflectionScale` | `1` | 仅 Ambient:缩放烘焙反射探针显示的内容(`1` = 烘焙原样)。 |
@@ -474,6 +476,12 @@ Lighting 面板会说场景已经过期。
const app = createWebApp(module, { colorSpace: 'linear' });
```
+无论哪种模式,拾色器显示的都是屏幕上的颜色。线性项目里,`Sprite` 和 `Light` 的颜色按 sRGB 存储,由引擎解码;常驻网格的 `MeshRenderer.color` 和材质颜色则原样传给着色器,所以存的是线性值:场景文件里的 `0.25` 在拾色器里显示为 `#89`。用代码写网格颜色时要传线性值。
+
+### 从 three.js 迁移
+
+`intensity` 不含 π 因子:强度为 `1` 的平行光正对表面时,给它的是完整的颜色;three.js(r155 起)的漫反射光要除以 π。所以从 three.js 场景抄过来的数值大约亮三倍,要把光照强度除以 π。它的 `HemisphereLight` 对应打开 `hemisphere` 的 `Ambient` 灯。
+
## 动态平面反射
给平面实体添加 `PlanarReflection`,实体需要有 GPU 常驻网格的 `MeshRenderer`
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index a35ee7829..04b5a9d7e 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 115,
"beta": 176,
- "experimental": 2837,
+ "experimental": 2840,
"deprecated": 3
},
- "total": 3128,
+ "total": 3131,
"subsystems": [
{
"id": "mobile-controls",
diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.json
index a704d75c0..047d756f6 100644
--- a/docs/astro/src/data/components.generated.json
+++ b/docs/astro/src/data/components.generated.json
@@ -3054,6 +3054,18 @@
"doc": "Multiply baked indirect light (lightmaps, probe volumes) by this colour (1 = as baked).",
"advanced": true
},
+ {
+ "key": "hemisphere",
+ "type": "boolean",
+ "default": "false",
+ "doc": "Light from above in Color, from below in Ground Color, blended by which way a surface faces."
+ },
+ {
+ "key": "groundColor",
+ "type": "Color",
+ "default": "#594d40",
+ "doc": "The ambient colour a surface facing straight down receives (Hemisphere)."
+ },
{
"key": "enabled",
"type": "boolean",
@@ -3076,7 +3088,11 @@
"outerAngle",
"shadowSoftness",
"sourceAngle",
- "shadowDistance"
+ "shadowDistance",
+ "groundColor.r",
+ "groundColor.g",
+ "groundColor.b",
+ "groundColor.a"
]
},
{
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index cdeb0dc52..a6422d78b 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -5,7 +5,7 @@ Symbols: 115 public · 164 beta · 2049 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"ace63550c0783bc7"
+"6bf8e03097b59051"
```
## ANCHOR_AXES — const @experimental
@@ -5562,6 +5562,8 @@ environment: number
environmentRotation: number
falloff: number
followEnvironmentSun: boolean
+groundColor: Color
+hemisphere: boolean
innerAngle: number
innerRadius: number
intensity: number
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 7011b7326..62bc4dd01 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5,7 +5,7 @@ Symbols: 115 public · 169 beta · 2068 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"ace63550c0783bc7"
+"6bf8e03097b59051"
```
## ANCHOR_AXES — const @experimental
@@ -5570,6 +5570,8 @@ environment: number
environmentRotation: number
falloff: number
followEnvironmentSun: boolean
+groundColor: Color
+hemisphere: boolean
innerAngle: number
innerRadius: number
intensity: number
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 95d569f5b..9feabcdcb 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -5557,6 +5557,8 @@ environment: number
environmentRotation: number
falloff: number
followEnvironmentSun: boolean
+groundColor: Color
+hemisphere: boolean
innerAngle: number
innerRadius: number
intensity: number
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index adf91ecac..97cab51c8 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -5557,6 +5557,8 @@ environment: number
environmentRotation: number
falloff: number
followEnvironmentSun: boolean
+groundColor: Color
+hemisphere: boolean
innerAngle: number
innerRadius: number
intensity: number
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 434610e1a..314fe76d3 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -5564,6 +5564,8 @@ environment: number
environmentRotation: number
falloff: number
followEnvironmentSun: boolean
+groundColor: Color
+hemisphere: boolean
innerAngle: number
innerRadius: number
intensity: number
diff --git a/sdk/src/ecs/bridge/ptrAccessors.generated.ts b/sdk/src/ecs/bridge/ptrAccessors.generated.ts
index 21ba34d90..6489dce63 100644
--- a/sdk/src/ecs/bridge/ptrAccessors.generated.ts
+++ b/sdk/src/ecs/bridge/ptrAccessors.generated.ts
@@ -952,6 +952,8 @@ export interface LightPtrData {
reflectionScale: number;
reflectionSaturation: number;
bakedTint: Color;
+ hemisphere: boolean;
+ groundColor: Color;
enabled: boolean;
}
@@ -985,7 +987,9 @@ export function fillLight(
out.reflectionScale = f32[(ptr + 104) >> 2];
out.reflectionSaturation = f32[(ptr + 108) >> 2];
const bakedTint_ = out.bakedTint; bakedTint_.r = f32[(ptr + 112) >> 2]; bakedTint_.g = f32[((ptr + 112) >> 2) + 1]; bakedTint_.b = f32[((ptr + 112) >> 2) + 2]; bakedTint_.a = f32[((ptr + 112) >> 2) + 3];
- out.enabled = u8[ptr + 128] !== 0;
+ out.hemisphere = u8[ptr + 128] !== 0;
+ const groundColor_ = out.groundColor; groundColor_.r = f32[(ptr + 132) >> 2]; groundColor_.g = f32[((ptr + 132) >> 2) + 1]; groundColor_.b = f32[((ptr + 132) >> 2) + 2]; groundColor_.a = f32[((ptr + 132) >> 2) + 3];
+ out.enabled = u8[ptr + 148] !== 0;
}
export function writeLight(
@@ -1018,7 +1022,9 @@ export function writeLight(
f32[(ptr + 104) >> 2] = data.reflectionScale;
f32[(ptr + 108) >> 2] = data.reflectionSaturation;
f32[(ptr + 112) >> 2] = data.bakedTint.r; f32[((ptr + 112) >> 2) + 1] = data.bakedTint.g; f32[((ptr + 112) >> 2) + 2] = data.bakedTint.b; f32[((ptr + 112) >> 2) + 3] = data.bakedTint.a;
- u8[ptr + 128] = data.enabled ? 1 : 0;
+ u8[ptr + 128] = data.hemisphere ? 1 : 0;
+ f32[(ptr + 132) >> 2] = data.groundColor.r; f32[((ptr + 132) >> 2) + 1] = data.groundColor.g; f32[((ptr + 132) >> 2) + 2] = data.groundColor.b; f32[((ptr + 132) >> 2) + 3] = data.groundColor.a;
+ u8[ptr + 148] = data.enabled ? 1 : 0;
}
export function createLightData(): LightPtrData {
@@ -1049,6 +1055,8 @@ export function createLightData(): LightPtrData {
reflectionScale: 0,
reflectionSaturation: 0,
bakedTint: { r: 0, g: 0, b: 0, a: 0 },
+ hemisphere: false,
+ groundColor: { r: 0, g: 0, b: 0, a: 0 },
enabled: false,
};
}
diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.ts
index 595d56220..359bd540a 100644
--- a/sdk/src/ecs/component.generated.ts
+++ b/sdk/src/ecs/component.generated.ts
@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BillboardMode, BodyType, Canv
* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to
* run on mismatch, because mismatched offsets read the wrong heap bytes.
*/
-export const ABI_LAYOUT_HASH = 'ace63550c0783bc7';
+export const ABI_LAYOUT_HASH = '6bf8e03097b59051';
/**
* One asset-valued field of a component: which field, and what kind of
@@ -546,13 +546,15 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
reflectionScale: 1,
reflectionSaturation: 1,
bakedTint: { r: 1, g: 1, b: 1, a: 1 },
+ hemisphere: false,
+ groundColor: { r: 0.35, g: 0.3, b: 0.25, a: 1 },
enabled: true,
},
renderableField: 'enabled',
assetFields: [{ field: 'cookie', type: 'texture' as AssetFieldType }, { field: 'environment', type: 'environment' as AssetFieldType }],
entityFields: [],
- colorFields: ['color', 'bakedTint'],
- animatableFields: ['color.r', 'color.g', 'color.b', 'color.a', 'intensity', 'radius', 'innerRadius', 'falloff', 'shadowStrength', 'cookieSize.x', 'cookieSize.y', 'innerAngle', 'outerAngle', 'shadowSoftness', 'sourceAngle', 'shadowDistance'],
+ colorFields: ['color', 'bakedTint', 'groundColor'],
+ animatableFields: ['color.r', 'color.g', 'color.b', 'color.a', 'intensity', 'radius', 'innerRadius', 'falloff', 'shadowStrength', 'cookieSize.x', 'cookieSize.y', 'innerAngle', 'outerAngle', 'shadowSoftness', 'sourceAngle', 'shadowDistance', 'groundColor.r', 'groundColor.g', 'groundColor.b', 'groundColor.a'],
fields: {
type: { enum: [{ label: 'Point', value: 0 }, { label: 'Directional', value: 1 }, { label: 'Ambient', value: 2 }, { label: 'Spot', value: 3 }], tooltip: "Point, Directional, Ambient, or Spot." },
intensity: { min: 0, tooltip: "Brightness multiplier of the light." },
@@ -579,6 +581,8 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
reflectionScale: { min: 0, tooltip: "Scale what baked reflection probes show (1 = as baked).", advanced: true, shownWhen: { field: "type", values: [2] } },
reflectionSaturation: { min: 0, max: 1, tooltip: "How much colour baked reflection probes keep (0 = grey).", advanced: true, shownWhen: { field: "type", values: [2] } },
bakedTint: { tooltip: "Multiply baked indirect light (lightmaps, probe volumes) by this colour (1 = as baked).", advanced: true, shownWhen: { field: "type", values: [2] } },
+ hemisphere: { tooltip: "Light from above in Color, from below in Ground Color, blended by which way a surface faces.", shownWhen: { field: "type", values: [2] } },
+ groundColor: { tooltip: "The ambient colour a surface facing straight down receives (Hemisphere).", shownWhen: { field: "type", values: [2] } },
},
},
LightProbeVolume: {
@@ -1719,6 +1723,8 @@ export interface LightData {
reflectionScale: number;
reflectionSaturation: number;
bakedTint: Color;
+ hemisphere: boolean;
+ groundColor: Color;
enabled: boolean;
}
diff --git a/sdk/src/wasm/ptrLayouts.generated.ts b/sdk/src/wasm/ptrLayouts.generated.ts
index 35ba5c7ec..b0f8dd133 100644
--- a/sdk/src/wasm/ptrLayouts.generated.ts
+++ b/sdk/src/wasm/ptrLayouts.generated.ts
@@ -285,7 +285,9 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
{ name: 'reflectionScale', type: 'f32', offset: 104 },
{ name: 'reflectionSaturation', type: 'f32', offset: 108 },
{ name: 'bakedTint', type: 'color', offset: 112 },
- { name: 'enabled', type: 'bool', offset: 128 },
+ { name: 'hemisphere', type: 'bool', offset: 128 },
+ { name: 'groundColor', type: 'color', offset: 132 },
+ { name: 'enabled', type: 'bool', offset: 148 },
],
},
LightProbeVolume: {
diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.ts
index 0d9fda1b9..6a3666010 100644
--- a/sdk/src/wasm/wasm.generated.ts
+++ b/sdk/src/wasm/wasm.generated.ts
@@ -695,6 +695,8 @@ export interface Light {
reflectionScale: number;
reflectionSaturation: number;
bakedTint: Vec4;
+ hemisphere: boolean;
+ groundColor: Vec4;
enabled: boolean;
}
diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap
index e4645dec7..5e008fbbb 100644
--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap
+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap
@@ -355,6 +355,24 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho
},
"tooltip": "Take direction and strength from the environment's sun, and light the sky without it.",
},
+ "groundColor": {
+ "shownWhen": {
+ "field": "type",
+ "values": [
+ 2,
+ ],
+ },
+ "tooltip": "The ambient colour a surface facing straight down receives (Hemisphere).",
+ },
+ "hemisphere": {
+ "shownWhen": {
+ "field": "type",
+ "values": [
+ 2,
+ ],
+ },
+ "tooltip": "Light from above in Color, from below in Ground Color, blended by which way a surface faces.",
+ },
"innerAngle": {
"advanced": true,
"max": 180,
diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cpp
index d7c650134..fbf0b57e2 100644
--- a/src/esengine/bindings/EditorAPI.generated.cpp
+++ b/src/esengine/bindings/EditorAPI.generated.cpp
@@ -2,10 +2,10 @@
* @file EditorAPI.generated.cpp
* @brief Auto-generated editor API with string-dispatched component access
* @details Generated by EHT - DO NOT EDIT
- * @schema_hash 6f0cd242105a26be
+ * @schema_hash 042cfceefbe1ff33
*/
-#define ES_EDITOR_API_SCHEMA_HASH "6f0cd242105a26be"
+#define ES_EDITOR_API_SCHEMA_HASH "042cfceefbe1ff33"
#include <emscripten/bind.h>
#include <string>
@@ -406,6 +406,11 @@ std::string editor_getComponentSchema(const std::string& name) {
{"key":"bakedTint.g","type":"color","group":"Light"},
{"key":"bakedTint.b","type":"color","group":"Light"},
{"key":"bakedTint.a","type":"color","group":"Light"},
+ {"key":"hemisphere","type":"bool","group":"Light"},
+ {"key":"groundColor.r","type":"color","group":"Light"},
+ {"key":"groundColor.g","type":"color","group":"Light"},
+ {"key":"groundColor.b","type":"color","group":"Light"},
+ {"key":"groundColor.a","type":"color","group":"Light"},
{"key":"enabled","type":"bool","group":"Light"}
])JSON";
} else if (name == "LightProbeVolume") {
@@ -1559,6 +1564,10 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s
else if (field == "bakedTint.g") { c.bakedTint.g = value; }
else if (field == "bakedTint.b") { c.bakedTint.b = value; }
else if (field == "bakedTint.a") { c.bakedTint.a = value; }
+ else if (field == "groundColor.r") { c.groundColor.r = value; }
+ else if (field == "groundColor.g") { c.groundColor.g = value; }
+ else if (field == "groundColor.b") { c.groundColor.b = value; }
+ else if (field == "groundColor.a") { c.groundColor.a = value; }
else { return false; }
return true;
} else if (comp == "LightProbeVolume") {
@@ -2167,6 +2176,10 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st
else if (field == "bakedTint.g") { return c.bakedTint.g; }
else if (field == "bakedTint.b") { return c.bakedTint.b; }
else if (field == "bakedTint.a") { return c.bakedTint.a; }
+ else if (field == "groundColor.r") { return c.groundColor.r; }
+ else if (field == "groundColor.g") { return c.groundColor.g; }
+ else if (field == "groundColor.b") { return c.groundColor.b; }
+ else if (field == "groundColor.a") { return c.groundColor.a; }
} else if (comp == "LightProbeVolume") {
if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return 0.0f;
const auto& c = reg.get<esengine::ecs::LightProbeVolume>(entity);
@@ -3210,6 +3223,7 @@ bool editor_setBool(Registry& reg, u32 e, const std::string& comp, const std::st
else if (field == "followEnvironmentSun") { c.followEnvironmentSun = value; }
else if (field == "aimFollowedSun") { c.aimFollowedSun = value; }
else if (field == "drawEnvironment") { c.drawEnvironment = value; }
+ else if (field == "hemisphere") { c.hemisphere = value; }
else if (field == "enabled") { c.enabled = value; }
else { return false; }
return true;
@@ -3494,6 +3508,7 @@ bool editor_getBool(Registry& reg, u32 e, const std::string& comp, const std::st
else if (field == "followEnvironmentSun") { return c.followEnvironmentSun; }
else if (field == "aimFollowedSun") { return c.aimFollowedSun; }
else if (field == "drawEnvironment") { return c.drawEnvironment; }
+ else if (field == "hemisphere") { return c.hemisphere; }
else if (field == "enabled") { return c.enabled; }
} else if (comp == "LightProbeVolume") {
if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return false;
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index 78d3df4ea..b85f4e776 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -672,6 +672,8 @@ struct LightJS {
f32 reflectionScale;
f32 reflectionSaturation;
glm::vec4 bakedTint;
+ bool hemisphere;
+ glm::vec4 groundColor;
bool enabled;
};
@@ -702,6 +704,8 @@ void lightApplyJS(esengine::ecs::Light& c, const LightJS& js) {
c.reflectionScale = js.reflectionScale;
c.reflectionSaturation = js.reflectionSaturation;
c.bakedTint = js.bakedTint;
+ c.hemisphere = js.hemisphere;
+ c.groundColor = js.groundColor;
c.enabled = js.enabled;
}
@@ -739,6 +743,8 @@ LightJS lightToJS(const esengine::ecs::Light& c) {
js.reflectionScale = c.reflectionScale;
js.reflectionSaturation = c.reflectionSaturation;
js.bakedTint = c.bakedTint;
+ js.hemisphere = c.hemisphere;
+ js.groundColor = c.groundColor;
js.enabled = c.enabled;
return js;
}
@@ -2051,6 +2057,8 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
.field("reflectionScale", &LightJS::reflectionScale)
.field("reflectionSaturation", &LightJS::reflectionSaturation)
.field("bakedTint", &LightJS::bakedTint)
+ .field("hemisphere", &LightJS::hemisphere)
+ .field("groundColor", &LightJS::groundColor)
.field("enabled", &LightJS::enabled);
value_object<LightProbeVolumeJS>("LightProbeVolume")
@@ -4070,7 +4078,9 @@ static_assert(offsetof(esengine::ecs::Light, drawEnvironment) == 100, "ABI offse
static_assert(offsetof(esengine::ecs::Light, reflectionScale) == 104, "ABI offset drift: esengine::ecs::Light.reflectionScale (EHT expected 104)");
static_assert(offsetof(esengine::ecs::Light, reflectionSaturation) == 108, "ABI offset drift: esengine::ecs::Light.reflectionSaturation (EHT expected 108)");
static_assert(offsetof(esengine::ecs::Light, bakedTint) == 112, "ABI offset drift: esengine::ecs::Light.bakedTint (EHT expected 112)");
-static_assert(offsetof(esengine::ecs::Light, enabled) == 128, "ABI offset drift: esengine::ecs::Light.enabled (EHT expected 128)");
+static_assert(offsetof(esengine::ecs::Light, hemisphere) == 128, "ABI offset drift: esengine::ecs::Light.hemisphere (EHT expected 128)");
+static_assert(offsetof(esengine::ecs::Light, groundColor) == 132, "ABI offset drift: esengine::ecs::Light.groundColor (EHT expected 132)");
+static_assert(offsetof(esengine::ecs::Light, enabled) == 148, "ABI offset drift: esengine::ecs::Light.enabled (EHT expected 148)");
static_assert(offsetof(esengine::ecs::LightProbeVolume, probes) == 0, "ABI offset drift: esengine::ecs::LightProbeVolume.probes (EHT expected 0)");
static_assert(offsetof(esengine::ecs::LightProbeVolume, halfExtents) == 4, "ABI offset drift: esengine::ecs::LightProbeVolume.halfExtents (EHT expected 4)");
static_assert(offsetof(esengine::ecs::LightProbeVolume, spacing) == 16, "ABI offset drift: esengine::ecs::LightProbeVolume.spacing (EHT expected 16)");
@@ -4374,7 +4384,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif
// ABI Hash -- runtime handshake against the SDK bundle
// =============================================================================
-static const char* kEsAbiLayoutHash = "ace63550c0783bc7";
+static const char* kEsAbiLayoutHash = "6bf8e03097b59051";
std::string esengineGetAbiLayoutHash() {
return std::string(kEsAbiLayoutHash);
diff --git a/src/esengine/ecs/components/Light.hpp b/src/esengine/ecs/components/Light.hpp
index 38994f8ae..7753b2846 100644
--- a/src/esengine/ecs/components/Light.hpp
+++ b/src/esengine/ecs/components/Light.hpp
@@ -239,6 +239,20 @@ struct Light {
tooltip="Multiply baked indirect light (lightmaps, probe volumes) by this colour (1 = as baked).")
glm::vec4 bakedTint{1.0f, 1.0f, 1.0f, 1.0f};
+ /** @brief Make this Ambient light two colours: @ref color from above, @ref groundColor
+ * from below, blended by which way a surface faces. Off is the flat term it has
+ * always been. A sky and the ground it bounces off, without baking a panorama;
+ * ignored where @ref environment is set, whose irradiance already says that. */
+ ES_PROPERTY(shown_when=type:Ambient,
+ tooltip="Light from above in Color, from below in Ground Color, blended by which way a surface faces.")
+ bool hemisphere{false};
+
+ /** @brief What a surface facing straight down receives with @ref hemisphere on. Scaled by
+ * @ref intensity, and authored the way @ref color is. */
+ ES_PROPERTY(animatable, shown_when=type:Ambient,
+ tooltip="The ambient colour a surface facing straight down receives (Hemisphere).")
+ glm::vec4 groundColor{0.35f, 0.3f, 0.25f, 1.0f};
+
/** @brief Disabled lights are skipped during collection. */
ES_PROPERTY()
bool enabled{true};
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cpp
index ff8962e7f..60afdfa96 100644
--- a/src/esengine/renderer/frame/RenderFrame.cpp
+++ b/src/esengine/renderer/frame/RenderFrame.cpp
@@ -1673,6 +1673,11 @@ void RenderFrame::collectLights(ecs::Registry& registry) {
if (collectEnvironment(light, rgb * light.intensity,
sunCast && entity == skyLight)) continue;
lights.addAmbient(rgb * light.intensity);
+ if (light.hemisphere) {
+ const glm::vec3 ground = linear_color_ ? srgbToLinearCpu(glm::vec3{light.groundColor})
+ : glm::vec3{light.groundColor};
+ lights.addAmbientGround((ground - rgb) * light.intensity);
+ }
continue;
}
diff --git a/src/esengine/renderer/store/LightConstants.hpp b/src/esengine/renderer/store/LightConstants.hpp
index ecd63fbba..698f5c016 100644
--- a/src/esengine/renderer/store/LightConstants.hpp
+++ b/src/esengine/renderer/store/LightConstants.hpp
@@ -179,6 +179,10 @@ struct LightConstants {
glm::uvec4 tileMask[TILE_COLUMNS * TILE_ROWS]{};
/// x = how many tiled lights there are (0 = the loop does not run), y = tile columns, z = tile rows, w unused.
glm::vec4 tileInfo{0.0f};
+ /// rgb = what the ambient term moves by between a surface facing up and one facing down: ground minus
+ /// sky, so zero (no hemisphere light) leaves `ambient` as the flat term, pixel for pixel. Last, because a
+ /// block that does not read it is free not to declare it.
+ glm::vec4 ambientGround{0.0f};
};
static_assert(sizeof(GpuLight) == 96, "GpuLight must be std140-tight (six vec4s)");
@@ -187,7 +191,7 @@ static_assert(sizeof(LightConstants) == 16 + 96 * MAX_LIGHTS + 16
+ 64 * MAX_SHADOW_TILES + 16 * MAX_SHADOW_TILES
+ 16 + 16 * 9 + 16 + 16
+ 16 + 32 * MAX_REFLECTION_PROBES + 16
- + 96 * MAX_TILED_LIGHTS + 16 * TILE_COLUMNS * TILE_ROWS + 16,
+ + 96 * MAX_TILED_LIGHTS + 16 * TILE_COLUMNS * TILE_ROWS + 16 + 16,
"LightConstants must match the std140 GLSL block layout");
} // namespace esengine
diff --git a/src/esengine/renderer/store/LightStore.hpp b/src/esengine/renderer/store/LightStore.hpp
index 0dc5db03f..2dc732f6a 100644
--- a/src/esengine/renderer/store/LightStore.hpp
+++ b/src/esengine/renderer/store/LightStore.hpp
@@ -55,6 +55,15 @@ public:
dirty_ = true;
}
+ /// How far a hemisphere Ambient light moves the ambient term between a surface facing up and one
+ /// facing down (ground minus sky, already scaled by intensity). Sums the way the term itself does.
+ void addAmbientGround(const glm::vec3& delta) {
+ data_.ambientGround.x += delta.x;
+ data_.ambientGround.y += delta.y;
+ data_.ambientGround.z += delta.z;
+ dirty_ = true;
+ }
+
/// Appends a point/directional light. Silently drops past MAX_LIGHTS (the fixed shader loop
/// bound); callers keep the most significant lights first if they exceed the cap.
void addLight(const GpuLight& light) {
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cpp
index 3b4706c59..84df84b70 100644
--- a/src/esengine/resource/ShaderParser.cpp
+++ b/src/esengine/resource/ShaderParser.cpp
@@ -1365,6 +1365,7 @@ struct LightConstants {
tiledLights : array<Light, 96>,
tileMask : array<vec4u, 192>,
tileInfo : vec4f,
+ u_ambientGround : vec4f,
};
@group(0) @binding(2) var<uniform> lc : LightConstants;
struct ProbeConstants { u_probeIrradiance : array<vec4f, 1000>, u_probeTail : vec4f };
@@ -1826,9 +1827,12 @@ fn shIrradiance(sh : array<vec4f, 9>, N : vec3f) -> vec3f {
+ sh[7].rgb * (1.092548 * N.x * N.z)
+ sh[8].rgb * (0.546274 * (N.x * N.x - N.y * N.y));
}
+fn ambientFacing(dir : vec3f) -> vec3f {
+ return lc.u_ambient.rgb + lc.u_ambientGround.rgb * (0.5 - 0.5 * dir.y);
+}
fn envIrradiance(Nw : vec3f) -> vec3f {
let sh = shIrradiance(lc.u_envIrradiance, envDirection(Nw));
- return lc.u_ambient.rgb + max(sh, vec3f(0.0)) * lc.u_envTint.rgb;
+ return ambientFacing(Nw) + max(sh, vec3f(0.0)) * lc.u_envTint.rgb;
}
// The GLSL twin's indirectIrradiance: a volume replaces the environment, because a
// surface has one indirect term and a volume already holds every light and bounce
@@ -1925,7 +1929,7 @@ fn envRadiance(R : vec3f, roughness : f32, column : f32, P : vec3f) -> vec3f {
+ textureSampleLevel(t3, s3, clamp(uv - vec2f(0.0, r.y), vec2f(0.0), vec2f(1.0)), 0.0).rgb) * 0.125;
}
#endif
- if (lc.u_envParams.x < 0.5) { return lc.u_ambient.rgb; }
+ if (lc.u_envParams.x < 0.5) { return ambientFacing(R); }
let dir = reflectionDirection(R, P, column);
let lod = clamp(roughness, 0.0, 1.0) * lc.u_envParams.z;
let lo = floor(lod);
@@ -2707,6 +2711,7 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" Light u_tiledLights[96];\n"
" highp uvec4 u_tileMask[192];\n"
" highp vec4 u_tileInfo;\n"
+ " highp vec4 u_ambientGround;\n"
"};\n"
// One run of nine per INSTANCE, not one for the draw: a merged draw
// holds objects standing in many places. The flag in w tells "no
@@ -3184,9 +3189,13 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
// The environment's diffuse half. With no environment the coefficients
// are zero and this IS the flat ambient term, which keeps every existing
// scene pixel-identical rather than merely close.
+ // A hemisphere light moves the flat term by which way this faces in the world, and by nothing with none.
+ "highp vec3 ambientFacing(in highp vec3 dir) {\n"
+ " return u_ambient.rgb + u_ambientGround.rgb * (0.5 - 0.5 * dir.y);\n"
+ "}\n"
"highp vec3 envIrradiance(in highp vec3 Nw) {\n"
" highp vec3 sh = shIrradiance(u_envIrradiance, envDirection(Nw));\n"
- " return u_ambient.rgb + max(sh, vec3(0.0)) * u_envTint.rgb;\n"
+ " return ambientFacing(Nw) + max(sh, vec3(0.0)) * u_envTint.rgb;\n"
"}\n"
// The indirect term every lit surface starts from. A volume REPLACES the
// environment rather than adding to it — a surface has one indirect term
@@ -3289,7 +3298,7 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" + textureLod(u_envMap, clamp(uv - vec2(0.0, r.y), 0.0, 1.0), 0.0).rgb) * 0.125;\n"
" }\n"
"#endif\n"
- " if (u_envParams.x < 0.5) return u_ambient.rgb;\n"
+ " if (u_envParams.x < 0.5) return ambientFacing(R);\n"
" highp vec3 dir = reflectionDirection(R, P, column);\n"
" highp float lod = clamp(roughness, 0.0, 1.0) * u_envParams.z;\n"
" highp float lo = floor(lod);\n"
diff --git a/tests/aot/generated/conformance/handshake.h b/tests/aot/generated/conformance/handshake.h
index eeb514b7a..f6178a7c1 100644
--- a/tests/aot/generated/conformance/handshake.h
+++ b/tests/aot/generated/conformance/handshake.h
@@ -1,5 +1,5 @@
/* GENERATED by sdk/tests/aot-conformance.test.ts — do not edit. */
/* The contract half of the handshake. The width half is the harness. */
-#define ES_CONF_EXPECTED_CONTRACT_HASH 0xf32a5f990432930fULL
+#define ES_CONF_EXPECTED_CONTRACT_HASH 0xa0aa3df7a75dbd67ULL
/* And which BUILD the artifact beside this one is. */
#define ES_CONF_EXPECTED_MODULE_CONTRACT 0xc3d0e057d5701a2eULL
diff --git a/tests/aot/generated/conformance/systems_decl.c b/tests/aot/generated/conformance/systems_decl.c
index 1cf7585b7..90733d1d9 100644
--- a/tests/aot/generated/conformance/systems_decl.c
+++ b/tests/aot/generated/conformance/systems_decl.c
@@ -10,7 +10,7 @@
answer, it is a read of a different field. The address width belongs
to the MACHINE, so it mixes in here rather than in the compiler and a
32-bit artifact cannot load into a 64-bit host. */
-#define ES_ABI_ENGINE_DIGEST 0xf32a5f990432930fULL
+#define ES_ABI_ENGINE_DIGEST 0xa0aa3df7a75dbd67ULL
ES_EXPORT const uint64_t es_abi_hash =
ES_ABI_ENGINE_DIGEST ^ (0x9e3779b97f4a7c15ULL * (uint64_t)sizeof(es_addr_t));