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 edge outline effect with a colour and creases

yhh59e282a30a8f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4b1ddcc1..7c5a2967e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ published separately; it ships inside the editor.
### Added
+- **Edge Outline, a coloured line at silhouettes and creases.** A post effect (`edgeOutline`) that draws a line of `u_lineColor` where the scene's surface changes: where the distance from the camera steps (a silhouette) and where the surface's normal turns (the edge of a face, a fold), so a box on a floor is inked along its corners as well as its outline, which `depthOutline` (depth only, black only) does not do. Distance is measured in the world, so one threshold holds across a perspective view, and a plane at a grazing angle draws no line. Creases need surfaces that write their normal (lit meshes, Model and Toon materials); the same picture on WebGL2 and WebGPU.
- **Filled polygons and joined strokes.** `setPath(app, entity, points, style)` draws a path on a MeshRenderer: an ear-clipped fill of any simple polygon (concave ones, holes), and a stroke with mitered, rounded or bevelled corners and butt, round or square caps that does not overlap itself at a corner, so a translucent line is even; `feather` fades the outer edge for a quality level without multisampling. It sorts, batches and saves with the scene like any mesh. `Graphics` still fills only rects and circles; `buildPathGeometry`, `cubicBezier`, `quadraticBezier` and `circlePoints` are the pieces. The same picture on WebGL2 and WebGPU.
- **Toon and Matcap materials.** `builtin:toon` lights in steps: each lamp's light is cut into flat bands with a shade colour where no lamp reaches, a flat highlight and a rim, and a lamp's shadow is part of its step; the same picture on WebGL2 and WebGPU. `builtin:matcap` shows a picture of a lit sphere looked up by the way the surface faces the camera, with no lamp asked and one texture read, for phones.
- **Drawing only the frames that can look different.** `quality.renderOnDemand` (off unless a game turns it on): a still screen costs the game's logic and nothing else. A frame is drawn when the player did something (a key, a button, a finger, the pointer moved), the surface changed size, entities were created or destroyed, shaders are still compiling, or the game asked (`app.pipeline.demand.request()`), and for `renderOnDemandTail` frames (30) after the last of those; `demand.hold()` keeps every frame drawn while a tween, a video or an animation the engine cannot see move is playing. On the UI template a still screen made 11,600 draw calls in 3 seconds before and none with this on, and a click drew again at once. What the engine does not see is a script changing a value or an animation playing, which is what `request` and `hold` are for.
diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdx
index 47350d61d..5b5d03747 100644
--- a/docs/astro/src/content/docs/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx
@@ -46,6 +46,8 @@ several can stack in one frame at no extra target cost beyond the passes.
| `lensFlare` | Ghosts and a halo thrown by whatever is brighter than a threshold, with a colour fringe | `intensity`, `threshold`, `ghosts`, `dispersal`, `haloWidth`, `chromatic`, `tint` |
| `pixelate` | Block quantization | `pixelSize` |
| `outline` | Ink-edge outlines (Sobel edge darkening) | `intensity`, `threshold`, `thickness` |
+| `depthOutline` | Black outline where the depth steps (a silhouette, not shading) | `intensity`, `threshold`, `thickness` |
+| `edgeOutline` | A coloured line at silhouettes **and** creases: where the camera distance steps, and where the surface normal turns (needs surfaces that write a normal: lit meshes, Model, Toon) | `intensity`, `depthThreshold`, `normalThreshold`, `thickness`, colour `lineColor` |
| `grayscale` | Desaturate | `intensity` |
### Anti-aliasing before the chain
@@ -493,7 +495,7 @@ package carries only when its content uses one:
| Group | Subpath | Effects |
|---|---|---|
-| Basic | `esengine/fx-basic` | blur, bloom, vignette, grayscale, colorGrade, lutGrade, agx, chromaticAberration, tonemap, fxaa, sharpen, lensDistortion, pixelate, outline, depthOutline, filmGrain, motionBlur, lensFlare |
+| Basic | `esengine/fx-basic` | blur, bloom, vignette, grayscale, colorGrade, lutGrade, agx, chromaticAberration, tonemap, fxaa, sharpen, lensDistortion, pixelate, outline, depthOutline, edgeOutline, filmGrain, motionBlur, lensFlare |
| Atmosphere | `esengine/fx-atmosphere` | skyAtmosphere, heightFog, distanceFog, rain |
| Lighting | `esengine/fx-lighting` | ssao, gtao, ssr, ssgi, voxelGI, contactShadows, lightShafts, autoExposure, depthOfField, subsurface, taa |
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
index 8b48e09b2..edd1a510b 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
@@ -45,6 +45,8 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess
| `lensDistortion` | 桶形 / 枕形畸变 | `strength`、`zoom` |
| `pixelate` | 块状量化 | `pixelSize` |
| `outline` | 墨线描边(Sobel 边缘压暗) | `intensity`、`threshold`、`thickness` |
+| `depthOutline` | 深度跳变处的黑色轮廓(轮廓,不是着色) | `intensity`、`threshold`、`thickness` |
+| `edgeOutline` | 轮廓**和**折痕处画一条有颜色的线:相机距离跳变处,以及表面法线转折处(需要写法线的表面:受光网格、Model、Toon) | `intensity`、`depthThreshold`、`normalThreshold`、`thickness`、颜色 `lineColor` |
| `grayscale` | 去色 | `intensity` |
### 链路之前的抗锯齿
@@ -378,7 +380,7 @@ stack.addPass('lutGrade', getEffectDef('lutGrade')!.factory())
| 组 | 子路径 | 效果 |
|---|---|---|
-| 基础 | `esengine/fx-basic` | blur、bloom、vignette、grayscale、colorGrade、lutGrade、chromaticAberration、tonemap、fxaa、sharpen、lensDistortion、pixelate、outline、depthOutline、filmGrain、motionBlur、lensFlare |
+| 基础 | `esengine/fx-basic` | blur、bloom、vignette、grayscale、colorGrade、lutGrade、chromaticAberration、tonemap、fxaa、sharpen、lensDistortion、pixelate、outline、depthOutline、edgeOutline、filmGrain、motionBlur、lensFlare |
| 大气 | `esengine/fx-atmosphere` | skyAtmosphere、heightFog、distanceFog、rain |
| 光照 | `esengine/fx-lighting` | ssao、gtao、ssr、ssgi、voxelGI、contactShadows、lightShafts、autoExposure、depthOfField、subsurface、taa |
diff --git a/fixtures/scenes/edge-outline.esscene b/fixtures/scenes/edge-outline.esscene
new file mode 100644
index 000000000..7ae0a7603
--- /dev/null
+++ b/fixtures/scenes/edge-outline.esscene
@@ -0,0 +1,377 @@
+{
+ "version": 4,
+ "name": "edge-outline",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 320,
+ "z": 480
+ },
+ "rotation": {
+ "x": -0.284,
+ "y": 0,
+ "z": 0,
+ "w": 0.9588
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "fov": 60,
+ "nearPlane": 10,
+ "farPlane": 3000,
+ "isActive": true,
+ "priority": 0
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "edgeOutline",
+ "enabled": true,
+ "uniforms": {
+ "u_intensity": 1,
+ "u_depthThreshold": 0.01,
+ "u_normalThreshold": 0.4,
+ "u_thickness": 2
+ },
+ "colors": {
+ "u_lineColor": {
+ "r": 1,
+ "g": 0,
+ "b": 0,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Floor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -200
+ },
+ "scale": {
+ "x": 14,
+ "y": 1,
+ "z": 14
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:plane",
+ "color": {
+ "r": 0.75,
+ "g": 0.75,
+ "b": 0.75,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "WallBack",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 125,
+ "z": -600
+ },
+ "scale": {
+ "x": 14,
+ "y": 2.5,
+ "z": 0.2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.7,
+ "g": 0.72,
+ "b": 0.78,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "WallLeft",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -600,
+ "y": 125,
+ "z": -200
+ },
+ "scale": {
+ "x": 0.2,
+ "y": 2.5,
+ "z": 8
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.7,
+ "g": 0.72,
+ "b": 0.78,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 4,
+ "name": "Step",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -330,
+ "y": 25,
+ "z": -80
+ },
+ "scale": {
+ "x": 2,
+ "y": 0.5,
+ "z": 2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.65,
+ "g": 0.75,
+ "b": 0.6,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 5,
+ "name": "BoxContact",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -110,
+ "y": 50,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.8,
+ "g": 0.55,
+ "b": 0.4,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 6,
+ "name": "BoxFloating",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 110,
+ "y": 100,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.45,
+ "g": 0.65,
+ "b": 0.8,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 7,
+ "name": "Sphere",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 330,
+ "y": 50,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "color": {
+ "r": 0.78,
+ "g": 0.7,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 8,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "intensity": 1.1,
+ "direction": {
+ "x": 0.5,
+ "y": -0.6
+ },
+ "directionZ": -0.6
+ }
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/pipeline/src/project/targetSupport.ts b/pipeline/src/project/targetSupport.ts
index 0ad0ab52b..b1bb3d97e 100644
--- a/pipeline/src/project/targetSupport.ts
+++ b/pipeline/src/project/targetSupport.ts
@@ -84,7 +84,7 @@ export const SUBSYSTEM_COMPONENTS: Readonly<Record<Subsystem, readonly string[]>
export const POST_PROCESS_EFFECT_GROUP: Readonly<Record<string, Subsystem>> = {
blur: 'fxBasic', bloom: 'fxBasic', vignette: 'fxBasic', grayscale: 'fxBasic', colorGrade: 'fxBasic',
chromaticAberration: 'fxBasic', tonemap: 'fxBasic', fxaa: 'fxBasic', lensDistortion: 'fxBasic', pixelate: 'fxBasic',
- outline: 'fxBasic', depthOutline: 'fxBasic', lutGrade: 'fxBasic', agx: 'fxBasic', sharpen: 'fxBasic', filmGrain: 'fxBasic',
+ outline: 'fxBasic', depthOutline: 'fxBasic', edgeOutline: 'fxBasic', lutGrade: 'fxBasic', agx: 'fxBasic', sharpen: 'fxBasic', filmGrain: 'fxBasic',
motionBlur: 'fxBasic', lensFlare: 'fxBasic',
distanceFog: 'fxAtmosphere', skyAtmosphere: 'fxAtmosphere', heightFog: 'fxAtmosphere', rain: 'fxAtmosphere',
voxelGI: 'fxLighting', ssgi: 'fxLighting', contactShadows: 'fxLighting', lightShafts: 'fxLighting',
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index 2cf4bfd01..96b7efa52 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -279,6 +279,23 @@ registerEffect({
],
});
+registerEffect({
+ type: 'edgeOutline',
+ label: 'Edge Outline',
+ factory: () => postProcessEffects.createEdgeOutline(),
+ uniforms: [
+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 1, step: 0.01, defaultValue: 1 },
+ // A silhouette: how far a neighbour is behind this pixel, as a share of its own depth.
+ { name: 'u_depthThreshold', label: 'Depth Threshold', min: 0.0005, max: 0.2, step: 0.0005, defaultValue: 0.01 },
+ // A crease: how far the two surfaces face apart (0 the same way, 1 at a right angle, 2 opposite).
+ { name: 'u_normalThreshold', label: 'Crease Threshold', min: 0.02, max: 1.5, step: 0.01, defaultValue: 0.4 },
+ { name: 'u_thickness', label: 'Thickness', min: 1, max: 4, step: 1, defaultValue: 1 },
+ ],
+ colors: [
+ { name: 'u_lineColor', label: 'Line Colour', defaultValue: { r: 0, g: 0, b: 0, a: 1 } },
+ ],
+});
+
registerEffect({
type: 'distanceFog',
label: 'Distance Fog',
@@ -816,7 +833,7 @@ const CATEGORIES: Record<EffectCategory, string[]> = {
light: ['ssao', 'gtao', 'ssgi', 'ssr', 'voxelGI', 'contactShadows', 'lightShafts', 'subsurface'],
atmosphere: ['distanceFog', 'heightFog', 'skyAtmosphere', 'rain'],
aa: ['fxaa', 'taa'],
- stylize: ['blur', 'pixelate', 'outline', 'depthOutline'],
+ stylize: ['blur', 'pixelate', 'outline', 'depthOutline', 'edgeOutline'],
};
for (const [category, types] of Object.entries(CATEGORIES) as [EffectCategory, string[]][]) {
for (const type of types) {
diff --git a/sdk/src/postprocess/sources/basic.ts b/sdk/src/postprocess/sources/basic.ts
index 1574f83c3..f75d1a495 100644
--- a/sdk/src/postprocess/sources/basic.ts
+++ b/sdk/src/postprocess/sources/basic.ts
@@ -10,6 +10,7 @@ import { registerEffectSources, registerComputeSource } from '../effectSources';
import { SHARPEN_WGSL } from '../computeEffects';
import { lensEffects } from '../lensEffects';
import { AGX_LUT_BASE64, AGX_LUT_SIZE } from '../agxLut.generated';
+import { SSAO_GLSL, SSAO_WGSL, GBUFFER_GLSL, GBUFFER_WGSL } from './shared';
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -817,6 +818,122 @@ fn depthAt(texel : vec2i, size : vec2i) -> f32 {
return vec4f(mix(src.rgb, vec3f(0.0), vec3f(edge * mc.u_intensity)), src.a);
}
#pragma end
+`;
+ return Material.compileShader(source);
+ },
+ createEdgeOutline(): ShaderHandle {
+ // A line wherever the scene's SURFACE changes: where the depth steps (a silhouette, one thing in front of another) or the normal turns (a
+ // crease, a fold, the edge of a face), in a colour of the author's choosing. `depthOutline` reads the depth alone and draws in black, so a cube
+ // standing on a floor has only its outline; this finds its edges too, which is what an inked, toon look needs.
+ //
+ // Distance is the world distance from the camera, compared as a RATIO so one threshold holds across the view: the window depth the buffer
+ // holds is nowhere near linear (a perspective view puts everything past the first few percent of its range within a hair of 1), so a ratio of
+ // THAT finds no edge at all. The normal is the scene's own, written beside its colour by the shaders that write one (`#pragma gbuffer`):
+ // a pixel nothing wrote one for takes part in the silhouette and not in the crease.
+ const source = `#pragma shader "PP Edge Outline"
+#pragma version 300 es
+#pragma domain PostProcess
+#pragma param u_intensity float default(1) range(0,1)
+#pragma param u_depthThreshold float default(0.01) range(0.0005,0.2)
+#pragma param u_normalThreshold float default(0.4) range(0.02,1.5)
+#pragma param u_thickness float default(1) range(1,4)
+#pragma param u_lineColor color default(0,0,0,1)
+#pragma gbuffer
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+uniform highp sampler2D u_sceneDepth;
+uniform sampler2D u_gbuffer;
+out vec4 fragColor;
+
+${SSAO_GLSL}
+${GBUFFER_GLSL}
+
+// How far the surface at a texel is from the camera: along the view ray for a perspective view, along the view axis for an orthographic one.
+float viewDistance(ivec2 t, ivec2 size) {
+ vec3 P = worldAt(t, size);
+ return u_camera.w > 0.5 ? length(P - u_camera.xyz) : abs(dot(P, u_camera.xyz));
+}
+
+void main() {
+ vec4 src = texture(u_texture, v_texCoord);
+ ivec2 size = textureSize(u_sceneDepth, 0);
+ ivec2 here = screenTexel(v_texCoord, size);
+ int step = int(max(u_thickness, 1.0));
+
+ // Nothing was drawn here: the cleared far plane has no silhouette to find, and testing it would ring the whole frame.
+ if (depthAt(here, size) >= 1.0 || u_intensity <= 0.0) { fragColor = src; return; }
+ float d = viewDistance(here, size);
+
+ ivec2 offsets[4] = ivec2[4](ivec2(-step, 0), ivec2(step, 0), ivec2(0, -step), ivec2(0, step));
+ Surface mine = readSurface(here);
+ float around[4];
+ float crease = 0.0;
+ for (int i = 0; i < 4; ++i) {
+ ivec2 at = here + offsets[i];
+ // The cleared far plane beside a surface is a silhouette too, at the far side of anything: it counts as very far away.
+ around[i] = depthAt(at, size) >= 1.0 ? d * 1000.0 : viewDistance(at, size);
+ if (mine.known) {
+ Surface other = readSurface(clamp(at, ivec2(0), size - ivec2(1)));
+ // How far the two surfaces face apart; only between two that wrote a normal.
+ if (other.known) crease = max(crease, 1.0 - dot(mine.normal, other.normal));
+ }
+ }
+ // How much farther the two neighbours along an axis are than this pixel, on average: a step has it, and so does nothing else. A plane seen
+ // at a grazing angle changes distance fast but steadily, which is no edge, and the far side of a step has nearer neighbours, which is no
+ // second outline of its own.
+ float lap = max((around[0] + around[1]) * 0.5 - d, (around[2] + around[3]) * 0.5 - d) / max(d, 1e-3);
+ float silhouette = clamp((lap - u_depthThreshold) * 20.0, 0.0, 1.0);
+ float fold = clamp((crease - u_normalThreshold) * 8.0, 0.0, 1.0);
+ float edge = max(silhouette, fold) * u_intensity * u_lineColor.a;
+ fragColor = vec4(mix(src.rgb, u_lineColor.rgb, edge), src.a);
+}
+#pragma end
+
+#pragma fragment wgsl
+${SSAO_WGSL}
+${GBUFFER_WGSL}
+
+fn viewDistance(t : vec2i, size : vec2i) -> f32 {
+ let P = worldAt(t, size);
+ if (frame.camera.w > 0.5) { return length(P - frame.camera.xyz); }
+ return abs(dot(P, frame.camera.xyz));
+}
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);
+ let size = vec2i(textureDimensions(t7, 0));
+ let here = screenTexel(v.v_texCoord, size);
+ let step = i32(max(mc.u_thickness, 1.0));
+
+ if (depthAt(here, size) >= 1.0 || mc.u_intensity <= 0.0) { return src; }
+ let d = viewDistance(here, size);
+
+ let mine = readSurface(here);
+ var around = array<f32, 4>(0.0, 0.0, 0.0, 0.0);
+ var crease = 0.0;
+ for (var i : i32 = 0; i < 4; i = i + 1) {
+ var offset = vec2i(0, 0);
+ if (i == 0) { offset = vec2i(-step, 0); } else if (i == 1) { offset = vec2i(step, 0); } else if (i == 2) { offset = vec2i(0, -step); } else { offset = vec2i(0, step); }
+ let at = here + offset;
+ var reach = d * 1000.0;
+ if (depthAt(at, size) < 1.0) { reach = viewDistance(at, size); }
+ around[i] = reach;
+ if (mine.known) {
+ let other = readSurface(clamp(at, vec2i(0), size - vec2i(1)));
+ if (other.known) { crease = max(crease, 1.0 - dot(mine.normal, other.normal)); }
+ }
+ }
+ let lap = max((around[0] + around[1]) * 0.5 - d, (around[2] + around[3]) * 0.5 - d) / max(d, 1e-3);
+ let silhouette = clamp((lap - mc.u_depthThreshold) * 20.0, 0.0, 1.0);
+ let fold = clamp((crease - mc.u_normalThreshold) * 8.0, 0.0, 1.0);
+ let edge = max(silhouette, fold) * mc.u_intensity * mc.u_lineColor.a;
+ return vec4f(mix(src.rgb, mc.u_lineColor.rgb, vec3f(edge)), src.a);
+}
+#pragma end
`;
return Material.compileShader(source);
},
diff --git a/sdk/tests/shader-twins.test.ts b/sdk/tests/shader-twins.test.ts
index 965851f69..cb20d5769 100644
--- a/sdk/tests/shader-twins.test.ts
+++ b/sdk/tests/shader-twins.test.ts
@@ -53,7 +53,7 @@ describe('embedded .esshader structure', () => {
it('found the filter, effect and grid sources', () => {
expect(CASES.filter((c) => c.name.startsWith('filters.ts')).length).toBe(1);
expect(CASES.filter((c) => c.name.startsWith('spriteFilter.ts')).length).toBe(2);
- expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(37);
+ expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(38);
expect(CASES.filter((c) => c.name.startsWith('editorGridRenderer.ts')).length).toBe(1);
});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index ead889c8e..072d0f7d1 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3006,4 +3006,6 @@ export const NOTED = {
{"note":"Toon and Matcap materials."},
"feat(render): filled polygons and joined strokes as a path on a mesh":
{"note":"Filled polygons and joined strokes."},
+ "feat(render): an edge outline effect with a colour and creases":
+ {"note":"Edge Outline, a coloured line at silhouettes and creases."},
};
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 9b121ac76..b21fb1564 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -771,6 +771,7 @@ export const SCENES = [
{ id: "aa-edge", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/aa-edge.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.2353,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.2392,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.749,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.7529,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.502,\"y\":0.502,\"rgb\":[255,255,255],\"tol\":6},{\"x\":0.0784,\"y\":0.0784,\"rgb\":[0,0,0],\"tol\":6}]" } },
// The other half: the same edges, read through an identity post chain.
{ id: "aa-edge-post", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/aa-edge-post.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.2353,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.2392,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.749,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.7529,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.502,\"y\":0.502,\"rgb\":[255,255,255],\"tol\":6},{\"x\":0.0784,\"y\":0.0784,\"rgb\":[0,0,0],\"tol\":6}]" } },
+ { id: "edge-outline", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/edge-outline.esscene", ESTELLA_VERIFY_W: "640", ESTELLA_VERIFY_H: "480", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.2458,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.5,\"y\":0.85,\"rgb\":[129,129,129],\"tol\":12},{\"x\":0.36,\"y\":0.42,\"rgb\":[137,95,70],\"tol\":15},{\"x\":0.7,\"y\":0.45,\"rgb\":[128,128,128],\"tol\":12}]" } },
{ id: "ssao", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssao.esscene", ESTELLA_VERIFY_W: "320", ESTELLA_VERIFY_H: "240", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5016,\"y\":0.8996,\"rgb\":[191,191,191],\"tol\":6},{\"x\":0.3762,\"y\":0.4937,\"rgb\":[144,144,144],\"tol\":20},{\"x\":0.627,\"y\":0.4812,\"rgb\":[172,172,172],\"tol\":9},{\"x\":0.8527,\"y\":0.4686,\"rgb\":[147,147,147],\"tol\":9},{\"x\":0.1881,\"y\":0.5272,\"rgb\":[123,141,113],\"tol\":22},{\"x\":0.1285,\"y\":0.1967,\"rgb\":[133,136,148],\"tol\":9},{\"x\":0.627,\"y\":0.2008,\"rgb\":[179,184,199],\"tol\":5}]" } },
// The same occlusion with a neutral colour grade ahead of it in the chain: a pass
// behind another one still samples the scene's depth, and on WebGPU the colour it