reze-engine 0.68.25 → 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 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 >= 65535 ? 1 : this.lastObjectId + 1),
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 rzPixelFiltered.
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 rzPixelFiltered(coord: vec2<i32>) -> vec4f {
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 = rzPixelFiltered(coord);
564
+ let f = _rzPixelFiltered(coord);
565
565
  hdr = vec4f(f.rgb, hdr.a);
566
566
  alpha = f.a;
567
567
  }
@@ -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 centre = textureLoad(srcTex, c, 0);\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 let isSkin = select(0.0, 1.0, skin(tc) > 0.004);\n let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;\n let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar) * isSkin;\n weightSum += w;\n colour += w * textureLoad(srcTex, tc, 0).rgb;\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";
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,48HAqG3B,CAAA"}
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 centre = textureLoad(srcTex, c, 0);
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
- let isSkin = select(0.0, 1.0, skin(tc) > 0.004);
114
- let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;
115
- let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar) * isSkin;
116
- weightSum += w;
117
- colour += w * textureLoad(srcTex, tc, 0).rgb;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.68.25",
3
+ "version": "0.68.26",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
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 >= 65535 ? 1 : this.lastObjectId + 1),
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 rzPixelFiltered.
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 rzPixelFiltered(coord: vec2<i32>) -> vec4f {
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 = rzPixelFiltered(coord);
600
+ let f = _rzPixelFiltered(coord);
601
601
  hdr = vec4f(f.rgb, hdr.a);
602
602
  alpha = f.a;
603
603
  }
@@ -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 centre = textureLoad(srcTex, c, 0);
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
- let isSkin = select(0.0, 1.0, skin(tc) > 0.004);
116
- let dd = (linearDepth(tc) - d) * 1000.0 * SSSS_SCALE;
117
- let w = exp(-(offsets[i] * offsets[i] + dd * dd) / profileVar) * isSkin;
118
- weightSum += w;
119
- colour += w * textureLoad(srcTex, tc, 0).rgb;
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);