reze-engine 0.68.24 → 0.68.26
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/dist/engine.js +2 -2
- package/dist/shaders/passes/composite.js +3 -3
- package/dist/shaders/passes/particles.d.ts +7 -0
- package/dist/shaders/passes/particles.d.ts.map +1 -1
- package/dist/shaders/passes/particles.js +4 -2
- package/dist/shaders/passes/subsurface.d.ts +1 -1
- package/dist/shaders/passes/subsurface.d.ts.map +1 -1
- package/dist/shaders/passes/subsurface.js +19 -6
- package/package.json +1 -1
- package/src/engine.ts +2 -2
- package/src/shaders/passes/composite.ts +3 -3
- package/src/shaders/passes/particles.ts +11 -2
- package/src/shaders/passes/subsurface.ts +19 -6
package/dist/engine.js
CHANGED
|
@@ -37,7 +37,7 @@ import { LYRIC_ATLAS_MAX_H, LYRIC_ATLAS_MAX_W, LYRICS_FLOATS, packLyrics } from
|
|
|
37
37
|
import { sceneTargets as sceneTargetsFor, sceneColorFormats, setMrtIds, mrtIdsEnabled, SCENE_ID_FORMAT, } from "./shaders/passes/scene-contract";
|
|
38
38
|
import { LIGHT_GRID_BASE, LIGHT_HEADER, LIGHT_STRIDE, LIGHTS_FLOATS, MAX_LIGHTS, buildLightEmitShader, hasLightEmit, } from "./shaders/lights";
|
|
39
39
|
import { buildLightGrid } from "./light-grid";
|
|
40
|
-
import { groundShaderWgsl, GROUND_NOISE_BAKE_WGSL, GROUND_NOISE_SIZE } from "./shaders/passes/ground";
|
|
40
|
+
import { groundShaderWgsl, GROUND_NOISE_BAKE_WGSL, GROUND_NOISE_SIZE, GROUND_OBJECT_ID } from "./shaders/passes/ground";
|
|
41
41
|
import { outlineShaderWgsl, RZ_OUTLINE_COLOR_OFFSET, RZ_OUTLINE_DISSOLVE_OFFSET, RZ_OUTLINE_SHADOW_OFFSET, RZ_OUTLINE_TEXTURED_OFFSET, RZ_OUTLINE_WIDTH_OFFSET, } from "./shaders/passes/outline";
|
|
42
42
|
import { transparentDepthPrepassWgsl } from "./shaders/passes/depth-prepass";
|
|
43
43
|
import { SELECTION_MASK_SHADER_WGSL, SELECTION_EDGE_SHADER_WGSL } from "./shaders/passes/selection";
|
|
@@ -13368,7 +13368,7 @@ export class Engine {
|
|
|
13368
13368
|
// From a counter, never from the count: size + 1 handed a model added
|
|
13369
13369
|
// after a removal the id of one still in the scene, and two models with
|
|
13370
13370
|
// one id are one model to everything that reads the id buffer.
|
|
13371
|
-
objectId: (this.lastObjectId = this.lastObjectId >=
|
|
13371
|
+
objectId: (this.lastObjectId = this.lastObjectId >= GROUND_OBJECT_ID - 1 ? 1 : this.lastObjectId + 1),
|
|
13372
13372
|
dissolve: 1,
|
|
13373
13373
|
materialUniformBuffers: [],
|
|
13374
13374
|
outlineUniformBuffers: [],
|
|
@@ -122,7 +122,7 @@ override APPLY_GAMMA: bool = true;
|
|
|
122
122
|
// viewU[10] = (camera world position, _) — refreshed with the basis above.
|
|
123
123
|
// viewU[11..14] = the cast's positions (effects; count in viewU[10].w).
|
|
124
124
|
// viewU[15] = (soft curve contrast, pixel filter weights for offsets 0, ±1, ±2)
|
|
125
|
-
// — 1, 0, 0 is no filter; see
|
|
125
|
+
// — 1, 0, 0 is no filter; see _rzPixelFiltered.
|
|
126
126
|
// invGamma = 1/gamma precomputed on CPU — avoids a per-pixel divide.
|
|
127
127
|
@group(0) @binding(6) var bgEquirect: texture_2d<f32>;
|
|
128
128
|
// The scene pass's own MSAA depth buffer, bound depth-only. NOT an extra
|
|
@@ -182,7 +182,7 @@ fn rzFieldMerge(top: vec4f, bot: vec4f) -> vec4f {
|
|
|
182
182
|
* (Engine.setPixelFilter): separable weights viewU[15].yzw over offsets 0,
|
|
183
183
|
* ±1, ±2, the coverage filtered alongside so the sky still composites under
|
|
184
184
|
* it. Only called while a filter is on. */
|
|
185
|
-
fn
|
|
185
|
+
fn _rzPixelFiltered(coord: vec2<i32>) -> vec4f {
|
|
186
186
|
let sz = vec2<i32>(textureDimensions(hdrTex)) - vec2<i32>(1);
|
|
187
187
|
let w = array<f32, 3>(viewU[15].y, viewU[15].z, viewU[15].w);
|
|
188
188
|
let r = select(1, 2, w[2] > 0.0);
|
|
@@ -561,7 +561,7 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
561
561
|
var alpha = textureLoad(maskTex, coord, 0).g;
|
|
562
562
|
// A renderer's pixel filter, while one is set (viewU[15].y < 1).
|
|
563
563
|
if (viewU[15].y < 0.99999) {
|
|
564
|
-
let f =
|
|
564
|
+
let f = _rzPixelFiltered(coord);
|
|
565
565
|
hdr = vec4f(f.rgb, hdr.a);
|
|
566
566
|
alpha = f.a;
|
|
567
567
|
}
|
|
@@ -45,6 +45,13 @@ type ParticleSource = {
|
|
|
45
45
|
* stretched particle stretches along its velocity projected into it. `id`
|
|
46
46
|
* is the particle's slot, so the axes can come from its emitter. */
|
|
47
47
|
orient?: boolean;
|
|
48
|
+
/** The effect defines `particleCorner(p: Particle, id: u32, corner: u32) ->
|
|
49
|
+
* vec3f`: where each corner of the quad stands in world space, 0 and 1 along
|
|
50
|
+
* the bottom, 2 and 3 along the top, replacing the card entirely. Corners 2
|
|
51
|
+
* and 3 at one point make a true triangle with uv as its barycentrics, so a
|
|
52
|
+
* pool can draw a mesh: the positions are read in the vertex stage, after
|
|
53
|
+
* the step, where every corner of a frame sees the same state of the pool. */
|
|
54
|
+
corner?: boolean;
|
|
48
55
|
/** The effect defines `particleCount() -> u32`: how many of the pool are
|
|
49
56
|
* live this frame, as a function of its dials. The step is dispatched and
|
|
50
57
|
* the quads drawn for that many slots and no more, through indirect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"particles.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/particles.ts"],"names":[],"mappings":"AAgCA,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS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
314
|
}
|
|
315
315
|
}
|
|
316
|
-
let
|
|
317
|
-
|
|
316
|
+
${/\bfn\s+particleCorner\s*\(/.test(src.wgsl) ? ` let corners = array<u32, 6>(0u, 1u, 2u, 2u, 1u, 3u);
|
|
317
|
+
let world = particleCorner(p, ii, corners[vi]);
|
|
318
|
+
` : ` let world = p.pos + (right * r.x + up * r.y) * p.size;
|
|
319
|
+
`} out.clip = cam.proj * cam.view * vec4f(world, 1.0);
|
|
318
320
|
return out;
|
|
319
321
|
}
|
|
320
322
|
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
/** ray-mmd, skin profile (index 1): profileSpikeRadArr[1].xyz × (1 − sssAmount),
|
|
31
31
|
* with sssAmount = customA = 0.6 in Materials/Skin/material_skin.fx. */
|
|
32
32
|
export declare const SSS_SPIKE: [number, number, number];
|
|
33
|
-
export declare const SUBSURFACE_WGSL = "\n@group(0) @binding(0) var srcTex: texture_2d<f32>;\n@group(0) @binding(1) var maskTex: texture_2d<f32>;\n@group(0) @binding(2) var depthTex: texture_depth_multisampled_2d;\n// dofU[2] = (projA, projB): the same z-buffer inversion the composite uses.\n@group(0) @binding(3) var<uniform> dofU: array<vec4f, 3>;\n// sssU[0] = (direction.xy, radius, _); sssU[1] = (tanHalfFov\u00B7aspect, tanHalfFov, width, height).\n@group(0) @binding(4) var<uniform> sssU: array<vec4f, 2>;\n\nstruct VsOut { @builtin(position) pos: vec4f };\n\n@vertex fn vs(@builtin(vertex_index) i: u32) -> VsOut {\n let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));\n var o: VsOut;\n o.pos = vec4f(p * 2.0 - 1.0, 0.0, 1.0);\n return o;\n}\n\nfn size() -> vec2i { return vec2i(sssU[1].zw); }\n\nfn texel(uv: vec2f) -> vec2i {\n return clamp(vec2i(floor(uv * sssU[1].zw)), vec2i(0), size() - 1);\n}\n\nfn linearDepth(c: vec2i) -> f32 {\n let z = textureLoad(depthTex, c, 0);\n return clamp(dofU[2].y / (z - dofU[2].x), 0.05, 100000.0);\n}\n\n// View-space position of a texel centre \u2014 ray-mmd's GetViewPosition, with y up.\nfn viewPos(c: vec2i, d: f32) -> vec3f {\n let uv = (vec2f(c) + 0.5) / sssU[1].zw;\n let ndc = vec2f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0);\n return vec3f(ndc * sssU[1].xy * d, d);\n}\n\nfn skin(c: vec2i) -> f32 { return textureLoad(maskTex, c, 0).b; }\n\nfn blur(fragPos: vec4f) -> vec4f {\n let c = vec2i(fragPos.xy);\n let amount = skin(c) * 4.0;\n let dir = sssU[0].xy;\n let uv = (vec2f(c) + 0.5) / sssU[1].zw;\n let
|
|
33
|
+
export declare const SUBSURFACE_WGSL = "\n@group(0) @binding(0) var srcTex: texture_2d<f32>;\n@group(0) @binding(1) var maskTex: texture_2d<f32>;\n@group(0) @binding(2) var depthTex: texture_depth_multisampled_2d;\n// dofU[2] = (projA, projB): the same z-buffer inversion the composite uses.\n@group(0) @binding(3) var<uniform> dofU: array<vec4f, 3>;\n// sssU[0] = (direction.xy, radius, _); sssU[1] = (tanHalfFov\u00B7aspect, tanHalfFov, width, height).\n@group(0) @binding(4) var<uniform> sssU: array<vec4f, 2>;\n\nstruct VsOut { @builtin(position) pos: vec4f };\n\n@vertex fn vs(@builtin(vertex_index) i: u32) -> VsOut {\n let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));\n var o: VsOut;\n o.pos = vec4f(p * 2.0 - 1.0, 0.0, 1.0);\n return o;\n}\n\nfn size() -> vec2i { return vec2i(sssU[1].zw); }\n\nfn texel(uv: vec2f) -> vec2i {\n return clamp(vec2i(floor(uv * sssU[1].zw)), vec2i(0), size() - 1);\n}\n\nfn linearDepth(c: vec2i) -> f32 {\n let z = textureLoad(depthTex, c, 0);\n return clamp(dofU[2].y / (z - dofU[2].x), 0.05, 100000.0);\n}\n\n// View-space position of a texel centre \u2014 ray-mmd's GetViewPosition, with y up.\nfn viewPos(c: vec2i, d: f32) -> vec3f {\n let uv = (vec2f(c) + 0.5) / sssU[1].zw;\n let ndc = vec2f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0);\n return vec3f(ndc * sssU[1].xy * d, d);\n}\n\nfn skin(c: vec2i) -> f32 { return textureLoad(maskTex, c, 0).b; }\n\n// A colour a blur may take in: every channel finite. Read off the exponent bits, because a\n// fast-math compiler may fold x != x away. Without this one NaN or Inf beside the skin, from\n// any material on any GPU, spreads along the X pass and then the Y pass into bars and blocks\n// across the face: a tap weighted 0 still multiplies to NaN.\nfn finite3(c: vec3f) -> bool {\n let e = bitcast<vec3u>(c) & vec3u(0x7f800000u);\n return all(e != vec3u(0x7f800000u));\n}\n\nfn blur(fragPos: vec4f) -> vec4f {\n let c = vec2i(fragPos.xy);\n let amount = skin(c) * 4.0;\n let dir = sssU[0].xy;\n let uv = (vec2f(c) + 0.5) / sssU[1].zw;\n let raw = textureLoad(srcTex, c, 0);\n let centre = vec4f(select(vec3f(0.0), raw.rgb, finite3(raw.rgb)), raw.a);\n\n // ray-mmd, verbatim: six offsets, and the skin variances per channel.\n // A var, not a const: a const array cannot be indexed by the loop counter.\n var offsets = array<f32, 6>(0.352, 0.719, 1.117, 1.579, 2.177, 3.213);\n const profileVar = vec3f(9.6, 2.8, 2.2);\n // mSSSSScale at the controller's default; it sets both the width and how hard\n // a depth step rejects.\n const SSSS_SCALE: f32 = 0.04;\n\n let d = linearDepth(c);\n\n // The surface's normal, rebuilt from depth (ray-mmd reads it from its G-buffer;\n // this engine keeps none). Only its angle to the view matters: the blur narrows\n // along an axis the surface is turning away on.\n let s = size();\n let cx = min(c + vec2i(1, 0), s - 1);\n let cy = min(c + vec2i(0, 1), s - 1);\n let P = viewPos(c, d);\n let N = cross(viewPos(cx, linearDepth(cx)) - P, viewPos(cy, linearDepth(cy)) - P);\n let nxz = select(vec2f(0.0, 1.0), normalize(N.xz), dot(N.xz, N.xz) > 1e-12);\n let nyz = select(vec2f(0.0, 1.0), normalize(N.yz), dot(N.yz, N.yz) > 1e-12);\n let scaleX = abs(dot(nxz, normalize(P.xz)));\n let scaleY = abs(dot(nyz, normalize(P.yz)));\n let perspectiveScale = max(dot(dir, vec2f(scaleX, scaleY)), 0.3);\n\n let radius = 0.0055 * amount * perspectiveScale / SSSS_SCALE;\n let step = dir * radius / d;\n\n var weightSum = vec3f(1.0);\n var colour = centre.rgb;\n for (var i = 0; i < 6; i++) {\n let o = offsets[i] / 5.5 * step;\n for (var side = 0; side < 2; side++) {\n let tc = texel(select(uv - o, uv + o, side == 0));\n // Skin only: ray-mmd zeroes a non-skin pixel's depth so the depth term\n // rejects it; the mask says the same thing directly.\n // A tap is taken in or left out, never weighted to zero: 0 times a NaN is a NaN.\n let tap = textureLoad(srcTex, tc, 0).rgb;\n if (skin(tc) > 0.004 && finite3(tap)) {\n let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;\n let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar);\n weightSum += w;\n colour += w * tap;\n }\n }\n }\n return vec4f(colour / weightSum, centre.a);\n}\n\n@fragment fn fsX(@builtin(position) pos: vec4f) -> @location(0) vec4f {\n // Nothing reads the scratch target off skin: the Y pass rejects those taps.\n if (skin(vec2i(pos.xy)) <= 0.004) { return vec4f(0.0); }\n return blur(pos);\n}\n\n@fragment fn fsY(@builtin(position) pos: vec4f) -> @location(0) vec4f {\n // Off skin the HDR resolve must stay exactly as the scene left it.\n if (skin(vec2i(pos.xy)) <= 0.004) { discard; }\n return blur(pos);\n}\n";
|
|
34
34
|
//# sourceMappingURL=subsurface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subsurface.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/subsurface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;yEACyE;AACzE,eAAO,MAAM,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAsC,CAAA;AAErF,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"subsurface.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/subsurface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;yEACyE;AACzE,eAAO,MAAM,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAsC,CAAA;AAErF,eAAO,MAAM,eAAe,8lJAkH3B,CAAA"}
|
|
@@ -68,12 +68,22 @@ fn viewPos(c: vec2i, d: f32) -> vec3f {
|
|
|
68
68
|
|
|
69
69
|
fn skin(c: vec2i) -> f32 { return textureLoad(maskTex, c, 0).b; }
|
|
70
70
|
|
|
71
|
+
// A colour a blur may take in: every channel finite. Read off the exponent bits, because a
|
|
72
|
+
// fast-math compiler may fold x != x away. Without this one NaN or Inf beside the skin, from
|
|
73
|
+
// any material on any GPU, spreads along the X pass and then the Y pass into bars and blocks
|
|
74
|
+
// across the face: a tap weighted 0 still multiplies to NaN.
|
|
75
|
+
fn finite3(c: vec3f) -> bool {
|
|
76
|
+
let e = bitcast<vec3u>(c) & vec3u(0x7f800000u);
|
|
77
|
+
return all(e != vec3u(0x7f800000u));
|
|
78
|
+
}
|
|
79
|
+
|
|
71
80
|
fn blur(fragPos: vec4f) -> vec4f {
|
|
72
81
|
let c = vec2i(fragPos.xy);
|
|
73
82
|
let amount = skin(c) * 4.0;
|
|
74
83
|
let dir = sssU[0].xy;
|
|
75
84
|
let uv = (vec2f(c) + 0.5) / sssU[1].zw;
|
|
76
|
-
let
|
|
85
|
+
let raw = textureLoad(srcTex, c, 0);
|
|
86
|
+
let centre = vec4f(select(vec3f(0.0), raw.rgb, finite3(raw.rgb)), raw.a);
|
|
77
87
|
|
|
78
88
|
// ray-mmd, verbatim: six offsets, and the skin variances per channel.
|
|
79
89
|
// A var, not a const: a const array cannot be indexed by the loop counter.
|
|
@@ -110,11 +120,14 @@ fn blur(fragPos: vec4f) -> vec4f {
|
|
|
110
120
|
let tc = texel(select(uv - o, uv + o, side == 0));
|
|
111
121
|
// Skin only: ray-mmd zeroes a non-skin pixel's depth so the depth term
|
|
112
122
|
// rejects it; the mask says the same thing directly.
|
|
113
|
-
|
|
114
|
-
let
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
// A tap is taken in or left out, never weighted to zero: 0 times a NaN is a NaN.
|
|
124
|
+
let tap = textureLoad(srcTex, tc, 0).rgb;
|
|
125
|
+
if (skin(tc) > 0.004 && finite3(tap)) {
|
|
126
|
+
let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;
|
|
127
|
+
let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar);
|
|
128
|
+
weightSum += w;
|
|
129
|
+
colour += w * tap;
|
|
130
|
+
}
|
|
118
131
|
}
|
|
119
132
|
}
|
|
120
133
|
return vec4f(colour / weightSum, centre.a);
|
package/package.json
CHANGED
package/src/engine.ts
CHANGED
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
hasLightEmit,
|
|
81
81
|
} from "./shaders/lights"
|
|
82
82
|
import { buildLightGrid } from "./light-grid"
|
|
83
|
-
import { groundShaderWgsl, GROUND_NOISE_BAKE_WGSL, GROUND_NOISE_SIZE } from "./shaders/passes/ground"
|
|
83
|
+
import { groundShaderWgsl, GROUND_NOISE_BAKE_WGSL, GROUND_NOISE_SIZE, GROUND_OBJECT_ID } from "./shaders/passes/ground"
|
|
84
84
|
import {
|
|
85
85
|
outlineShaderWgsl,
|
|
86
86
|
RZ_OUTLINE_COLOR_OFFSET,
|
|
@@ -15579,7 +15579,7 @@ export class Engine {
|
|
|
15579
15579
|
// From a counter, never from the count: size + 1 handed a model added
|
|
15580
15580
|
// after a removal the id of one still in the scene, and two models with
|
|
15581
15581
|
// one id are one model to everything that reads the id buffer.
|
|
15582
|
-
objectId: (this.lastObjectId = this.lastObjectId >=
|
|
15582
|
+
objectId: (this.lastObjectId = this.lastObjectId >= GROUND_OBJECT_ID - 1 ? 1 : this.lastObjectId + 1),
|
|
15583
15583
|
dissolve: 1,
|
|
15584
15584
|
materialUniformBuffers: [],
|
|
15585
15585
|
outlineUniformBuffers: [],
|
|
@@ -156,7 +156,7 @@ override APPLY_GAMMA: bool = true;
|
|
|
156
156
|
// viewU[10] = (camera world position, _) — refreshed with the basis above.
|
|
157
157
|
// viewU[11..14] = the cast's positions (effects; count in viewU[10].w).
|
|
158
158
|
// viewU[15] = (soft curve contrast, pixel filter weights for offsets 0, ±1, ±2)
|
|
159
|
-
// — 1, 0, 0 is no filter; see
|
|
159
|
+
// — 1, 0, 0 is no filter; see _rzPixelFiltered.
|
|
160
160
|
// invGamma = 1/gamma precomputed on CPU — avoids a per-pixel divide.
|
|
161
161
|
@group(0) @binding(6) var bgEquirect: texture_2d<f32>;
|
|
162
162
|
// The scene pass's own MSAA depth buffer, bound depth-only. NOT an extra
|
|
@@ -216,7 +216,7 @@ fn rzFieldMerge(top: vec4f, bot: vec4f) -> vec4f {
|
|
|
216
216
|
* (Engine.setPixelFilter): separable weights viewU[15].yzw over offsets 0,
|
|
217
217
|
* ±1, ±2, the coverage filtered alongside so the sky still composites under
|
|
218
218
|
* it. Only called while a filter is on. */
|
|
219
|
-
fn
|
|
219
|
+
fn _rzPixelFiltered(coord: vec2<i32>) -> vec4f {
|
|
220
220
|
let sz = vec2<i32>(textureDimensions(hdrTex)) - vec2<i32>(1);
|
|
221
221
|
let w = array<f32, 3>(viewU[15].y, viewU[15].z, viewU[15].w);
|
|
222
222
|
let r = select(1, 2, w[2] > 0.0);
|
|
@@ -597,7 +597,7 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
597
597
|
var alpha = textureLoad(maskTex, coord, 0).g;
|
|
598
598
|
// A renderer's pixel filter, while one is set (viewU[15].y < 1).
|
|
599
599
|
if (viewU[15].y < 0.99999) {
|
|
600
|
-
let f =
|
|
600
|
+
let f = _rzPixelFiltered(coord);
|
|
601
601
|
hdr = vec4f(f.rgb, hdr.a);
|
|
602
602
|
alpha = f.a;
|
|
603
603
|
}
|
|
@@ -111,6 +111,13 @@ type ParticleSource = {
|
|
|
111
111
|
* stretched particle stretches along its velocity projected into it. `id`
|
|
112
112
|
* is the particle's slot, so the axes can come from its emitter. */
|
|
113
113
|
orient?: boolean
|
|
114
|
+
/** The effect defines `particleCorner(p: Particle, id: u32, corner: u32) ->
|
|
115
|
+
* vec3f`: where each corner of the quad stands in world space, 0 and 1 along
|
|
116
|
+
* the bottom, 2 and 3 along the top, replacing the card entirely. Corners 2
|
|
117
|
+
* and 3 at one point make a true triangle with uv as its barycentrics, so a
|
|
118
|
+
* pool can draw a mesh: the positions are read in the vertex stage, after
|
|
119
|
+
* the step, where every corner of a frame sees the same state of the pool. */
|
|
120
|
+
corner?: boolean
|
|
114
121
|
/** The effect defines `particleCount() -> u32`: how many of the pool are
|
|
115
122
|
* live this frame, as a function of its dials. The step is dispatched and
|
|
116
123
|
* the quads drawn for that many slots and no more, through indirect
|
|
@@ -411,8 +418,10 @@ ${src.orient ? ` // the author's own plane (particleOrient): a card on a surfac
|
|
|
411
418
|
r = vec2f(d.y, -d.x) * cp.x + d * (cp.y * p.stretch);
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
|
-
let
|
|
415
|
-
|
|
421
|
+
${/\bfn\s+particleCorner\s*\(/.test(src.wgsl) ? ` let corners = array<u32, 6>(0u, 1u, 2u, 2u, 1u, 3u);
|
|
422
|
+
let world = particleCorner(p, ii, corners[vi]);
|
|
423
|
+
` : ` let world = p.pos + (right * r.x + up * r.y) * p.size;
|
|
424
|
+
`} out.clip = cam.proj * cam.view * vec4f(world, 1.0);
|
|
416
425
|
return out;
|
|
417
426
|
}
|
|
418
427
|
|
|
@@ -70,12 +70,22 @@ fn viewPos(c: vec2i, d: f32) -> vec3f {
|
|
|
70
70
|
|
|
71
71
|
fn skin(c: vec2i) -> f32 { return textureLoad(maskTex, c, 0).b; }
|
|
72
72
|
|
|
73
|
+
// A colour a blur may take in: every channel finite. Read off the exponent bits, because a
|
|
74
|
+
// fast-math compiler may fold x != x away. Without this one NaN or Inf beside the skin, from
|
|
75
|
+
// any material on any GPU, spreads along the X pass and then the Y pass into bars and blocks
|
|
76
|
+
// across the face: a tap weighted 0 still multiplies to NaN.
|
|
77
|
+
fn finite3(c: vec3f) -> bool {
|
|
78
|
+
let e = bitcast<vec3u>(c) & vec3u(0x7f800000u);
|
|
79
|
+
return all(e != vec3u(0x7f800000u));
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
fn blur(fragPos: vec4f) -> vec4f {
|
|
74
83
|
let c = vec2i(fragPos.xy);
|
|
75
84
|
let amount = skin(c) * 4.0;
|
|
76
85
|
let dir = sssU[0].xy;
|
|
77
86
|
let uv = (vec2f(c) + 0.5) / sssU[1].zw;
|
|
78
|
-
let
|
|
87
|
+
let raw = textureLoad(srcTex, c, 0);
|
|
88
|
+
let centre = vec4f(select(vec3f(0.0), raw.rgb, finite3(raw.rgb)), raw.a);
|
|
79
89
|
|
|
80
90
|
// ray-mmd, verbatim: six offsets, and the skin variances per channel.
|
|
81
91
|
// A var, not a const: a const array cannot be indexed by the loop counter.
|
|
@@ -112,11 +122,14 @@ fn blur(fragPos: vec4f) -> vec4f {
|
|
|
112
122
|
let tc = texel(select(uv - o, uv + o, side == 0));
|
|
113
123
|
// Skin only: ray-mmd zeroes a non-skin pixel's depth so the depth term
|
|
114
124
|
// rejects it; the mask says the same thing directly.
|
|
115
|
-
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
// A tap is taken in or left out, never weighted to zero: 0 times a NaN is a NaN.
|
|
126
|
+
let tap = textureLoad(srcTex, tc, 0).rgb;
|
|
127
|
+
if (skin(tc) > 0.004 && finite3(tap)) {
|
|
128
|
+
let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;
|
|
129
|
+
let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar);
|
|
130
|
+
weightSum += w;
|
|
131
|
+
colour += w * tap;
|
|
132
|
+
}
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
135
|
return vec4f(colour / weightSum, centre.a);
|