mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-29 09:34:33 +01:00
Merge pull request #109 from storytold/fix/sss-ghosting
Viewport: no ghost edges in the subsurface blur
This commit is contained in:
3 files changed
+13
-7
No files matched your search
@@ -1584,7 +1584,7 @@ impl Renderer {
|
||||
b: [fx(s.vignette), fx(s.sharpen), fx(s.grain), BLOOM_THRESHOLD],
|
||||
c: dof_c,
|
||||
d: sss_d,
|
||||
e: [flag(cam.ortho), 0.0, 0.0, 0.0],
|
||||
e: [flag(cam.ortho), sample as f32, 0.0, 0.0],
|
||||
};
|
||||
let Some(v) = self.targets(device, frame.view_id, frame.size, bloom, fx_on, refraction) else { return };
|
||||
queue.write_buffer(&v.globals, 0, bytemuck::bytes_of(&raw));
|
||||
|
||||
@@ -22,7 +22,8 @@ fn texel_at(t: texture_2d<f32>, p: vec2<f32>) -> vec4<f32> {
|
||||
|
||||
// ---- Subsurface scattering: a separable bilateral blur (Jimenez et al., "Separable Subsurface
|
||||
// Scattering", 2015) of the scattering diffuse light, a Gaussian per color channel as wide as
|
||||
// its mean free path, cut off across depth discontinuities.
|
||||
// its mean free path. A tap across a depth discontinuity (or off the mesh) takes the centre's
|
||||
// light instead, so no tap drops out of the sum as it crosses a silhouette.
|
||||
|
||||
const SSS_TAPS: i32 = 8;
|
||||
|
||||
@@ -41,17 +42,22 @@ fn sss_blur(p: vec2<f32>, dir: vec2<f32>) -> vec4<f32> {
|
||||
let stride = dir * (smax * 3.0 / f32(SSS_TAPS));
|
||||
let depth_range = 3.0 * max(post.d.x, max(post.d.y, post.d.z));
|
||||
let inv = 1.0 / (2.0 * sigma * sigma + vec3<f32>(1e-4));
|
||||
// Wide blurs space their taps pixels apart: shifting them per pixel (interleaved gradient
|
||||
// noise) and per accumulated frame turns what would show as copies of edges into fine grain.
|
||||
let ign = fract(52.9829189 * fract(dot(p, vec2<f32>(0.06711056, 0.00583715))));
|
||||
let jitter = fract(ign + post.e.y * 0.618034) - 0.5;
|
||||
var sum = c.rgb;
|
||||
var wsum = vec3<f32>(1.0);
|
||||
for (var k = -SSS_TAPS; k <= SSS_TAPS; k++) {
|
||||
if (k == 0) {
|
||||
continue;
|
||||
}
|
||||
let t = texel_at(src, p + stride * f32(k));
|
||||
let x = f32(k) * smax * 3.0 / f32(SSS_TAPS);
|
||||
let o = f32(k) + jitter;
|
||||
let t = texel_at(src, p + stride * o);
|
||||
let x = o * smax * 3.0 / f32(SSS_TAPS);
|
||||
let wd = select(0.0, max(1.0 - abs(t.a - c.a) / depth_range, 0.0), t.a > 0.0);
|
||||
let w = exp(-x * x * inv) * wd;
|
||||
sum += t.rgb * w;
|
||||
let w = exp(-x * x * inv);
|
||||
sum += mix(c.rgb, t.rgb, wd) * w;
|
||||
wsum += w;
|
||||
}
|
||||
return vec4<f32>(sum / wsum, c.a);
|
||||
|
||||
@@ -7,7 +7,7 @@ struct Post {
|
||||
b: vec4<f32>, // x vignette, y sharpen, z grain, w bloom threshold
|
||||
c: vec4<f32>, // depth of field (fx.wgsl): x circle of confusion at infinity (pixels), y focus depth, z largest circle radius (pixels), w accumulation sample
|
||||
d: vec4<f32>, // subsurface blur (fx.wgsl): xyz mean free path per channel (world units), w pixels per world unit at depth 1
|
||||
e: vec4<f32>, // x orthographic camera (1: pixels per world unit don't fall off with depth), yzw -
|
||||
e: vec4<f32>, // x orthographic camera (1: pixels per world unit don't fall off with depth), y accumulation sample, zw -
|
||||
};
|
||||
|
||||
@group(0) @binding(3) var<uniform> post: Post;
|
||||
|
||||
Reference in new issue
Block a user