@driftengine/core 4.4.0 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -1,4 +1,25 @@
1
1
  [
2
+ {
3
+ "version": "4.4.1",
4
+ "date": "2026-09-28",
5
+ "entries": [
6
+ {
7
+ "kind": "fixed",
8
+ "short": "Ambient occlusion no longer lays stripes across a surface seen edge on, or darkens one with nothing on it: a far floor or a ramp reads smooth and open.",
9
+ "text": "**The blur refused every neighbour of a surface seen edge on**, because it compared each tap's depth with the centre's: a floor forty metres out changes its depth by four percent a row, twice the tolerance, so the pass down the frame kept the centre alone and the estimate's rotation pattern stayed on screen as four-pixel stripes across every ramp and far floor. A tap is now compared with the depth this pixel's own plane predicts there, which is exact because 1/z is affine across a plane, so it is refused only for leaving the surface. Measured on a game's ramp at night, the row-to-row ripple fell from 0.028 to 0.0017, and silhouettes are unchanged.\n\n**And the estimate is stored at half scale.** On a plane turned from the eye one of a pixel's two lines sees more than the whole sky and the other less, and only the average over every turn is exactly one; an eight-bit target clipped each turn above one before the blur could average it, so an open plane seen at 80° came back 3.6% shaded. Scenes with occlusion on change where they have surfaces seen edge on."
10
+ },
11
+ {
12
+ "kind": "fixed",
13
+ "short": "A light that declines to cast no longer moves every lamp after it onto its neighbour's shadow, so street lamps keep their own shadows while a car's headlights are on.",
14
+ "text": "**`updatePointShadows` published each shadow at the wrong place after a light that declines to cast.** The shader reads a light's shadow at the light's own place in the shaded list; the lights that cast were gathered into a shorter list first, and each shadow was published at its place in that one. So a light with `castsShadow: false` moved every casting light after it one place down: the first lamp's shadow landed on the declining light and each lamp after it wore the next one's. A light riding a camera or a car is exactly the light that declines, and it is nearly always shaded first. The place is now kept, and left empty.\n\nA consumer that worked around this by handing over only the lights before the first one that declines can hand over the whole count. That cap is what switched lamps' shadows on and off as a car moved, because which lamps rank ahead of its headlights changes with every metre."
15
+ },
16
+ {
17
+ "kind": "fixed",
18
+ "short": "The published packages carry only what the engine is: no local build caches in the packager, and no compiled leftovers of modules since deleted.",
19
+ "text": "**`@driftengine/package` had shipped the packager's local Gradle caches and a build report since at least 4.2.0.** Its `files` names `android` whole, and the ignore rules for that directory's build output live in the repository's `.gitignore`, which npm does not read for a package. Nineteen files, none of them the engine's and none carrying a path or a name from the machine that built them, checked; they are excluded now, with the rest of what an Android build writes.\n\n**And 4.4.0 shipped two modules whose sources had been deleted**, `core`'s `render/shaders/agx.js` and `texture`'s `tensor/reuse.js`, because the build wrote into `dist` and never emptied it. It empties it first now, and `npm run cleanroom` refuses a tarball holding any file that is neither tracked nor built from a source that exists."
20
+ }
21
+ ]
22
+ },
2
23
  {
3
24
  "version": "4.4.0",
4
25
  "date": "2026-09-28",
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The runtime everything needs: renderer, loop, camera, input, geometry. Collision and dynamics live in [`@driftengine/physics`](../physics/README.md), which this package depends on and re-exports whole, so reaching for them through this barrel works as it always did.
4
4
 
5
- **Cost: 789.3 KB gzipped, importing `createRenderer`.** Measured by `scripts/size-gate.test.mjs`, which fails if it drifts more than
5
+ **Cost: 789.9 KB gzipped, importing `createRenderer`.** Measured by `scripts/size-gate.test.mjs`, which fails if it drifts more than
6
6
  3% — the number is a fact about the build rather than a claim in a document.
7
7
 
8
8
  Part of [DriftEngine](../../README.md). See [`docs/ARCHITECTURE.md`](../../docs/ARCHITECTURE.md)
@@ -1,4 +1,4 @@
1
- import { AO_BLUR_FRAG, AO_FRAG } from './shaders/ambientOcclusion.js';
1
+ import { AO_BLUR_FRAG, AO_FRAG, AO_STORE } from './shaders/ambientOcclusion.js';
2
2
  import { FULLSCREEN_VERT } from './shaders/fullscreen.js';
3
3
  import { compileProgram, uniformLocations } from './shader.js';
4
4
  /**
@@ -146,6 +146,8 @@ export class AmbientOcclusionPass {
146
146
  this.step[0] = 1 / width;
147
147
  this.step[1] = 0;
148
148
  gl.uniform2fv(this.blurUniforms['uStep'] ?? null, this.step);
149
+ /* Still at the estimate's scale, which the second axis needs whole. */
150
+ gl.uniform1f(this.blurUniforms['uAoScale'] ?? null, 1);
149
151
  gl.drawArrays(gl.TRIANGLES, 0, 3);
150
152
  /* And down, back into the estimate, which is the texture handed out. */
151
153
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.estimateFramebuffer);
@@ -153,6 +155,8 @@ export class AmbientOcclusionPass {
153
155
  this.step[0] = 0;
154
156
  this.step[1] = 1 / height;
155
157
  gl.uniform2fv(this.blurUniforms['uStep'] ?? null, this.step);
158
+ /* And decoded, so the composite reads open sky as one. */
159
+ gl.uniform1f(this.blurUniforms['uAoScale'] ?? null, 1 / AO_STORE);
156
160
  gl.drawArrays(gl.TRIANGLES, 0, 3);
157
161
  gl.bindVertexArray(null);
158
162
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
@@ -68,7 +68,7 @@ declare const RUSH_TEXTURES: {
68
68
  export declare const AO_FRAG_FIELDS: UniformFields;
69
69
  export declare const AO_FRAG_SIZE: 96;
70
70
  export declare const AO_BLUR_FIELDS: UniformFields;
71
- export declare const AO_BLUR_SIZE: 32;
71
+ export declare const AO_BLUR_SIZE: 48;
72
72
  export declare const MEDIUM_FRAG_FIELDS: UniformFields;
73
73
  export declare const MEDIUM_FRAG_SIZE: 240;
74
74
  export declare const MEDIUM_UPSAMPLE_FIELDS: UniformFields;
@@ -48,6 +48,7 @@ import { reflectionTargetSize } from '../../planarReflectionDraw.js';
48
48
  import { drawingBufferSize } from '../../drawingBuffer.js';
49
49
  import { MOTION_BLUR_MAX_UV, OUTPUT_TRANSFORM_CODE, RUSH_REACH_UV } from '../../vertexDefaults.js';
50
50
  import { ExposurePass } from './exposurePass.js';
51
+ import { AO_STORE } from '../../shaders/ambientOcclusion.js';
51
52
  import { clampAutoExposure } from '../../shaders/exposure.js';
52
53
  import { clampLocalExposure } from '../../shaders/localExposure.js';
53
54
  import { createDepthResolveLayout, createPostStageLayout, depthResolvePipeline, postPipeline, sceneColorFormat, AO_BLUR_FIELDS, AO_BLUR_FRAG_WGSL, AO_BLUR_SIZE, AO_BLUR_TEXTURES, AO_BLUR_UNIFORMS, AO_FRAG_FIELDS, AO_FRAG_SIZE, AO_FRAG_WGSL, AO_TEXTURES, AO_UNIFORMS, ADDITIVE_BLEND, BLOOM_DOWNSAMPLE_FIELDS, BLOOM_DOWNSAMPLE_FRAG_WGSL, BLOOM_PREFILTER_FIELDS, BLOOM_PREFILTER_FRAG_WGSL, BLOOM_STAGE_SIZE, BLOOM_TEXTURES, BLOOM_UNIFORMS, BLOOM_UPSAMPLE_FIELDS, BLOOM_UPSAMPLE_FRAG_WGSL, RESOLVED_DEPTH_FORMAT, RUSH_FRAG_FIELDS, RUSH_FRAG_SIZE, RUSH_FRAG_WGSL, RUSH_TEXTURES, RUSH_UNIFORMS, TAA_FRAG_FIELDS, TAA_FRAG_SIZE, TAA_TEXTURES, TAA_UNIFORMS, TEMPORAL_RESOLVE_FRAG_WGSL, MEDIUM_FRAG_FIELDS, MEDIUM_FRAG_SIZE, MEDIUM_FRAG_WGSL, MEDIUM_TEXTURES, MEDIUM_TRANSMIT_BLEND, MEDIUM_UNIFORMS, MEDIUM_UPSAMPLE_FIELDS, MEDIUM_UPSAMPLE_FRAG_WGSL, MEDIUM_UPSAMPLE_SIZE, MEDIUM_UPSAMPLE_TEXTURES, MEDIUM_UPSAMPLE_UNIFORMS, OIT_COMPOSITE_BLEND, OIT_RESOLVE_FRAG_WGSL, OIT_TEXTURES, DECAL_FRAG_FIELDS, DECAL_FRAG_SIZE, DECAL_MULTIPLY_BLEND, DECAL_PROJECT_FRAG_WGSL, DECAL_TEXTURES, DECAL_UNIFORMS, PREMULTIPLIED_OVER_BLEND, SSR_FRAG_FIELDS, SSR_FRAG_SIZE, SSR_RESOLVE_FRAG_WGSL, SSR_RESOLVE_TEXTURES, SSR_TEXTURES, SSR_TRACE_FRAG_WGSL, SSR_UNIFORMS, createOitResolveLayout, createSsrResolveLayout, } from './postPass.js';
@@ -9124,12 +9125,15 @@ export class WebGPURenderer {
9124
9125
  otherwise halve the blur and leave half the pattern standing. */
9125
9126
  const width = Math.max(1, this.aoTarget?.width ?? 1);
9126
9127
  const height = Math.max(1, this.aoTarget?.height ?? 1);
9127
- for (const [index, step] of [
9128
- [0, [1 / width, 0]],
9129
- [1, [0, 1 / height]],
9128
+ /* Across at the estimate's own scale, which the second axis needs whole; down decoded, so the
9129
+ composite reads open sky as one. The same two `ambientOcclusionPass.ts` writes. */
9130
+ for (const [index, step, scale] of [
9131
+ [0, [1 / width, 0], 1],
9132
+ [1, [0, 1 / height], 1 / AO_STORE],
9130
9133
  ]) {
9131
9134
  f[slot(index) + at('uStep')] = step[0];
9132
9135
  f[slot(index) + at('uStep') + 1] = step[1];
9136
+ f[slot(index) + at('uAoScale')] = scale;
9133
9137
  f[slot(index) + at('uDepthToViewZ')] = inv[10] ?? 0;
9134
9138
  f[slot(index) + at('uDepthToViewZ') + 1] = inv[14] ?? 0;
9135
9139
  f[slot(index) + at('uDepthToViewZ') + 2] = inv[11] ?? 0;
@@ -45,7 +45,8 @@ ready: Uint8Array, count: number, out: Int32Array,
45
45
  */
46
46
  chronic?: Uint8Array): number;
47
47
  /**
48
- * The shaded lights that also cast, in the order they were shaded.
48
+ * The shaded lights that also cast, each at its own place in the shaded list, and −1 at the place
49
+ * of a light that does not.
49
50
  *
50
51
  * `castsShadow: false` says a light is not worth a cubemap. `selectPointLights` honours
51
52
  * that when it builds the *eligible* list, and that was taken for the whole promise — but
@@ -57,7 +58,16 @@ chronic?: Uint8Array): number;
57
58
  * It showed up as a shadow with nothing to throw it — a lamp that rides the camera
58
59
  * declines to cast for exactly that reason, and cast anyway.
59
60
  *
60
- * Writes into `out` and returns how many it wrote; allocation-free, because this runs
61
+ * **The place is kept rather than the gap closed, because the place is the shader's index.** The
62
+ * pool publishes each map under its light's position in this list, and the shader reads a light's
63
+ * shadow at the light's position in the shaded one. Closing the gap made the two numberings
64
+ * disagree after the first light that declined: every lamp shaded after it was published one
65
+ * place down, the first on the declining light and each of the rest on its neighbour. A consumer
66
+ * whose headlights decline, and are nearly always shaded first, could only keep its lamps honest by
67
+ * dropping the shadows of every lamp ranked after them, and which lamps those were changed as the
68
+ * car moved.
69
+ *
70
+ * Writes into `out` and returns how many places it wrote; allocation-free, because this runs
61
71
  * every frame.
62
72
  */
63
73
  export declare function selectCastingLights(lights: readonly {
@@ -84,7 +84,8 @@ chronic) {
84
84
  return written;
85
85
  }
86
86
  /**
87
- * The shaded lights that also cast, in the order they were shaded.
87
+ * The shaded lights that also cast, each at its own place in the shaded list, and −1 at the place
88
+ * of a light that does not.
88
89
  *
89
90
  * `castsShadow: false` says a light is not worth a cubemap. `selectPointLights` honours
90
91
  * that when it builds the *eligible* list, and that was taken for the whole promise — but
@@ -96,20 +97,25 @@ chronic) {
96
97
  * It showed up as a shadow with nothing to throw it — a lamp that rides the camera
97
98
  * declines to cast for exactly that reason, and cast anyway.
98
99
  *
99
- * Writes into `out` and returns how many it wrote; allocation-free, because this runs
100
+ * **The place is kept rather than the gap closed, because the place is the shader's index.** The
101
+ * pool publishes each map under its light's position in this list, and the shader reads a light's
102
+ * shadow at the light's position in the shaded one. Closing the gap made the two numberings
103
+ * disagree after the first light that declined: every lamp shaded after it was published one
104
+ * place down, the first on the declining light and each of the rest on its neighbour. A consumer
105
+ * whose headlights decline, and are nearly always shaded first, could only keep its lamps honest by
106
+ * dropping the shadows of every lamp ranked after them, and which lamps those were changed as the
107
+ * car moved.
108
+ *
109
+ * Writes into `out` and returns how many places it wrote; allocation-free, because this runs
100
110
  * every frame.
101
111
  */
102
112
  export function selectCastingLights(lights, activeWorldIndices, activeCount, out) {
103
- let written = 0;
104
- for (let i = 0; i < activeCount && written < out.length; i++) {
113
+ const count = Math.min(activeCount, out.length);
114
+ for (let i = 0; i < count; i++) {
105
115
  const worldIndex = activeWorldIndices[i] ?? -1;
106
- if (worldIndex < 0)
107
- continue;
108
- if (lights[worldIndex]?.castsShadow === false)
109
- continue;
110
- out[written++] = worldIndex;
116
+ out[i] = worldIndex >= 0 && lights[worldIndex]?.castsShadow !== false ? worldIndex : -1;
111
117
  }
112
- return written;
118
+ return count;
113
119
  }
114
120
  /**
115
121
  * How many consecutive frames a slot must be stale before it is treated as chronically so.
@@ -24,7 +24,8 @@
24
24
  * wherever the depth test cuts the window short, as a dotted line along every edge.
25
25
  */
26
26
  /**
27
- * The estimate. Writes one channel: 1 is open sky, 0 is fully enclosed.
27
+ * The estimate. Writes one channel at `AO_STORE`: that is open sky, 0 is fully enclosed, and the
28
+ * second axis of the blur decodes it.
28
29
  *
29
30
  * **Horizons, not neighbours: ground-truth ambient occlusion (Jimenez et al. 2016).** Each pixel
30
31
  * walks two lines across the screen, both ways, and keeps the highest thing it can see along each
@@ -62,3 +63,40 @@ export declare function gtaoArc(h0: number, h1: number, normal: number): number;
62
63
  export declare function nextHorizon(horizon: number, cosine: number): number;
63
64
  /** The shader's thickness heuristic. See `AO_THIN` inside `AO_FRAG`. */
64
65
  export declare const AO_THIN = 0.2;
66
+ /**
67
+ * What the estimate is multiplied by before it is stored, and divided by once the blur is done.
68
+ *
69
+ * **Half, because an unblurred estimate is allowed past one.** A pixel's two lines see a plane
70
+ * turned away from the eye from two directions, and the closed form credits one of them more than
71
+ * the whole sky and the other less: it is the average over every turn that is exactly one, and the
72
+ * average is what the blur is for. Stored as it came, an eight-bit target clipped every turn above
73
+ * one before the blur could average it, and every surface seen edge on came back a few percent
74
+ * shaded with nothing on it. A line reaches π/2 at most, so half fits the whole range.
75
+ *
76
+ * What it gives up is one bit of the intermediate: steps of 1/128 rather than 1/256 until the
77
+ * second axis decodes, which the eight taps a pixel averages carry below what a frame can show.
78
+ */
79
+ export declare const AO_STORE = 0.5;
80
+ /** How far a neighbour may sit from this pixel's surface, as a fraction of its distance. */
81
+ export declare const AO_BLUR_DEPTH_TOLERANCE = 0.02;
82
+ /**
83
+ * The blur's weight for a neighbour `offset` pixels along the axis, from view depths: this pixel's
84
+ * own, the two either side of it, and the neighbour's. The shader's lines written out again.
85
+ *
86
+ * **The neighbour is compared with this pixel's plane, not with this pixel's depth.** Comparing
87
+ * depths refused every neighbour of a surface seen edge on: a floor forty metres out changes its
88
+ * depth by four percent a row, twice the tolerance, so the pass down the frame kept the centre alone
89
+ * and left the rotation tile's rows standing — four-pixel stripes across every ramp and far floor,
90
+ * reported as strips on a track. On a plane 1/z is affine in the screen, so one step of it predicts
91
+ * the plane's depth at every tap exactly, and a tap is refused only for leaving the plane.
92
+ *
93
+ * The step is taken from whichever neighbour is closer to the centre in 1/z. At a silhouette that is
94
+ * the one on this pixel's own side, so the far surface cannot bend the prediction toward it; on a
95
+ * plane the two agree to a quantisation step, which moves a weight by nothing a frame shows. What it
96
+ * gives up is a crease: past the fold between a floor and a wall the prediction runs on along the
97
+ * floor, so the wall's taps fade out over the tolerance rather than being kept.
98
+ *
99
+ * **Written here rather than in the shader**, because a comment inside the GLSL is part of the string
100
+ * a consumer ships.
101
+ */
102
+ export declare function blurWeight(centre: number, before: number, after: number, neighbour: number, offset: number): number;
@@ -25,7 +25,8 @@ import { glslIsFarDepth, glslSceneDepthToNdc } from '../depthConvention.js';
25
25
  * wherever the depth test cuts the window short, as a dotted line along every edge.
26
26
  */
27
27
  /**
28
- * The estimate. Writes one channel: 1 is open sky, 0 is fully enclosed.
28
+ * The estimate. Writes one channel at `AO_STORE`: that is open sky, 0 is fully enclosed, and the
29
+ * second axis of the blur decodes it.
29
30
  *
30
31
  * **Horizons, not neighbours: ground-truth ambient occlusion (Jimenez et al. 2016).** Each pixel
31
32
  * walks two lines across the screen, both ways, and keeps the highest thing it can see along each
@@ -117,6 +118,8 @@ const float AO_EDGE_RATIO = 8.0;
117
118
  * and far below the step at any edge worth shading — a kerb against a deck is metres of it.
118
119
  */
119
120
  const float AO_EDGE_FLOOR = 0.05;
121
+ /** Stored at half, so a turn the closed form credits past one reaches the blur whole. See AO_STORE in the module. */
122
+ const float AO_STORE = 0.5;
120
123
 
121
124
  /** View-space position of whatever is at this pixel, from its depth alone. */
122
125
  vec3 viewPosition(vec2 uv, float depth) {
@@ -304,7 +307,7 @@ void main() {
304
307
  visible += projectedLength * gtaoArc(h0, h1, normalAngle);
305
308
  }
306
309
 
307
- fragColor = clamp(visible / float(AO_SLICES), 0.0, 1.0);
310
+ fragColor = clamp(visible / float(AO_SLICES) * AO_STORE, 0.0, 1.0);
308
311
  }
309
312
  `;
310
313
  /**
@@ -333,12 +336,14 @@ uniform vec2 uStep;
333
336
  * asks that question five times per pixel.
334
337
  */
335
338
  uniform vec4 uDepthToViewZ;
339
+ /** One across, carrying the estimate's AO_STORE scale; its inverse down, decoding it. */
340
+ uniform float uAoScale;
336
341
 
337
342
  out float fragColor;
338
343
 
339
344
  /**
340
- * How far apart two pixels may be, as a fraction of their distance from the eye, before they
341
- * stop being the same surface.
345
+ * How far a neighbour may sit from the depth this pixel's own surface predicts there, as a
346
+ * fraction of that depth, before it stops being the same surface.
342
347
  *
343
348
  * Relative rather than absolute, because the same 5 cm step is a cliff on a dashboard and
344
349
  * nothing at all on a far wall.
@@ -351,8 +356,19 @@ float viewZ(float depth) {
351
356
  }
352
357
 
353
358
  void main() {
354
- float centre = viewZ(textureLod(uDepth, vUv, 0.0).r);
355
- float tolerance = AO_BLUR_DEPTH_TOLERANCE * abs(centre) + 1e-4;
359
+ float depth = textureLod(uDepth, vUv, 0.0).r;
360
+ float own = textureLod(uAo, vUv, 0.0).r;
361
+ /* Nothing to average over the sky, and no surface to predict one from. */
362
+ if (${glslIsFarDepth('depth')}) {
363
+ fragColor = min(own * uAoScale, 1.0);
364
+ return;
365
+ }
366
+ float centre = viewZ(depth);
367
+ /* Each tap is compared with this pixel's plane, not with its depth. See blurWeight in the module. */
368
+ float inverse = 1.0 / centre;
369
+ float stepAfter = 1.0 / viewZ(textureLod(uDepth, vUv + uStep, 0.0).r) - inverse;
370
+ float stepBefore = inverse - 1.0 / viewZ(textureLod(uDepth, vUv - uStep, 0.0).r);
371
+ float slope = abs(stepAfter) < abs(stepBefore) ? stepAfter : stepBefore;
356
372
  float sum = 0.0;
357
373
  float weight = 0.0;
358
374
  /*
@@ -380,14 +396,15 @@ void main() {
380
396
  for (int i = -3; i <= 4; i++) {
381
397
  vec2 uv = vUv + uStep * float(i);
382
398
  float z = viewZ(textureLod(uDepth, uv, 0.0).r);
383
- /* One if this neighbour is on the same surface, falling to zero across an edge. */
384
- float w = max(0.0, 1.0 - abs(z - centre) / tolerance);
399
+ /* One if this neighbour is on this pixel's surface, falling to zero as it leaves it. */
400
+ float w = max(0.0, 1.0 - abs(z * (inverse + slope * float(i)) - 1.0) / AO_BLUR_DEPTH_TOLERANCE);
385
401
  sum += textureLod(uAo, uv, 0.0).r * w;
386
402
  weight += w;
387
403
  }
388
404
  /* An isolated pixel — a thin rail against a far wall — keeps its own estimate rather than
389
405
  dividing by nothing. */
390
- fragColor = weight > 0.0 ? sum / weight : textureLod(uAo, vUv, 0.0).r;
406
+ float blurred = weight > 0.0 ? sum / weight : own;
407
+ fragColor = min(blurred * uAoScale, 1.0);
391
408
  }
392
409
  `;
393
410
  /**
@@ -407,3 +424,46 @@ export function nextHorizon(horizon, cosine) {
407
424
  }
408
425
  /** The shader's thickness heuristic. See `AO_THIN` inside `AO_FRAG`. */
409
426
  export const AO_THIN = 0.2;
427
+ /**
428
+ * What the estimate is multiplied by before it is stored, and divided by once the blur is done.
429
+ *
430
+ * **Half, because an unblurred estimate is allowed past one.** A pixel's two lines see a plane
431
+ * turned away from the eye from two directions, and the closed form credits one of them more than
432
+ * the whole sky and the other less: it is the average over every turn that is exactly one, and the
433
+ * average is what the blur is for. Stored as it came, an eight-bit target clipped every turn above
434
+ * one before the blur could average it, and every surface seen edge on came back a few percent
435
+ * shaded with nothing on it. A line reaches π/2 at most, so half fits the whole range.
436
+ *
437
+ * What it gives up is one bit of the intermediate: steps of 1/128 rather than 1/256 until the
438
+ * second axis decodes, which the eight taps a pixel averages carry below what a frame can show.
439
+ */
440
+ export const AO_STORE = 0.5;
441
+ /** How far a neighbour may sit from this pixel's surface, as a fraction of its distance. */
442
+ export const AO_BLUR_DEPTH_TOLERANCE = 0.02;
443
+ /**
444
+ * The blur's weight for a neighbour `offset` pixels along the axis, from view depths: this pixel's
445
+ * own, the two either side of it, and the neighbour's. The shader's lines written out again.
446
+ *
447
+ * **The neighbour is compared with this pixel's plane, not with this pixel's depth.** Comparing
448
+ * depths refused every neighbour of a surface seen edge on: a floor forty metres out changes its
449
+ * depth by four percent a row, twice the tolerance, so the pass down the frame kept the centre alone
450
+ * and left the rotation tile's rows standing — four-pixel stripes across every ramp and far floor,
451
+ * reported as strips on a track. On a plane 1/z is affine in the screen, so one step of it predicts
452
+ * the plane's depth at every tap exactly, and a tap is refused only for leaving the plane.
453
+ *
454
+ * The step is taken from whichever neighbour is closer to the centre in 1/z. At a silhouette that is
455
+ * the one on this pixel's own side, so the far surface cannot bend the prediction toward it; on a
456
+ * plane the two agree to a quantisation step, which moves a weight by nothing a frame shows. What it
457
+ * gives up is a crease: past the fold between a floor and a wall the prediction runs on along the
458
+ * floor, so the wall's taps fade out over the tolerance rather than being kept.
459
+ *
460
+ * **Written here rather than in the shader**, because a comment inside the GLSL is part of the string
461
+ * a consumer ships.
462
+ */
463
+ export function blurWeight(centre, before, after, neighbour, offset) {
464
+ const inverse = 1 / centre;
465
+ const stepAfter = 1 / after - inverse;
466
+ const stepBefore = inverse - 1 / before;
467
+ const slope = Math.abs(stepAfter) < Math.abs(stepBefore) ? stepAfter : stepBefore;
468
+ return Math.max(0, 1 - Math.abs(neighbour * (inverse + slope * offset) - 1) / AO_BLUR_DEPTH_TOLERANCE);
469
+ }
@@ -1,5 +1,5 @@
1
- export declare const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var centre: f32;\n var param: f32;\n var tolerance: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_1: f32;\n var w: f32;\n var local: f32;\n\n let _e31 = vUv_1;\n let _e32 = textureSampleLevel(uDepth_t, uDepth_s, _e31, 0f);\n param = _e32.x;\n let _e34 = viewZ_u0028_f1_u003b((&param));\n centre = _e34;\n let _e35 = centre;\n tolerance = ((0.02f * abs(_e35)) + 0.0001f);\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e39 = i;\n if (_e39 <= 4i) {\n let _e41 = vUv_1;\n let _e43 = unnamed.uStep;\n let _e44 = i;\n uv = (_e41 + (_e43 * f32(_e44)));\n let _e48 = uv;\n let _e49 = textureSampleLevel(uDepth_t, uDepth_s, _e48, 0f);\n param_1 = _e49.x;\n let _e51 = viewZ_u0028_f1_u003b((&param_1));\n z = _e51;\n let _e52 = z;\n let _e53 = centre;\n let _e56 = tolerance;\n w = max(0f, (1f - (abs((_e52 - _e53)) / _e56)));\n let _e60 = uv;\n let _e61 = textureSampleLevel(uAo_t, uAo_s, _e60, 0f);\n let _e63 = w;\n let _e65 = sum;\n sum = (_e65 + (_e61.x * _e63));\n let _e67 = w;\n let _e68 = weight;\n weight = (_e68 + _e67);\n continue;\n } else {\n break;\n }\n continuing {\n let _e70 = i;\n i = (_e70 + 1i);\n }\n }\n let _e72 = weight;\n if (_e72 > 0f) {\n let _e74 = sum;\n let _e75 = weight;\n local = (_e74 / _e75);\n } else {\n let _e77 = vUv_1;\n let _e78 = textureSampleLevel(uAo_t, uAo_s, _e77, 0f);\n local = _e78.x;\n }\n let _e80 = local;\n fragColor = _e80;\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
2
- export declare const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp((_e430 / 2f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
1
+ export declare const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n uAoScale: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var depth_1: f32;\n var own: f32;\n var centre: f32;\n var param: f32;\n var inverse: f32;\n var stepAfter: f32;\n var param_1: f32;\n var stepBefore: f32;\n var param_2: f32;\n var slope: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_3: f32;\n var w: f32;\n var blurred: f32;\n var local: f32;\n\n let _e39 = vUv_1;\n let _e40 = textureSampleLevel(uDepth_t, uDepth_s, _e39, 0f);\n depth_1 = _e40.x;\n let _e42 = vUv_1;\n let _e43 = textureSampleLevel(uAo_t, uAo_s, _e42, 0f);\n own = _e43.x;\n let _e45 = depth_1;\n if (_e45 <= 0f) {\n let _e47 = own;\n let _e49 = unnamed.uAoScale;\n fragColor = min((_e47 * _e49), 1f);\n return;\n }\n let _e52 = depth_1;\n param = _e52;\n let _e53 = viewZ_u0028_f1_u003b((&param));\n centre = _e53;\n let _e54 = centre;\n inverse = (1f / _e54);\n let _e56 = vUv_1;\n let _e58 = unnamed.uStep;\n let _e60 = textureSampleLevel(uDepth_t, uDepth_s, (_e56 + _e58), 0f);\n param_1 = _e60.x;\n let _e62 = viewZ_u0028_f1_u003b((&param_1));\n let _e64 = inverse;\n stepAfter = ((1f / _e62) - _e64);\n let _e66 = inverse;\n let _e67 = vUv_1;\n let _e69 = unnamed.uStep;\n let _e71 = textureSampleLevel(uDepth_t, uDepth_s, (_e67 - _e69), 0f);\n param_2 = _e71.x;\n let _e73 = viewZ_u0028_f1_u003b((&param_2));\n stepBefore = (_e66 - (1f / _e73));\n let _e76 = stepAfter;\n let _e78 = stepBefore;\n let _e81 = stepAfter;\n let _e82 = stepBefore;\n slope = select(_e82, _e81, (abs(_e76) < abs(_e78)));\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e84 = i;\n if (_e84 <= 4i) {\n let _e86 = vUv_1;\n let _e88 = unnamed.uStep;\n let _e89 = i;\n uv = (_e86 + (_e88 * f32(_e89)));\n let _e93 = uv;\n let _e94 = textureSampleLevel(uDepth_t, uDepth_s, _e93, 0f);\n param_3 = _e94.x;\n let _e96 = viewZ_u0028_f1_u003b((&param_3));\n z = _e96;\n let _e97 = z;\n let _e98 = inverse;\n let _e99 = slope;\n let _e100 = i;\n w = max(0f, (1f - (abs(((_e97 * (_e98 + (_e99 * f32(_e100)))) - 1f)) / 0.02f)));\n let _e110 = uv;\n let _e111 = textureSampleLevel(uAo_t, uAo_s, _e110, 0f);\n let _e113 = w;\n let _e115 = sum;\n sum = (_e115 + (_e111.x * _e113));\n let _e117 = w;\n let _e118 = weight;\n weight = (_e118 + _e117);\n continue;\n } else {\n break;\n }\n continuing {\n let _e120 = i;\n i = (_e120 + 1i);\n }\n }\n let _e122 = weight;\n if (_e122 > 0f) {\n let _e124 = sum;\n let _e125 = weight;\n local = (_e124 / _e125);\n } else {\n let _e127 = own;\n local = _e127;\n }\n let _e128 = local;\n blurred = _e128;\n let _e129 = blurred;\n let _e131 = unnamed.uAoScale;\n fragColor = min((_e129 * _e131), 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
2
+ export declare const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp(((_e430 / 2f) * 0.5f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
3
3
  /**
4
4
  * What the transform assigned, so the renderer binds the same numbers.
5
5
  *
@@ -8,7 +8,7 @@ export declare const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32
8
8
  export declare const AMBIENTOCCLUSION_BINDINGS: {
9
9
  readonly AO_BLUR_FRAG: {
10
10
  readonly uniforms: 1;
11
- readonly uniformSize: 32;
11
+ readonly uniformSize: 48;
12
12
  readonly fields: {
13
13
  readonly uStep: {
14
14
  readonly offset: 0;
@@ -20,6 +20,11 @@ export declare const AMBIENTOCCLUSION_BINDINGS: {
20
20
  readonly size: 16;
21
21
  readonly type: "vec4";
22
22
  };
23
+ readonly uAoScale: {
24
+ readonly offset: 32;
25
+ readonly size: 4;
26
+ readonly type: "float";
27
+ };
23
28
  };
24
29
  readonly textures: {
25
30
  readonly uAo: {
@@ -4,8 +4,8 @@
4
4
  * The GLSL beside this file is the source of truth. A hand edit here is discarded by
5
5
  * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
6
  */
7
- export const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var centre: f32;\n var param: f32;\n var tolerance: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_1: f32;\n var w: f32;\n var local: f32;\n\n let _e31 = vUv_1;\n let _e32 = textureSampleLevel(uDepth_t, uDepth_s, _e31, 0f);\n param = _e32.x;\n let _e34 = viewZ_u0028_f1_u003b((&param));\n centre = _e34;\n let _e35 = centre;\n tolerance = ((0.02f * abs(_e35)) + 0.0001f);\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e39 = i;\n if (_e39 <= 4i) {\n let _e41 = vUv_1;\n let _e43 = unnamed.uStep;\n let _e44 = i;\n uv = (_e41 + (_e43 * f32(_e44)));\n let _e48 = uv;\n let _e49 = textureSampleLevel(uDepth_t, uDepth_s, _e48, 0f);\n param_1 = _e49.x;\n let _e51 = viewZ_u0028_f1_u003b((&param_1));\n z = _e51;\n let _e52 = z;\n let _e53 = centre;\n let _e56 = tolerance;\n w = max(0f, (1f - (abs((_e52 - _e53)) / _e56)));\n let _e60 = uv;\n let _e61 = textureSampleLevel(uAo_t, uAo_s, _e60, 0f);\n let _e63 = w;\n let _e65 = sum;\n sum = (_e65 + (_e61.x * _e63));\n let _e67 = w;\n let _e68 = weight;\n weight = (_e68 + _e67);\n continue;\n } else {\n break;\n }\n continuing {\n let _e70 = i;\n i = (_e70 + 1i);\n }\n }\n let _e72 = weight;\n if (_e72 > 0f) {\n let _e74 = sum;\n let _e75 = weight;\n local = (_e74 / _e75);\n } else {\n let _e77 = vUv_1;\n let _e78 = textureSampleLevel(uAo_t, uAo_s, _e77, 0f);\n local = _e78.x;\n }\n let _e80 = local;\n fragColor = _e80;\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
8
- export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp((_e430 / 2f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
7
+ export const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n uAoScale: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var depth_1: f32;\n var own: f32;\n var centre: f32;\n var param: f32;\n var inverse: f32;\n var stepAfter: f32;\n var param_1: f32;\n var stepBefore: f32;\n var param_2: f32;\n var slope: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_3: f32;\n var w: f32;\n var blurred: f32;\n var local: f32;\n\n let _e39 = vUv_1;\n let _e40 = textureSampleLevel(uDepth_t, uDepth_s, _e39, 0f);\n depth_1 = _e40.x;\n let _e42 = vUv_1;\n let _e43 = textureSampleLevel(uAo_t, uAo_s, _e42, 0f);\n own = _e43.x;\n let _e45 = depth_1;\n if (_e45 <= 0f) {\n let _e47 = own;\n let _e49 = unnamed.uAoScale;\n fragColor = min((_e47 * _e49), 1f);\n return;\n }\n let _e52 = depth_1;\n param = _e52;\n let _e53 = viewZ_u0028_f1_u003b((&param));\n centre = _e53;\n let _e54 = centre;\n inverse = (1f / _e54);\n let _e56 = vUv_1;\n let _e58 = unnamed.uStep;\n let _e60 = textureSampleLevel(uDepth_t, uDepth_s, (_e56 + _e58), 0f);\n param_1 = _e60.x;\n let _e62 = viewZ_u0028_f1_u003b((&param_1));\n let _e64 = inverse;\n stepAfter = ((1f / _e62) - _e64);\n let _e66 = inverse;\n let _e67 = vUv_1;\n let _e69 = unnamed.uStep;\n let _e71 = textureSampleLevel(uDepth_t, uDepth_s, (_e67 - _e69), 0f);\n param_2 = _e71.x;\n let _e73 = viewZ_u0028_f1_u003b((&param_2));\n stepBefore = (_e66 - (1f / _e73));\n let _e76 = stepAfter;\n let _e78 = stepBefore;\n let _e81 = stepAfter;\n let _e82 = stepBefore;\n slope = select(_e82, _e81, (abs(_e76) < abs(_e78)));\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e84 = i;\n if (_e84 <= 4i) {\n let _e86 = vUv_1;\n let _e88 = unnamed.uStep;\n let _e89 = i;\n uv = (_e86 + (_e88 * f32(_e89)));\n let _e93 = uv;\n let _e94 = textureSampleLevel(uDepth_t, uDepth_s, _e93, 0f);\n param_3 = _e94.x;\n let _e96 = viewZ_u0028_f1_u003b((&param_3));\n z = _e96;\n let _e97 = z;\n let _e98 = inverse;\n let _e99 = slope;\n let _e100 = i;\n w = max(0f, (1f - (abs(((_e97 * (_e98 + (_e99 * f32(_e100)))) - 1f)) / 0.02f)));\n let _e110 = uv;\n let _e111 = textureSampleLevel(uAo_t, uAo_s, _e110, 0f);\n let _e113 = w;\n let _e115 = sum;\n sum = (_e115 + (_e111.x * _e113));\n let _e117 = w;\n let _e118 = weight;\n weight = (_e118 + _e117);\n continue;\n } else {\n break;\n }\n continuing {\n let _e120 = i;\n i = (_e120 + 1i);\n }\n }\n let _e122 = weight;\n if (_e122 > 0f) {\n let _e124 = sum;\n let _e125 = weight;\n local = (_e124 / _e125);\n } else {\n let _e127 = own;\n local = _e127;\n }\n let _e128 = local;\n blurred = _e128;\n let _e129 = blurred;\n let _e131 = unnamed.uAoScale;\n fragColor = min((_e129 * _e131), 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
8
+ export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp(((_e430 / 2f) * 0.5f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
9
9
  /**
10
10
  * What the transform assigned, so the renderer binds the same numbers.
11
11
  *
@@ -14,7 +14,7 @@ export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n
14
14
  export const AMBIENTOCCLUSION_BINDINGS = {
15
15
  "AO_BLUR_FRAG": {
16
16
  "uniforms": 1,
17
- "uniformSize": 32,
17
+ "uniformSize": 48,
18
18
  "fields": {
19
19
  "uStep": {
20
20
  "offset": 0,
@@ -25,6 +25,11 @@ export const AMBIENTOCCLUSION_BINDINGS = {
25
25
  "offset": 16,
26
26
  "size": 16,
27
27
  "type": "vec4"
28
+ },
29
+ "uAoScale": {
30
+ "offset": 32,
31
+ "size": 4,
32
+ "type": "float"
28
33
  }
29
34
  },
30
35
  "textures": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftengine/core",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "DriftEngine reusable browser 3D runtime",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,8 +29,8 @@
29
29
  ],
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
- "@driftengine/drft": "4.4.0",
33
- "@driftengine/physics": "4.4.0",
32
+ "@driftengine/drft": "4.4.1",
33
+ "@driftengine/physics": "4.4.1",
34
34
  "gl-matrix": "^3.4.3"
35
35
  },
36
36
  "author": "Drift Technologies",
@@ -63,8 +63,8 @@
63
63
  "prepack": "node ../../scripts/build.mjs @driftengine/core"
64
64
  },
65
65
  "devDependencies": {
66
- "@driftengine/nav": "4.4.0",
67
- "@driftengine/network": "4.4.0",
68
- "@driftengine/texture": "4.4.0"
66
+ "@driftengine/nav": "4.4.1",
67
+ "@driftengine/network": "4.4.1",
68
+ "@driftengine/texture": "4.4.1"
69
69
  }
70
70
  }
@@ -1,4 +1,4 @@
1
- import { AO_BLUR_FRAG, AO_FRAG } from './shaders/ambientOcclusion.ts';
1
+ import { AO_BLUR_FRAG, AO_FRAG, AO_STORE } from './shaders/ambientOcclusion.ts';
2
2
  import { FULLSCREEN_VERT } from './shaders/fullscreen.ts';
3
3
  import { compileProgram, uniformLocations } from './shader.ts';
4
4
 
@@ -168,6 +168,8 @@ export class AmbientOcclusionPass {
168
168
  this.step[0] = 1 / width;
169
169
  this.step[1] = 0;
170
170
  gl.uniform2fv(this.blurUniforms['uStep'] ?? null, this.step);
171
+ /* Still at the estimate's scale, which the second axis needs whole. */
172
+ gl.uniform1f(this.blurUniforms['uAoScale'] ?? null, 1);
171
173
  gl.drawArrays(gl.TRIANGLES, 0, 3);
172
174
 
173
175
  /* And down, back into the estimate, which is the texture handed out. */
@@ -176,6 +178,8 @@ export class AmbientOcclusionPass {
176
178
  this.step[0] = 0;
177
179
  this.step[1] = 1 / height;
178
180
  gl.uniform2fv(this.blurUniforms['uStep'] ?? null, this.step);
181
+ /* And decoded, so the composite reads open sky as one. */
182
+ gl.uniform1f(this.blurUniforms['uAoScale'] ?? null, 1 / AO_STORE);
179
183
  gl.drawArrays(gl.TRIANGLES, 0, 3);
180
184
 
181
185
  gl.bindVertexArray(null);
@@ -181,6 +181,7 @@ import { reflectionTargetSize, type ReflectionSize } from '../../planarReflectio
181
181
  import { drawingBufferSize } from '../../drawingBuffer.ts';
182
182
  import { MOTION_BLUR_MAX_UV, OUTPUT_TRANSFORM_CODE, RUSH_REACH_UV } from '../../vertexDefaults.ts';
183
183
  import { ExposurePass } from './exposurePass.ts';
184
+ import { AO_STORE } from '../../shaders/ambientOcclusion.ts';
184
185
  import { clampAutoExposure } from '../../shaders/exposure.ts';
185
186
  import { clampLocalExposure } from '../../shaders/localExposure.ts';
186
187
  import type { UniformFields } from './scatterPass.ts';
@@ -11045,12 +11046,15 @@ export class WebGPURenderer implements RendererApi {
11045
11046
  otherwise halve the blur and leave half the pattern standing. */
11046
11047
  const width = Math.max(1, this.aoTarget?.width ?? 1);
11047
11048
  const height = Math.max(1, this.aoTarget?.height ?? 1);
11048
- for (const [index, step] of [
11049
- [0, [1 / width, 0]],
11050
- [1, [0, 1 / height]],
11049
+ /* Across at the estimate's own scale, which the second axis needs whole; down decoded, so the
11050
+ composite reads open sky as one. The same two `ambientOcclusionPass.ts` writes. */
11051
+ for (const [index, step, scale] of [
11052
+ [0, [1 / width, 0], 1],
11053
+ [1, [0, 1 / height], 1 / AO_STORE],
11051
11054
  ] as const) {
11052
11055
  f[slot(index) + at('uStep')] = step[0];
11053
11056
  f[slot(index) + at('uStep') + 1] = step[1];
11057
+ f[slot(index) + at('uAoScale')] = scale;
11054
11058
  f[slot(index) + at('uDepthToViewZ')] = inv[10] ?? 0;
11055
11059
  f[slot(index) + at('uDepthToViewZ') + 1] = inv[14] ?? 0;
11056
11060
  f[slot(index) + at('uDepthToViewZ') + 2] = inv[11] ?? 0;
@@ -86,7 +86,8 @@ export function planPointShadowBakes(
86
86
  }
87
87
 
88
88
  /**
89
- * The shaded lights that also cast, in the order they were shaded.
89
+ * The shaded lights that also cast, each at its own place in the shaded list, and −1 at the place
90
+ * of a light that does not.
90
91
  *
91
92
  * `castsShadow: false` says a light is not worth a cubemap. `selectPointLights` honours
92
93
  * that when it builds the *eligible* list, and that was taken for the whole promise — but
@@ -98,7 +99,16 @@ export function planPointShadowBakes(
98
99
  * It showed up as a shadow with nothing to throw it — a lamp that rides the camera
99
100
  * declines to cast for exactly that reason, and cast anyway.
100
101
  *
101
- * Writes into `out` and returns how many it wrote; allocation-free, because this runs
102
+ * **The place is kept rather than the gap closed, because the place is the shader's index.** The
103
+ * pool publishes each map under its light's position in this list, and the shader reads a light's
104
+ * shadow at the light's position in the shaded one. Closing the gap made the two numberings
105
+ * disagree after the first light that declined: every lamp shaded after it was published one
106
+ * place down, the first on the declining light and each of the rest on its neighbour. A consumer
107
+ * whose headlights decline, and are nearly always shaded first, could only keep its lamps honest by
108
+ * dropping the shadows of every lamp ranked after them, and which lamps those were changed as the
109
+ * car moved.
110
+ *
111
+ * Writes into `out` and returns how many places it wrote; allocation-free, because this runs
102
112
  * every frame.
103
113
  */
104
114
  export function selectCastingLights(
@@ -107,14 +117,12 @@ export function selectCastingLights(
107
117
  activeCount: number,
108
118
  out: Int32Array,
109
119
  ): number {
110
- let written = 0;
111
- for (let i = 0; i < activeCount && written < out.length; i++) {
120
+ const count = Math.min(activeCount, out.length);
121
+ for (let i = 0; i < count; i++) {
112
122
  const worldIndex = activeWorldIndices[i] ?? -1;
113
- if (worldIndex < 0) continue;
114
- if (lights[worldIndex]?.castsShadow === false) continue;
115
- out[written++] = worldIndex;
123
+ out[i] = worldIndex >= 0 && lights[worldIndex]?.castsShadow !== false ? worldIndex : -1;
116
124
  }
117
- return written;
125
+ return count;
118
126
  }
119
127
 
120
128
  /**
@@ -26,7 +26,8 @@ import { glslIsFarDepth, glslSceneDepthToNdc } from '../depthConvention.ts';
26
26
  */
27
27
 
28
28
  /**
29
- * The estimate. Writes one channel: 1 is open sky, 0 is fully enclosed.
29
+ * The estimate. Writes one channel at `AO_STORE`: that is open sky, 0 is fully enclosed, and the
30
+ * second axis of the blur decodes it.
30
31
  *
31
32
  * **Horizons, not neighbours: ground-truth ambient occlusion (Jimenez et al. 2016).** Each pixel
32
33
  * walks two lines across the screen, both ways, and keeps the highest thing it can see along each
@@ -118,6 +119,8 @@ const float AO_EDGE_RATIO = 8.0;
118
119
  * and far below the step at any edge worth shading — a kerb against a deck is metres of it.
119
120
  */
120
121
  const float AO_EDGE_FLOOR = 0.05;
122
+ /** Stored at half, so a turn the closed form credits past one reaches the blur whole. See AO_STORE in the module. */
123
+ const float AO_STORE = 0.5;
121
124
 
122
125
  /** View-space position of whatever is at this pixel, from its depth alone. */
123
126
  vec3 viewPosition(vec2 uv, float depth) {
@@ -305,7 +308,7 @@ void main() {
305
308
  visible += projectedLength * gtaoArc(h0, h1, normalAngle);
306
309
  }
307
310
 
308
- fragColor = clamp(visible / float(AO_SLICES), 0.0, 1.0);
311
+ fragColor = clamp(visible / float(AO_SLICES) * AO_STORE, 0.0, 1.0);
309
312
  }
310
313
  `;
311
314
 
@@ -335,12 +338,14 @@ uniform vec2 uStep;
335
338
  * asks that question five times per pixel.
336
339
  */
337
340
  uniform vec4 uDepthToViewZ;
341
+ /** One across, carrying the estimate's AO_STORE scale; its inverse down, decoding it. */
342
+ uniform float uAoScale;
338
343
 
339
344
  out float fragColor;
340
345
 
341
346
  /**
342
- * How far apart two pixels may be, as a fraction of their distance from the eye, before they
343
- * stop being the same surface.
347
+ * How far a neighbour may sit from the depth this pixel's own surface predicts there, as a
348
+ * fraction of that depth, before it stops being the same surface.
344
349
  *
345
350
  * Relative rather than absolute, because the same 5 cm step is a cliff on a dashboard and
346
351
  * nothing at all on a far wall.
@@ -353,8 +358,19 @@ float viewZ(float depth) {
353
358
  }
354
359
 
355
360
  void main() {
356
- float centre = viewZ(textureLod(uDepth, vUv, 0.0).r);
357
- float tolerance = AO_BLUR_DEPTH_TOLERANCE * abs(centre) + 1e-4;
361
+ float depth = textureLod(uDepth, vUv, 0.0).r;
362
+ float own = textureLod(uAo, vUv, 0.0).r;
363
+ /* Nothing to average over the sky, and no surface to predict one from. */
364
+ if (${glslIsFarDepth('depth')}) {
365
+ fragColor = min(own * uAoScale, 1.0);
366
+ return;
367
+ }
368
+ float centre = viewZ(depth);
369
+ /* Each tap is compared with this pixel's plane, not with its depth. See blurWeight in the module. */
370
+ float inverse = 1.0 / centre;
371
+ float stepAfter = 1.0 / viewZ(textureLod(uDepth, vUv + uStep, 0.0).r) - inverse;
372
+ float stepBefore = inverse - 1.0 / viewZ(textureLod(uDepth, vUv - uStep, 0.0).r);
373
+ float slope = abs(stepAfter) < abs(stepBefore) ? stepAfter : stepBefore;
358
374
  float sum = 0.0;
359
375
  float weight = 0.0;
360
376
  /*
@@ -382,14 +398,15 @@ void main() {
382
398
  for (int i = -3; i <= 4; i++) {
383
399
  vec2 uv = vUv + uStep * float(i);
384
400
  float z = viewZ(textureLod(uDepth, uv, 0.0).r);
385
- /* One if this neighbour is on the same surface, falling to zero across an edge. */
386
- float w = max(0.0, 1.0 - abs(z - centre) / tolerance);
401
+ /* One if this neighbour is on this pixel's surface, falling to zero as it leaves it. */
402
+ float w = max(0.0, 1.0 - abs(z * (inverse + slope * float(i)) - 1.0) / AO_BLUR_DEPTH_TOLERANCE);
387
403
  sum += textureLod(uAo, uv, 0.0).r * w;
388
404
  weight += w;
389
405
  }
390
406
  /* An isolated pixel — a thin rail against a far wall — keeps its own estimate rather than
391
407
  dividing by nothing. */
392
- fragColor = weight > 0.0 ? sum / weight : textureLod(uAo, vUv, 0.0).r;
408
+ float blurred = weight > 0.0 ? sum / weight : own;
409
+ fragColor = min(blurred * uAoScale, 1.0);
393
410
  }
394
411
  `;
395
412
 
@@ -414,3 +431,58 @@ export function nextHorizon(horizon: number, cosine: number): number {
414
431
 
415
432
  /** The shader's thickness heuristic. See `AO_THIN` inside `AO_FRAG`. */
416
433
  export const AO_THIN = 0.2;
434
+
435
+ /**
436
+ * What the estimate is multiplied by before it is stored, and divided by once the blur is done.
437
+ *
438
+ * **Half, because an unblurred estimate is allowed past one.** A pixel's two lines see a plane
439
+ * turned away from the eye from two directions, and the closed form credits one of them more than
440
+ * the whole sky and the other less: it is the average over every turn that is exactly one, and the
441
+ * average is what the blur is for. Stored as it came, an eight-bit target clipped every turn above
442
+ * one before the blur could average it, and every surface seen edge on came back a few percent
443
+ * shaded with nothing on it. A line reaches π/2 at most, so half fits the whole range.
444
+ *
445
+ * What it gives up is one bit of the intermediate: steps of 1/128 rather than 1/256 until the
446
+ * second axis decodes, which the eight taps a pixel averages carry below what a frame can show.
447
+ */
448
+ export const AO_STORE = 0.5;
449
+
450
+ /** How far a neighbour may sit from this pixel's surface, as a fraction of its distance. */
451
+ export const AO_BLUR_DEPTH_TOLERANCE = 0.02;
452
+
453
+ /**
454
+ * The blur's weight for a neighbour `offset` pixels along the axis, from view depths: this pixel's
455
+ * own, the two either side of it, and the neighbour's. The shader's lines written out again.
456
+ *
457
+ * **The neighbour is compared with this pixel's plane, not with this pixel's depth.** Comparing
458
+ * depths refused every neighbour of a surface seen edge on: a floor forty metres out changes its
459
+ * depth by four percent a row, twice the tolerance, so the pass down the frame kept the centre alone
460
+ * and left the rotation tile's rows standing — four-pixel stripes across every ramp and far floor,
461
+ * reported as strips on a track. On a plane 1/z is affine in the screen, so one step of it predicts
462
+ * the plane's depth at every tap exactly, and a tap is refused only for leaving the plane.
463
+ *
464
+ * The step is taken from whichever neighbour is closer to the centre in 1/z. At a silhouette that is
465
+ * the one on this pixel's own side, so the far surface cannot bend the prediction toward it; on a
466
+ * plane the two agree to a quantisation step, which moves a weight by nothing a frame shows. What it
467
+ * gives up is a crease: past the fold between a floor and a wall the prediction runs on along the
468
+ * floor, so the wall's taps fade out over the tolerance rather than being kept.
469
+ *
470
+ * **Written here rather than in the shader**, because a comment inside the GLSL is part of the string
471
+ * a consumer ships.
472
+ */
473
+ export function blurWeight(
474
+ centre: number,
475
+ before: number,
476
+ after: number,
477
+ neighbour: number,
478
+ offset: number,
479
+ ): number {
480
+ const inverse = 1 / centre;
481
+ const stepAfter = 1 / after - inverse;
482
+ const stepBefore = inverse - 1 / before;
483
+ const slope = Math.abs(stepAfter) < Math.abs(stepBefore) ? stepAfter : stepBefore;
484
+ return Math.max(
485
+ 0,
486
+ 1 - Math.abs(neighbour * (inverse + slope * offset) - 1) / AO_BLUR_DEPTH_TOLERANCE,
487
+ );
488
+ }
@@ -5,9 +5,9 @@
5
5
  * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
6
  */
7
7
 
8
- export const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var centre: f32;\n var param: f32;\n var tolerance: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_1: f32;\n var w: f32;\n var local: f32;\n\n let _e31 = vUv_1;\n let _e32 = textureSampleLevel(uDepth_t, uDepth_s, _e31, 0f);\n param = _e32.x;\n let _e34 = viewZ_u0028_f1_u003b((&param));\n centre = _e34;\n let _e35 = centre;\n tolerance = ((0.02f * abs(_e35)) + 0.0001f);\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e39 = i;\n if (_e39 <= 4i) {\n let _e41 = vUv_1;\n let _e43 = unnamed.uStep;\n let _e44 = i;\n uv = (_e41 + (_e43 * f32(_e44)));\n let _e48 = uv;\n let _e49 = textureSampleLevel(uDepth_t, uDepth_s, _e48, 0f);\n param_1 = _e49.x;\n let _e51 = viewZ_u0028_f1_u003b((&param_1));\n z = _e51;\n let _e52 = z;\n let _e53 = centre;\n let _e56 = tolerance;\n w = max(0f, (1f - (abs((_e52 - _e53)) / _e56)));\n let _e60 = uv;\n let _e61 = textureSampleLevel(uAo_t, uAo_s, _e60, 0f);\n let _e63 = w;\n let _e65 = sum;\n sum = (_e65 + (_e61.x * _e63));\n let _e67 = w;\n let _e68 = weight;\n weight = (_e68 + _e67);\n continue;\n } else {\n break;\n }\n continuing {\n let _e70 = i;\n i = (_e70 + 1i);\n }\n }\n let _e72 = weight;\n if (_e72 > 0f) {\n let _e74 = sum;\n let _e75 = weight;\n local = (_e74 / _e75);\n } else {\n let _e77 = vUv_1;\n let _e78 = textureSampleLevel(uAo_t, uAo_s, _e77, 0f);\n local = _e78.x;\n }\n let _e80 = local;\n fragColor = _e80;\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
8
+ export const AO_BLUR_FRAG_WGSL = "struct Uniforms {\n uStep: vec2<f32>,\n uDepthToViewZ: vec4<f32>,\n uAoScale: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uAo_s: sampler;\nvar<private> fragColor: f32;\n\nfn viewZ_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var ndc: f32;\n\n let _e22 = (*depth);\n ndc = (1f - (_e22 * 2f));\n let _e27 = unnamed.uDepthToViewZ[0u];\n let _e28 = ndc;\n let _e32 = unnamed.uDepthToViewZ[1u];\n let _e36 = unnamed.uDepthToViewZ[2u];\n let _e37 = ndc;\n let _e41 = unnamed.uDepthToViewZ[3u];\n return (((_e27 * _e28) + _e32) / ((_e36 * _e37) + _e41));\n}\n\nfn main_1() {\n var depth_1: f32;\n var own: f32;\n var centre: f32;\n var param: f32;\n var inverse: f32;\n var stepAfter: f32;\n var param_1: f32;\n var stepBefore: f32;\n var param_2: f32;\n var slope: f32;\n var sum: f32;\n var weight: f32;\n var i: i32;\n var uv: vec2<f32>;\n var z: f32;\n var param_3: f32;\n var w: f32;\n var blurred: f32;\n var local: f32;\n\n let _e39 = vUv_1;\n let _e40 = textureSampleLevel(uDepth_t, uDepth_s, _e39, 0f);\n depth_1 = _e40.x;\n let _e42 = vUv_1;\n let _e43 = textureSampleLevel(uAo_t, uAo_s, _e42, 0f);\n own = _e43.x;\n let _e45 = depth_1;\n if (_e45 <= 0f) {\n let _e47 = own;\n let _e49 = unnamed.uAoScale;\n fragColor = min((_e47 * _e49), 1f);\n return;\n }\n let _e52 = depth_1;\n param = _e52;\n let _e53 = viewZ_u0028_f1_u003b((&param));\n centre = _e53;\n let _e54 = centre;\n inverse = (1f / _e54);\n let _e56 = vUv_1;\n let _e58 = unnamed.uStep;\n let _e60 = textureSampleLevel(uDepth_t, uDepth_s, (_e56 + _e58), 0f);\n param_1 = _e60.x;\n let _e62 = viewZ_u0028_f1_u003b((&param_1));\n let _e64 = inverse;\n stepAfter = ((1f / _e62) - _e64);\n let _e66 = inverse;\n let _e67 = vUv_1;\n let _e69 = unnamed.uStep;\n let _e71 = textureSampleLevel(uDepth_t, uDepth_s, (_e67 - _e69), 0f);\n param_2 = _e71.x;\n let _e73 = viewZ_u0028_f1_u003b((&param_2));\n stepBefore = (_e66 - (1f / _e73));\n let _e76 = stepAfter;\n let _e78 = stepBefore;\n let _e81 = stepAfter;\n let _e82 = stepBefore;\n slope = select(_e82, _e81, (abs(_e76) < abs(_e78)));\n sum = 0f;\n weight = 0f;\n i = -3i;\n loop {\n let _e84 = i;\n if (_e84 <= 4i) {\n let _e86 = vUv_1;\n let _e88 = unnamed.uStep;\n let _e89 = i;\n uv = (_e86 + (_e88 * f32(_e89)));\n let _e93 = uv;\n let _e94 = textureSampleLevel(uDepth_t, uDepth_s, _e93, 0f);\n param_3 = _e94.x;\n let _e96 = viewZ_u0028_f1_u003b((&param_3));\n z = _e96;\n let _e97 = z;\n let _e98 = inverse;\n let _e99 = slope;\n let _e100 = i;\n w = max(0f, (1f - (abs(((_e97 * (_e98 + (_e99 * f32(_e100)))) - 1f)) / 0.02f)));\n let _e110 = uv;\n let _e111 = textureSampleLevel(uAo_t, uAo_s, _e110, 0f);\n let _e113 = w;\n let _e115 = sum;\n sum = (_e115 + (_e111.x * _e113));\n let _e117 = w;\n let _e118 = weight;\n weight = (_e118 + _e117);\n continue;\n } else {\n break;\n }\n continuing {\n let _e120 = i;\n i = (_e120 + 1i);\n }\n }\n let _e122 = weight;\n if (_e122 > 0f) {\n let _e124 = sum;\n let _e125 = weight;\n local = (_e124 / _e125);\n } else {\n let _e127 = own;\n local = _e127;\n }\n let _e128 = local;\n blurred = _e128;\n let _e129 = blurred;\n let _e131 = unnamed.uAoScale;\n fragColor = min((_e129 * _e131), 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
9
9
 
10
- export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp((_e430 / 2f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
10
+ export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n uInvProjection: mat4x4<f32>,\n uRadius: f32,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uDepth_s: sampler;\nvar<private> fragColor: f32;\nvar<private> gl_FragCoord_1: vec4<f32>;\n\nfn gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b(h0_: ptr<function, f32>, h1_: ptr<function, f32>, normal: ptr<function, f32>) -> f32 {\n var c: f32;\n var s2_: f32;\n\n let _e40 = (*normal);\n c = cos(_e40);\n let _e42 = (*normal);\n s2_ = (2f * sin(_e42));\n let _e45 = (*h0_);\n let _e47 = (*normal);\n let _e51 = c;\n let _e53 = (*h0_);\n let _e54 = s2_;\n let _e58 = (*h1_);\n let _e60 = (*normal);\n let _e64 = c;\n let _e66 = (*h1_);\n let _e67 = s2_;\n return ((0.25f * ((-(cos(((2f * _e45) - _e47))) + _e51) + (_e53 * _e54))) + (0.25f * ((-(cos(((2f * _e58) - _e60))) + _e64) + (_e66 * _e67))));\n}\n\nfn viewPosition_u0028_vf2_u003b_f1_u003b(uv: ptr<function, vec2<f32>>, depth: ptr<function, f32>) -> vec3<f32> {\n var clip: vec4<f32>;\n var view: vec4<f32>;\n\n let _e39 = (*uv);\n let _e42 = ((_e39 * 2f) - vec2(1f));\n let _e43 = (*depth);\n clip = vec4<f32>(_e42.x, _e42.y, (1f - (_e43 * 2f)), 1f);\n let _e50 = unnamed.uInvProjection;\n let _e51 = clip;\n view = (_e50 * _e51);\n let _e53 = view;\n let _e56 = view[3u];\n return (_e53.xyz / vec3(_e56));\n}\n\nfn main_1() {\n var stepX: vec2<f32>;\n var stepY: vec2<f32>;\n var depth_1: f32;\n var p: vec3<f32>;\n var param: vec2<f32>;\n var param_1: f32;\n var dpdx_: vec3<f32>;\n var dpdy_: vec3<f32>;\n var right: vec3<f32>;\n var param_2: vec2<f32>;\n var param_3: f32;\n var left: vec3<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var down: vec3<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var up: vec3<f32>;\n var param_8: vec2<f32>;\n var param_9: f32;\n var here: f32;\n var edgeFloor: f32;\n var rightGap: f32;\n var leftGap: f32;\n var downGap: f32;\n var upGap: f32;\n var n: vec3<f32>;\n var toEye: vec3<f32>;\n var reach: vec2<f32>;\n var tile: f32;\n var turn: f32;\n var stagger: f32;\n var pixel: vec2<f32>;\n var visible: f32;\n var slice: i32;\n var angle: f32;\n var screen: vec2<f32>;\n var along: vec3<f32>;\n var param_10: vec2<f32>;\n var param_11: f32;\n var across: vec3<f32>;\n var axis: vec3<f32>;\n var projected: vec3<f32>;\n var projectedLength: f32;\n var normalAngle: f32;\n var horizon0_: f32;\n var horizon1_: f32;\n var k: i32;\n var t: f32;\n var stride: vec2<f32>;\n var side: i32;\n var uv_1: vec2<f32>;\n var local: vec2<f32>;\n var sampled: f32;\n var v: vec3<f32>;\n var param_12: vec2<f32>;\n var param_13: f32;\n var distance2_: f32;\n var cosine: f32;\n var fade: f32;\n var local_1: f32;\n var local_2: f32;\n var h0_1: f32;\n var h1_1: f32;\n var param_14: f32;\n var param_15: f32;\n var param_16: f32;\n\n let _e102 = vUv_1;\n let _e103 = dpdx(_e102);\n stepX = _e103;\n let _e104 = vUv_1;\n let _e105 = dpdy(_e104);\n stepY = _e105;\n let _e106 = vUv_1;\n let _e107 = textureSampleLevel(uDepth_t, uDepth_s, _e106, 0f);\n depth_1 = _e107.x;\n let _e109 = vUv_1;\n param = _e109;\n let _e110 = depth_1;\n param_1 = _e110;\n let _e111 = viewPosition_u0028_vf2_u003b_f1_u003b((&param), (&param_1));\n p = _e111;\n let _e112 = p;\n let _e113 = dpdx(_e112);\n dpdx_ = _e113;\n let _e114 = p;\n let _e115 = dpdy(_e114);\n dpdy_ = _e115;\n let _e116 = depth_1;\n if (_e116 <= 0f) {\n fragColor = 1f;\n return;\n }\n let _e118 = vUv_1;\n let _e119 = stepX;\n let _e121 = vUv_1;\n let _e122 = stepX;\n let _e124 = textureSampleLevel(uDepth_t, uDepth_s, (_e121 + _e122), 0f);\n param_2 = (_e118 + _e119);\n param_3 = _e124.x;\n let _e126 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_2), (&param_3));\n right = _e126;\n let _e127 = vUv_1;\n let _e128 = stepX;\n let _e130 = vUv_1;\n let _e131 = stepX;\n let _e133 = textureSampleLevel(uDepth_t, uDepth_s, (_e130 - _e131), 0f);\n param_4 = (_e127 - _e128);\n param_5 = _e133.x;\n let _e135 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n left = _e135;\n let _e136 = vUv_1;\n let _e137 = stepY;\n let _e139 = vUv_1;\n let _e140 = stepY;\n let _e142 = textureSampleLevel(uDepth_t, uDepth_s, (_e139 + _e140), 0f);\n param_6 = (_e136 + _e137);\n param_7 = _e142.x;\n let _e144 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n down = _e144;\n let _e145 = vUv_1;\n let _e146 = stepY;\n let _e148 = vUv_1;\n let _e149 = stepY;\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, (_e148 - _e149), 0f);\n param_8 = (_e145 - _e146);\n param_9 = _e151.x;\n let _e153 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n up = _e153;\n let _e155 = p[2u];\n here = -(_e155);\n let _e157 = here;\n edgeFloor = (0.05f * _e157);\n let _e160 = right[2u];\n let _e162 = here;\n rightGap = abs((-(_e160) - _e162));\n let _e166 = left[2u];\n let _e168 = here;\n leftGap = abs((-(_e166) - _e168));\n let _e172 = down[2u];\n let _e174 = here;\n downGap = abs((-(_e172) - _e174));\n let _e178 = up[2u];\n let _e180 = here;\n upGap = abs((-(_e178) - _e180));\n let _e183 = rightGap;\n let _e184 = leftGap;\n let _e186 = edgeFloor;\n if (_e183 > ((_e184 * 8f) + _e186)) {\n let _e189 = p;\n let _e190 = left;\n dpdx_ = (_e189 - _e190);\n } else {\n let _e192 = leftGap;\n let _e193 = rightGap;\n let _e195 = edgeFloor;\n if (_e192 > ((_e193 * 8f) + _e195)) {\n let _e198 = right;\n let _e199 = p;\n dpdx_ = (_e198 - _e199);\n }\n }\n let _e201 = downGap;\n let _e202 = upGap;\n let _e204 = edgeFloor;\n if (_e201 > ((_e202 * 8f) + _e204)) {\n let _e207 = p;\n let _e208 = up;\n dpdy_ = (_e207 - _e208);\n } else {\n let _e210 = upGap;\n let _e211 = downGap;\n let _e213 = edgeFloor;\n if (_e210 > ((_e211 * 8f) + _e213)) {\n let _e216 = down;\n let _e217 = p;\n dpdy_ = (_e216 - _e217);\n }\n }\n let _e219 = dpdx_;\n let _e220 = dpdy_;\n n = normalize(cross(_e219, _e220));\n let _e223 = n;\n let _e224 = p;\n if (dot(_e223, _e224) > 0f) {\n let _e227 = n;\n n = -(_e227);\n }\n let _e229 = p;\n toEye = normalize(-(_e229));\n let _e233 = unnamed.uRadius;\n let _e235 = unnamed.uProjScale;\n let _e239 = p[2u];\n reach = min((((_e235 * _e233) * 0.5f) / vec2(max(-(_e239), 0.001f))), vec2<f32>(0.06f, 0.06f));\n let _e246 = gl_FragCoord_1[0u];\n let _e252 = gl_FragCoord_1[1u];\n tile = ((_e246 - (floor((_e246 / 4f)) * 4f)) + (4f * (_e252 - (floor((_e252 / 4f)) * 4f))));\n let _e259 = tile;\n turn = (_e259 * 0.098174766f);\n let _e261 = tile;\n stagger = fract((_e261 * 0.618034f));\n let _e264 = stepX;\n let _e266 = stepY;\n pixel = vec2<f32>(length(_e264), length(_e266));\n visible = 0f;\n slice = 0i;\n loop {\n let _e269 = slice;\n if (_e269 < 2i) {\n let _e271 = turn;\n let _e272 = slice;\n angle = (_e271 + (f32(_e272) * 1.5707964f));\n let _e276 = angle;\n let _e279 = pixel[0u];\n let _e282 = pixel[1u];\n let _e284 = angle;\n screen = vec2<f32>(((cos(_e276) * _e279) / _e282), sin(_e284));\n let _e287 = vUv_1;\n let _e288 = screen;\n param_10 = (_e287 + (_e288 * 0.001f));\n let _e291 = depth_1;\n param_11 = _e291;\n let _e292 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_10), (&param_11));\n let _e293 = p;\n along = normalize((_e292 - _e293));\n let _e296 = along;\n let _e297 = toEye;\n let _e298 = along;\n let _e299 = toEye;\n across = normalize((_e296 - (_e297 * dot(_e298, _e299))));\n let _e304 = across;\n let _e305 = toEye;\n axis = cross(_e304, _e305);\n let _e307 = n;\n let _e308 = axis;\n let _e309 = n;\n let _e310 = axis;\n projected = (_e307 - (_e308 * dot(_e309, _e310)));\n let _e314 = projected;\n projectedLength = length(_e314);\n let _e316 = projectedLength;\n if (_e316 < 0.0001f) {\n continue;\n }\n let _e318 = projected;\n let _e319 = across;\n let _e321 = projected;\n let _e322 = toEye;\n normalAngle = atan2(dot(_e318, _e319), dot(_e321, _e322));\n horizon0_ = -1f;\n horizon1_ = -1f;\n k = 0i;\n loop {\n let _e325 = k;\n if (_e325 < 6i) {\n let _e327 = k;\n let _e329 = stagger;\n t = ((f32(_e327) + _e329) / 6f);\n let _e332 = screen;\n let _e334 = reach[1u];\n let _e336 = t;\n let _e337 = t;\n stride = ((_e332 * _e334) * ((_e336 * _e337) + 0.013888889f));\n side = 0i;\n loop {\n let _e341 = side;\n if (_e341 < 2i) {\n let _e343 = side;\n if (_e343 == 0i) {\n let _e345 = vUv_1;\n let _e346 = stride;\n local = (_e345 - _e346);\n } else {\n let _e348 = vUv_1;\n let _e349 = stride;\n local = (_e348 + _e349);\n }\n let _e351 = local;\n uv_1 = _e351;\n let _e352 = uv_1;\n let _e353 = textureSampleLevel(uDepth_t, uDepth_s, _e352, 0f);\n sampled = _e353.x;\n let _e355 = sampled;\n if (_e355 <= 0f) {\n continue;\n }\n let _e357 = uv_1;\n param_12 = _e357;\n let _e358 = sampled;\n param_13 = _e358;\n let _e359 = viewPosition_u0028_vf2_u003b_f1_u003b((&param_12), (&param_13));\n let _e360 = p;\n v = (_e359 - _e360);\n let _e362 = v;\n let _e363 = v;\n distance2_ = dot(_e362, _e363);\n let _e365 = distance2_;\n if (_e365 < 0.00000001f) {\n continue;\n }\n let _e367 = v;\n let _e368 = toEye;\n let _e370 = distance2_;\n cosine = (dot(_e367, _e368) * inverseSqrt(_e370));\n let _e373 = distance2_;\n let _e375 = unnamed.uRadius;\n let _e377 = unnamed.uRadius;\n fade = clamp((1f - (_e373 / (_e375 * _e377))), 0f, 1f);\n let _e382 = cosine;\n let _e383 = fade;\n cosine = mix(-1f, _e382, _e383);\n let _e385 = side;\n if (_e385 == 0i) {\n let _e387 = cosine;\n let _e388 = horizon0_;\n if (_e387 > _e388) {\n let _e390 = cosine;\n local_1 = _e390;\n } else {\n let _e391 = horizon0_;\n let _e392 = cosine;\n local_1 = mix(_e391, _e392, 0.2f);\n }\n let _e394 = local_1;\n horizon0_ = _e394;\n } else {\n let _e395 = cosine;\n let _e396 = horizon1_;\n if (_e395 > _e396) {\n let _e398 = cosine;\n local_2 = _e398;\n } else {\n let _e399 = horizon1_;\n let _e400 = cosine;\n local_2 = mix(_e399, _e400, 0.2f);\n }\n let _e402 = local_2;\n horizon1_ = _e402;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e403 = side;\n side = (_e403 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e405 = k;\n k = (_e405 + 1i);\n }\n }\n let _e407 = horizon0_;\n let _e411 = normalAngle;\n h0_1 = max(-(acos(clamp(_e407, -1f, 1f))), (_e411 - 1.5707963f));\n let _e414 = horizon1_;\n let _e417 = normalAngle;\n h1_1 = min(acos(clamp(_e414, -1f, 1f)), (_e417 + 1.5707963f));\n let _e420 = projectedLength;\n let _e421 = h0_1;\n param_14 = _e421;\n let _e422 = h1_1;\n param_15 = _e422;\n let _e423 = normalAngle;\n param_16 = _e423;\n let _e424 = gtaoArc_u0028_f1_u003b_f1_u003b_f1_u003b((&param_14), (&param_15), (&param_16));\n let _e426 = visible;\n visible = (_e426 + (_e420 * _e424));\n continue;\n } else {\n break;\n }\n continuing {\n let _e428 = slice;\n slice = (_e428 + 1i);\n }\n }\n let _e430 = visible;\n fragColor = clamp(((_e430 / 2f) * 0.5f), 0f, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) f32 {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
11
11
 
12
12
  /**
13
13
  * What the transform assigned, so the renderer binds the same numbers.
@@ -17,7 +17,7 @@ export const AO_FRAG_WGSL = "struct Uniforms {\n uProjScale: vec2<f32>,\n
17
17
  export const AMBIENTOCCLUSION_BINDINGS = {
18
18
  "AO_BLUR_FRAG": {
19
19
  "uniforms": 1,
20
- "uniformSize": 32,
20
+ "uniformSize": 48,
21
21
  "fields": {
22
22
  "uStep": {
23
23
  "offset": 0,
@@ -28,6 +28,11 @@ export const AMBIENTOCCLUSION_BINDINGS = {
28
28
  "offset": 16,
29
29
  "size": 16,
30
30
  "type": "vec4"
31
+ },
32
+ "uAoScale": {
33
+ "offset": 32,
34
+ "size": 4,
35
+ "type": "float"
31
36
  }
32
37
  },
33
38
  "textures": {
@@ -1,31 +0,0 @@
1
- /**
2
- * AgX: a tone curve whose shade stays open, for scenes lit mostly by bounce.
3
- *
4
- * **What ACES does to a courtyard.** The reference RRT and ODT are graded for a dark cinema, and
5
- * their toe is steep: a surface at 1% of white leaves the curve at 4 of 255. A room lit by light
6
- * bounced off its own walls lives in exactly that range, so its arcades read black beside renders
7
- * of the same model, and the grime in its stone reads as ink. Measured on a bought courtyard: 39%
8
- * of the frame below 16 of 255, against about 5% in the model maker's own renders.
9
- *
10
- * **AgX encodes the scene logarithmically and draws one sigmoid through it**, Troy Sobotka's
11
- * construction as Blender, Filament and three.js ship it. The same 1% leaves at 18 of 255, middle
12
- * grey lands at half the display range, and a highlight desaturates toward white instead of
13
- * clipping to a hue. What it gives up is ACES's punch in the midtones: the same scene reads
14
- * flatter, which a grade adds back as a look where ACES bakes it into the conversion. What would
15
- * make it the wrong choice is a world graded against three.js's or Unreal's ACES, which is the
16
- * match `aces` exists for.
17
- *
18
- * The constants are the Filament and three.js ones: Rec. 2020 primaries, the inset and outset
19
- * matrices, an encoding from 2^-10 to 2^6.5 times middle grey, and the iolite polynomial fit of
20
- * the default contrast curve, whose mean squared error against Blender's is 3.7e-6.
21
- */
22
- /**
23
- * `agxFilmic(vec3)`: linear sRGB in, linear sRGB out, clamped to [0, 1]. Reads `uOutputExposure`,
24
- * which the including source declares.
25
- */
26
- export declare const AGX_GLSL = "\nvec3 agxContrast(vec3 x) {\n vec3 x2 = x * x;\n vec3 x4 = x2 * x2;\n return 15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232;\n}\n\nvec3 agxFilmic(vec3 x) {\n x *= uOutputExposure;\n // Columns, as GLSL reads them: linear sRGB to linear Rec. 2020, then the inset.\n const mat3 SRGB_TO_REC2020 = mat3(\n 0.6274, 0.0691, 0.0164,\n 0.3293, 0.9195, 0.0880,\n 0.0433, 0.0113, 0.8956\n );\n const mat3 AGX_INSET = mat3(\n 0.856627153315983, 0.137318972929847, 0.11189821299995,\n 0.0951212405381588, 0.761241990602591, 0.0767994186031903,\n 0.0482516061458583, 0.101439036467562, 0.811302368396859\n );\n const mat3 AGX_OUTSET = mat3(\n 1.1271005818144368, -0.1413297634984383, -0.14132976349843826,\n -0.11060664309660323, 1.157823702216272, -0.11060664309660294,\n -0.016493938717834573, -0.016493938717834257, 1.2519364065950405\n );\n const mat3 REC2020_TO_SRGB = mat3(\n 1.6605, -0.1246, -0.0182,\n -0.5876, 1.1329, -0.1006,\n -0.0728, -0.0083, 1.1187\n );\n vec3 c = AGX_INSET * (SRGB_TO_REC2020 * x);\n /* log2 of middle grey times 2^-10 and 2^6.5: -12.47393 and 4.026069, 16.5 stops apart. */\n c = clamp((log2(max(c, vec3(1e-10))) + 12.47393) / 16.5, 0.0, 1.0);\n c = AGX_OUTSET * agxContrast(c);\n c = pow(max(c, vec3(0.0)), vec3(2.2));\n return clamp(REC2020_TO_SRGB * c, 0.0, 1.0);\n}\n";
27
- /**
28
- * The curve for a neutral grey, as the shader computes it: every matrix above keeps grey grey, so
29
- * one channel is the whole of it. For a test to pin to hand-derived values.
30
- */
31
- export declare function agxGrey(linear: number, exposure?: number): number;
@@ -1,81 +0,0 @@
1
- /**
2
- * AgX: a tone curve whose shade stays open, for scenes lit mostly by bounce.
3
- *
4
- * **What ACES does to a courtyard.** The reference RRT and ODT are graded for a dark cinema, and
5
- * their toe is steep: a surface at 1% of white leaves the curve at 4 of 255. A room lit by light
6
- * bounced off its own walls lives in exactly that range, so its arcades read black beside renders
7
- * of the same model, and the grime in its stone reads as ink. Measured on a bought courtyard: 39%
8
- * of the frame below 16 of 255, against about 5% in the model maker's own renders.
9
- *
10
- * **AgX encodes the scene logarithmically and draws one sigmoid through it**, Troy Sobotka's
11
- * construction as Blender, Filament and three.js ship it. The same 1% leaves at 18 of 255, middle
12
- * grey lands at half the display range, and a highlight desaturates toward white instead of
13
- * clipping to a hue. What it gives up is ACES's punch in the midtones: the same scene reads
14
- * flatter, which a grade adds back as a look where ACES bakes it into the conversion. What would
15
- * make it the wrong choice is a world graded against three.js's or Unreal's ACES, which is the
16
- * match `aces` exists for.
17
- *
18
- * The constants are the Filament and three.js ones: Rec. 2020 primaries, the inset and outset
19
- * matrices, an encoding from 2^-10 to 2^6.5 times middle grey, and the iolite polynomial fit of
20
- * the default contrast curve, whose mean squared error against Blender's is 3.7e-6.
21
- */
22
- /**
23
- * `agxFilmic(vec3)`: linear sRGB in, linear sRGB out, clamped to [0, 1]. Reads `uOutputExposure`,
24
- * which the including source declares.
25
- */
26
- export const AGX_GLSL = `
27
- vec3 agxContrast(vec3 x) {
28
- vec3 x2 = x * x;
29
- vec3 x4 = x2 * x2;
30
- return 15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232;
31
- }
32
-
33
- vec3 agxFilmic(vec3 x) {
34
- x *= uOutputExposure;
35
- // Columns, as GLSL reads them: linear sRGB to linear Rec. 2020, then the inset.
36
- const mat3 SRGB_TO_REC2020 = mat3(
37
- 0.6274, 0.0691, 0.0164,
38
- 0.3293, 0.9195, 0.0880,
39
- 0.0433, 0.0113, 0.8956
40
- );
41
- const mat3 AGX_INSET = mat3(
42
- 0.856627153315983, 0.137318972929847, 0.11189821299995,
43
- 0.0951212405381588, 0.761241990602591, 0.0767994186031903,
44
- 0.0482516061458583, 0.101439036467562, 0.811302368396859
45
- );
46
- const mat3 AGX_OUTSET = mat3(
47
- 1.1271005818144368, -0.1413297634984383, -0.14132976349843826,
48
- -0.11060664309660323, 1.157823702216272, -0.11060664309660294,
49
- -0.016493938717834573, -0.016493938717834257, 1.2519364065950405
50
- );
51
- const mat3 REC2020_TO_SRGB = mat3(
52
- 1.6605, -0.1246, -0.0182,
53
- -0.5876, 1.1329, -0.1006,
54
- -0.0728, -0.0083, 1.1187
55
- );
56
- vec3 c = AGX_INSET * (SRGB_TO_REC2020 * x);
57
- /* log2 of middle grey times 2^-10 and 2^6.5: -12.47393 and 4.026069, 16.5 stops apart. */
58
- c = clamp((log2(max(c, vec3(1e-10))) + 12.47393) / 16.5, 0.0, 1.0);
59
- c = AGX_OUTSET * agxContrast(c);
60
- c = pow(max(c, vec3(0.0)), vec3(2.2));
61
- return clamp(REC2020_TO_SRGB * c, 0.0, 1.0);
62
- }
63
- `;
64
- /**
65
- * The curve for a neutral grey, as the shader computes it: every matrix above keeps grey grey, so
66
- * one channel is the whole of it. For a test to pin to hand-derived values.
67
- */
68
- export function agxGrey(linear, exposure = 1) {
69
- const x = Math.max(linear * exposure, 1e-10);
70
- const t = Math.min(Math.max((Math.log2(x) + 12.47393) / 16.5, 0), 1);
71
- const t2 = t * t;
72
- const t4 = t2 * t2;
73
- const s = 15.5 * t4 * t2 -
74
- 40.14 * t4 * t +
75
- 31.96 * t4 -
76
- 6.868 * t2 * t +
77
- 0.4298 * t2 +
78
- 0.1191 * t -
79
- 0.00232;
80
- return Math.min(Math.max(Math.max(s, 0) ** 2.2, 0), 1);
81
- }