mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Preserve texture set hover in the IOR branch merge
This commit is contained in:
commit
2cbbebfd3f
428 files changed
+24761
-4005
No files matched your search
@@ -101,6 +101,7 @@ struct GlobalsRaw {
|
||||
refr: [f32; 4],
|
||||
highlight: [f32; 4],
|
||||
highlight_shift: [f32; 4],
|
||||
set_hover: [f32; 4],
|
||||
bake_high: [f32; 4],
|
||||
bake_matching_error: [f32; 4],
|
||||
bake_cage: [f32; 4],
|
||||
@@ -138,6 +139,9 @@ const HIGHLIGHT_WIDTH_PX: f32 = 1.5;
|
||||
/// Opacity of the highlighted set's edge lines
|
||||
const HIGHLIGHT_OPACITY: f32 = 0.9;
|
||||
|
||||
/// Opacity of the texture-set hover tint over the shaded material.
|
||||
const SET_HOVER_OPACITY: f32 = 0.35;
|
||||
|
||||
/// Copies of each highlight line, shifted diagonally to the four corners of its extra width (`vs_wire_highlight`)
|
||||
const HIGHLIGHT_SHIFTS: u32 = 4;
|
||||
|
||||
@@ -195,6 +199,8 @@ pub struct Shade {
|
||||
pub wireframe_opacity: f32,
|
||||
/// One texture set's mesh edges in a highlight color over the 3D view (the set under a shelf drag)
|
||||
pub highlight: Option<SetHighlight>,
|
||||
/// The texture set whose visible surfaces are tinted in the 3D view.
|
||||
pub set_hover: Option<SetHighlight>,
|
||||
/// Specular/glossiness shading: base color is the diffuse color and the Specular channel the
|
||||
/// F0 color (roughness arrives as 1 - glossiness from the display conversion).
|
||||
pub spec_gloss: bool,
|
||||
@@ -312,6 +318,7 @@ impl Default for Shade {
|
||||
wireframe_3d: false,
|
||||
wireframe_opacity: 0.4,
|
||||
highlight: None,
|
||||
set_hover: None,
|
||||
spec_gloss: false,
|
||||
parallax: false,
|
||||
taa: false,
|
||||
@@ -1946,8 +1953,8 @@ impl Renderer {
|
||||
ranges: &'a [(u32, u32, usize)],
|
||||
visible: &'a [bool],
|
||||
only: Option<usize>,
|
||||
) -> impl Iterator<Item = (std::ops::Range<u32>, &'a SetGpu)> + 'a {
|
||||
drawable_ranges(ranges, &self.material_sets, visible, only).filter_map(|(range, ts)| Some((range, self.sets.get(ts)?)))
|
||||
) -> impl Iterator<Item = (std::ops::Range<u32>, usize, &'a SetGpu)> + 'a {
|
||||
drawable_ranges(ranges, &self.material_sets, visible, only).filter_map(|(range, texture_set)| Some((range, texture_set, self.sets.get(texture_set)?)))
|
||||
}
|
||||
|
||||
/// Keep the key-light shadow map current; returns its view-projection. `light` points to
|
||||
@@ -2008,7 +2015,7 @@ impl Renderer {
|
||||
let geo = m.dense.as_ref().filter(|_| displacing).unwrap_or(&m.geo);
|
||||
pass.set_vertex_buffer(0, geo.vb.slice(..));
|
||||
pass.set_index_buffer(geo.ib.slice(..), wgpu::IndexFormat::Uint32);
|
||||
for (range, set) in self.drawable(&geo.draws, visible, None) {
|
||||
for (range, _, set) in self.drawable(&geo.draws, visible, None) {
|
||||
pass.set_bind_group(1, &set.bind_group, &[]);
|
||||
pass.draw_indexed(range, 0, 0..1);
|
||||
}
|
||||
@@ -2130,8 +2137,9 @@ impl Renderer {
|
||||
fwd: [fwd.x, fwd.y, fwd.z, 0.0],
|
||||
disp,
|
||||
refr: [if refraction { 1.0 } else { 0.0 }, (BEHIND_LEVELS - 1) as f32, REFRACTION_DEPTH * radius, s.dielectric_f0_scale],
|
||||
highlight: highlight_globals(s, data),
|
||||
highlight: highlight_globals(s.highlight, HIGHLIGHT_OPACITY, s, data),
|
||||
highlight_shift: highlight_shift(frame.size),
|
||||
set_hover: highlight_globals(s.set_hover, SET_HOVER_OPACITY, s, data),
|
||||
..bake_globals(s.bake)
|
||||
};
|
||||
let flag = |b: bool| if b { 1.0 } else { 0.0 };
|
||||
@@ -2140,11 +2148,12 @@ impl Renderer {
|
||||
b: [fx(s.vignette), fx(s.sharpen), fx(s.grain), BLOOM_THRESHOLD],
|
||||
c: dof_c,
|
||||
d: sss_d,
|
||||
e: [flag(cam.ortho), sample as f32, 0.0, 0.0],
|
||||
e: [flag(cam.ortho), sample as f32, raw.set_hover[3], 0.0],
|
||||
back_top: [s.background[0][0], s.background[0][1], s.background[0][2], 0.0],
|
||||
back_bottom: [s.background[1][0], s.background[1][1], s.background[1][2], 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));
|
||||
queue.write_buffer(&v.post_buf, 0, bytemuck::bytes_of(&post));
|
||||
upload_overlay(device, queue, v, &frame.overlay, (!data).then_some(s.exposure_ev));
|
||||
@@ -2219,9 +2228,13 @@ impl Renderer {
|
||||
let geo = self.geometry(m, frame);
|
||||
pass.set_vertex_buffer(0, geo.vb.slice(..));
|
||||
pass.set_index_buffer(geo.ib.slice(..), wgpu::IndexFormat::Uint32);
|
||||
for (range, set) in self.drawable(&geo.draws, &frame.visible, None) {
|
||||
|
||||
// Instance index 1 lets the G-buffer mark the hovered set for the scattering composite
|
||||
let hover_set = frame.shade.set_hover.filter(|_| frame.kind == ViewKind::Scene).map(|hover| hover.set);
|
||||
for (range, texture_set, set) in self.drawable(&geo.draws, &frame.visible, None) {
|
||||
pass.set_bind_group(1, &set.bind_group, &[]);
|
||||
pass.draw_indexed(range, 0, 0..1);
|
||||
let first_instance = u32::from(hover_set == Some(texture_set));
|
||||
pass.draw_indexed(range, 0, first_instance..first_instance + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2346,22 +2359,25 @@ impl Renderer {
|
||||
let bake = frame.shade.bake.filter(|_| uv_set.is_none());
|
||||
let low_poly_shown = bake.is_none_or(|bake| bake.low_poly.shown);
|
||||
let (highlight, highlight_set) = highlight.filter(|(_, set)| low_poly_shown && uv_set.is_none_or(|only| only == *set)).unzip();
|
||||
let hover_set = frame.shade.set_hover.filter(|_| uv_set.is_none()).map(|hover| hover.set);
|
||||
|
||||
// The wireframe and the highlight draw the mesh's own edges (displaced in the vertex shader too)
|
||||
let passes = [
|
||||
(low_poly_shown.then_some(mesh_pipeline), &geometry.vb, &geometry.ib, &geometry.draws, uv_set, 1),
|
||||
(wire.filter(|_| low_poly_shown), &mesh.geo.vb, &mesh.lines, &mesh.line_draws, uv_set, 1),
|
||||
(highlight, &mesh.geo.vb, &mesh.lines, &mesh.line_draws, highlight_set, HIGHLIGHT_SHIFTS),
|
||||
(low_poly_shown.then_some(mesh_pipeline), &geometry.vb, &geometry.ib, &geometry.draws, uv_set, 1, hover_set),
|
||||
(wire.filter(|_| low_poly_shown), &mesh.geo.vb, &mesh.lines, &mesh.line_draws, uv_set, 1, None),
|
||||
(highlight, &mesh.geo.vb, &mesh.lines, &mesh.line_draws, highlight_set, HIGHLIGHT_SHIFTS, None),
|
||||
];
|
||||
for (pipeline, vertices, indices, ranges, only_set, instances) in passes {
|
||||
for (pipeline, vertices, indices, ranges, only_set, instances, hover_set) in passes {
|
||||
let Some(pipeline) = pipeline else { continue };
|
||||
|
||||
pass.set_pipeline(pipeline);
|
||||
pass.set_vertex_buffer(0, vertices.slice(..));
|
||||
pass.set_index_buffer(indices.slice(..), wgpu::IndexFormat::Uint32);
|
||||
for (range, set) in self.drawable(ranges, &frame.visible, only_set) {
|
||||
for (range, texture_set, set) in self.drawable(ranges, &frame.visible, only_set) {
|
||||
// Instance index 1 lets the mesh shader tint the hovered draw
|
||||
let first_instance = u32::from(hover_set == Some(texture_set));
|
||||
pass.set_bind_group(1, &set.bind_group, &[]);
|
||||
pass.draw_indexed(range, 0, 0..instances);
|
||||
pass.draw_indexed(range, 0, first_instance..first_instance + instances);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2375,7 +2391,7 @@ impl Renderer {
|
||||
pass.set_pipeline(&self.uv_missing_seam_pipeline);
|
||||
pass.set_vertex_buffer(0, mesh.geo.vb.slice(..));
|
||||
pass.set_index_buffer(seams.lines.slice(..), wgpu::IndexFormat::Uint32);
|
||||
for (range, set) in self.drawable(&seams.line_draws, &frame.visible, Some(texture_set)) {
|
||||
for (range, _, set) in self.drawable(&seams.line_draws, &frame.visible, Some(texture_set)) {
|
||||
pass.set_bind_group(1, &set.bind_group, &[]);
|
||||
pass.draw_indexed(range, 0, 0..1);
|
||||
}
|
||||
@@ -2409,7 +2425,7 @@ impl Renderer {
|
||||
pass.set_pipeline(&self.missing_seam_pipeline);
|
||||
pass.set_vertex_buffer(0, low_poly.geo.vb.slice(..));
|
||||
pass.set_index_buffer(seams.lines.slice(..), wgpu::IndexFormat::Uint32);
|
||||
for (range, set) in self.drawable(&seams.line_draws, &frame.visible, None) {
|
||||
for (range, _, set) in self.drawable(&seams.line_draws, &frame.visible, None) {
|
||||
pass.set_bind_group(1, &set.bind_group, &[]);
|
||||
pass.draw_indexed(range, 0, 0..1);
|
||||
}
|
||||
@@ -2546,12 +2562,12 @@ fn upload_overlay(device: &wgpu::Device, queue: &wgpu::Queue, view: &mut ViewTar
|
||||
}
|
||||
}
|
||||
|
||||
/// Globals `highlight`: the highlight's color and opacity, all zero without one. Data views skip exposure and tone mapping, so they take the color as it is
|
||||
fn highlight_globals(shade: &Shade, data: bool) -> [f32; 4] {
|
||||
let Some(highlight) = shade.highlight else { return [0.0; 4] };
|
||||
/// The highlight's color and opacity. Data views take the color as it is.
|
||||
fn highlight_globals(highlight: Option<SetHighlight>, opacity: f32, shade: &Shade, data: bool) -> [f32; 4] {
|
||||
let Some(highlight) = highlight else { return [0.0; 4] };
|
||||
|
||||
let [r, g, b] = if data { highlight.color } else { highlight.scene_color(shade.exposure_ev, shade.aces) };
|
||||
[r, g, b, HIGHLIGHT_OPACITY]
|
||||
[r, g, b, opacity]
|
||||
}
|
||||
|
||||
/// The globals of bake mode's overlays and neutral material for `bake` (all zero without it)
|
||||
@@ -2683,8 +2699,8 @@ mod tests {
|
||||
let color = [0.8, 0.25, 0.08];
|
||||
let shade = Shade { highlight: Some(SetHighlight { set: 0, color }), exposure_ev: 1.0, ..Shade::default() };
|
||||
|
||||
assert_eq!(highlight_globals(&shade, true), [0.8, 0.25, 0.08, HIGHLIGHT_OPACITY]);
|
||||
assert_ne!(highlight_globals(&shade, false)[..3], color, "the material view undoes exposure and tone mapping");
|
||||
assert_eq!(highlight_globals(shade.highlight, HIGHLIGHT_OPACITY, &shade, true), [0.8, 0.25, 0.08, HIGHLIGHT_OPACITY]);
|
||||
assert_ne!(highlight_globals(shade.highlight, HIGHLIGHT_OPACITY, &shade, false)[..3], color, "the material view undoes exposure and tone mapping");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! A texture set's mesh edges drawn over the 3D view in a highlight color (the set under a shelf drag)
|
||||
//! Texture-set highlighting in the 3D viewport.
|
||||
|
||||
/// Brightest on-screen value the tone curve can reach without an infinite scene value
|
||||
const MAX_ACES_SCREEN_VALUE: f32 = 0.99;
|
||||
@@ -6,16 +6,16 @@ const MAX_ACES_SCREEN_VALUE: f32 = 0.99;
|
||||
/// Scene scale the post pass applies before its ACES curve (`aces` in post.wgsl)
|
||||
const ACES_INPUT_SCALE: f32 = 0.6;
|
||||
|
||||
/// Draw texture set `set`'s mesh edges over the 3D view in `color`
|
||||
/// A texture set to highlight in the 3D viewport.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct SetHighlight {
|
||||
pub set: usize,
|
||||
/// The lines' color on screen, linear RGB
|
||||
/// The highlight color on screen, linear RGB.
|
||||
pub color: [f32; 3],
|
||||
}
|
||||
|
||||
impl SetHighlight {
|
||||
/// The scene color the lines are drawn with so that exposure `exposure_ev` and the tone curve (ACES when `aces`) show them in [`Self::color`]
|
||||
/// The scene color that exposure `exposure_ev` and the tone curve (ACES when `aces`) show as [`Self::color`].
|
||||
pub fn scene_color(&self, exposure_ev: f32, aces: bool) -> [f32; 3] {
|
||||
scene_color_showing(self.color, exposure_ev, aces)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Scene effects between the scene pass and the post pass, appended to util.wgsl and post.wgsl
|
||||
// (uses `src`, `src_samp`, `post`, `fx_a`): the screen-space subsurface blur and depth of field.
|
||||
// Both read the G-buffer of `fs_gbuf` (mesh.wgsl): rgb the scattering part of the diffuse light,
|
||||
// a the view depth (0: background). Colors are linear HDR premultiplied by scene coverage.
|
||||
// Screen-space subsurface blur and depth of field run between the scene and post passes
|
||||
// G-buffer RGB holds scattering light in linear HDR premultiplied by scene coverage
|
||||
// G-buffer alpha holds view depth, with zero for background and a negative sign for hover
|
||||
|
||||
@group(0) @binding(5) var fx_b: texture_2d<f32>;
|
||||
@group(0) @binding(6) var fx_c: texture_2d<f32>;
|
||||
@@ -31,19 +30,22 @@ fn px_per_world(z: f32) -> f32 {
|
||||
return select(post.d.w / max(z, 1e-4), post.d.w, post.e.x > 0.5);
|
||||
}
|
||||
|
||||
// One direction of the blur over `src` (rgb light, a depth) at pixel `p` (same-size target).
|
||||
// The blur changes RGB and carries the centre's signed depth unchanged
|
||||
fn sss_blur(p: vec2<f32>, dir: vec2<f32>) -> vec4<f32> {
|
||||
let c = texel_at(src, p);
|
||||
let sigma = post.d.xyz * px_per_world(c.a);
|
||||
let z = abs(c.a);
|
||||
let sigma = post.d.xyz * px_per_world(z);
|
||||
let smax = max(sigma.r, max(sigma.g, sigma.b));
|
||||
if (c.a <= 0.0 || smax < 0.5) {
|
||||
|
||||
if (z <= 0.0 || smax < 0.5) {
|
||||
return c;
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
// Jitter the wide blur taps so copies of edges become 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;
|
||||
@@ -52,30 +54,35 @@ fn sss_blur(p: vec2<f32>, dir: vec2<f32>) -> vec4<f32> {
|
||||
if (k == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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 tz = abs(t.a);
|
||||
let wd = select(0.0, max(1.0 - abs(tz - z) / depth_range, 0.0), tz > 0.0);
|
||||
let w = exp(-x * x * inv);
|
||||
sum += mix(c.rgb, t.rgb, wd) * w;
|
||||
wsum += w;
|
||||
}
|
||||
|
||||
return vec4<f32>(sum / wsum, c.a);
|
||||
}
|
||||
|
||||
// src: the G-buffer.
|
||||
// Read scattering light and depth from the G-buffer
|
||||
@fragment
|
||||
fn fs_sss_h(i: FsOut) -> @location(0) vec4<f32> {
|
||||
return sss_blur(i.pos.xy, vec2<f32>(1.0, 0.0));
|
||||
}
|
||||
|
||||
// src: the horizontal pass, fx_a: the scene (without its scattering light, see `fs_mesh`). Adds
|
||||
// the blurred scattering light.
|
||||
// Restore scattering light from the horizontal pass to the main scene in fx_a
|
||||
// Apply hover opacity at the destination so neighbouring sets keep the light they receive
|
||||
@fragment
|
||||
fn fs_sss_v(i: FsOut) -> @location(0) vec4<f32> {
|
||||
let blurred = sss_blur(i.pos.xy, vec2<f32>(0.0, 1.0)).rgb;
|
||||
let blurred = sss_blur(i.pos.xy, vec2<f32>(0.0, 1.0));
|
||||
let scene = texel_at(fx_a, i.pos.xy);
|
||||
return scene + vec4<f32>(blurred * clamp(scene.a, 0.0, 1.0), 0.0);
|
||||
let scattering_weight = select(1.0, 1.0 - post.e.z, blurred.a < 0.0);
|
||||
|
||||
return scene + vec4<f32>(blurred.rgb * scattering_weight * clamp(scene.a, 0.0, 1.0), 0.0);
|
||||
}
|
||||
|
||||
// ---- Depth of field: a thin lens. Scatter-as-gather over a golden-angle spiral at half
|
||||
@@ -103,27 +110,28 @@ struct DofOut {
|
||||
@location(1) near: vec4<f32>,
|
||||
};
|
||||
|
||||
// src: the scene (full resolution), fx_a: the G-buffer.
|
||||
// Read full-resolution scene colors from src and depths from fx_a
|
||||
@fragment
|
||||
fn fs_dof_gather(i: FsOut) -> DofOut {
|
||||
let px = 1.0 / vec2<f32>(textureDimensions(src));
|
||||
let zc = texel(fx_a, i.uv).a;
|
||||
let zc = abs(texel(fx_a, i.uv).a);
|
||||
let cc = abs(coc(zc));
|
||||
let rmax = post.c.z;
|
||||
// Half the spacing of the taps: the soft edge of each tap's reach.
|
||||
|
||||
// Half the spacing of the taps softens the edge of each tap's reach
|
||||
let h = max(rmax * sqrt(PI_FX / f32(DOF_TAPS)) * 0.5, 0.5);
|
||||
var acc = textureSampleLevel(src, src_samp, i.uv, 0.0);
|
||||
var tot = 1.0;
|
||||
var near = 0.0;
|
||||
// The spiral turns per pixel (interleaved gradient noise) and per accumulated frame, so the
|
||||
// taps' pattern averages into smooth discs instead of showing as dots in bright highlights.
|
||||
|
||||
// Rotate the taps per pixel and frame so bright highlights average into smooth discs
|
||||
let ign = fract(52.9829189 * fract(dot(i.pos.xy, vec2<f32>(0.06711056, 0.00583715))));
|
||||
let turn = (ign + post.c.w * 0.618034) * 6.2831853;
|
||||
for (var k = 0; k < DOF_TAPS; k++) {
|
||||
let r = rmax * sqrt((f32(k) + 0.5) / f32(DOF_TAPS));
|
||||
let a = f32(k) * GOLDEN_ANGLE + turn;
|
||||
let uv = i.uv + vec2<f32>(cos(a), sin(a)) * (r * px);
|
||||
let z = texel(fx_a, uv).a;
|
||||
let z = abs(texel(fx_a, uv).a);
|
||||
let nearer = z > 0.0 && (zc <= 0.0 || z < zc);
|
||||
var size = abs(coc(z));
|
||||
if (!nearer) {
|
||||
@@ -136,20 +144,23 @@ fn fs_dof_gather(i: FsOut) -> DofOut {
|
||||
near = max(near, m * smoothstep(0.5, 1.5, size));
|
||||
}
|
||||
}
|
||||
|
||||
return DofOut(acc / tot, vec4<f32>(near));
|
||||
}
|
||||
|
||||
const PI_FX: f32 = 3.14159265;
|
||||
|
||||
// src: the sharp scene, fx_a: the gathered blur, fx_b: the G-buffer, fx_c: the near coverage.
|
||||
// Use G-buffer depth and near coverage to blend the half-resolution blur into the scene
|
||||
@fragment
|
||||
fn fs_dof(i: FsOut) -> @location(0) vec4<f32> {
|
||||
let sharp = texel_at(src, i.pos.xy);
|
||||
let f = max(smoothstep(0.5, 1.5, abs(coc(texel_at(fx_b, i.pos.xy).a))), textureSampleLevel(fx_c, src_samp, i.uv, 0.0).r);
|
||||
// In focus with nothing blurred in front: the sharp pixel itself (no blend through the
|
||||
// half-resolution blur at all).
|
||||
if (f <= 0.0) {
|
||||
let depth = abs(texel_at(fx_b, i.pos.xy).a);
|
||||
let blur_weight = max(smoothstep(0.5, 1.5, abs(coc(depth))), textureSampleLevel(fx_c, src_samp, i.uv, 0.0).r);
|
||||
|
||||
// Preserve the full-resolution pixel where no blur reaches it
|
||||
if (blur_weight <= 0.0) {
|
||||
return sharp;
|
||||
}
|
||||
return mix(sharp, textureSampleLevel(fx_a, src_samp, i.uv, 0.0), f);
|
||||
|
||||
return mix(sharp, textureSampleLevel(fx_a, src_samp, i.uv, 0.0), blur_weight);
|
||||
}
|
||||
@@ -26,6 +26,7 @@ struct Globals {
|
||||
refr: vec4<f32>, // x screen-space refraction on (1), y lods of the scene behind, z refraction depth (world units), w dielectric F0 scale
|
||||
highlight: vec4<f32>, // rgb highlighted set's edge color in the scene (before exposure and tone mapping), a opacity
|
||||
highlight_shift: vec4<f32>, // xy sideways shift of each highlight line copy (clip units), zw -
|
||||
set_hover: vec4<f32>, // rgb hovered set's scene color, a opacity
|
||||
bake_high: vec4<f32>, // bake mode: rgb high poly color, a -
|
||||
bake_matching_error: vec4<f32>, // rgb color where the bake's rays miss the high poly, a its strength (0 hidden)
|
||||
bake_cage: vec4<f32>, // rgb cage surface color, a opacity
|
||||
@@ -70,6 +71,7 @@ struct VOut {
|
||||
@location(1) nrm: vec3<f32>,
|
||||
@location(2) tan: vec4<f32>,
|
||||
@location(3) uv: vec2<f32>,
|
||||
@location(4) @interpolate(flat) hover: u32,
|
||||
};
|
||||
|
||||
// The vertex moved along its normal by the height channel (displacement).
|
||||
@@ -81,7 +83,7 @@ fn displaced(v: VIn) -> vec3<f32> {
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_mesh(v: VIn) -> VOut {
|
||||
fn vs_mesh(v: VIn, @builtin(instance_index) instance_index: u32) -> VOut {
|
||||
var o: VOut;
|
||||
let p = displaced(v);
|
||||
o.clip = g.view_proj * vec4<f32>(p, 1.0);
|
||||
@@ -89,6 +91,7 @@ fn vs_mesh(v: VIn) -> VOut {
|
||||
o.nrm = v.nrm;
|
||||
o.tan = v.tan;
|
||||
o.uv = v.uv;
|
||||
o.hover = instance_index;
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -350,16 +353,26 @@ fn unlit(c: vec4<f32>) -> Shaded {
|
||||
|
||||
fn mesh_color(i: VOut, front: bool) -> vec4<f32> {
|
||||
let o = shade_mesh(i, front);
|
||||
|
||||
// The subsurface pass restores the scattering light after blurring
|
||||
if (g.scatter.w > 0.5) {
|
||||
// The subsurface blur pass adds the scattering light back, blurred (fx.wgsl).
|
||||
return o.color - vec4<f32>(o.sss, 0.0);
|
||||
}
|
||||
|
||||
return o.color;
|
||||
}
|
||||
|
||||
const HOVERED_SET_INSTANCE: u32 = 1u;
|
||||
|
||||
@fragment
|
||||
fn fs_mesh(i: VOut, @builtin(front_facing) front: bool) -> @location(0) vec4<f32> {
|
||||
return mesh_color(i, front);
|
||||
let color = mesh_color(i, front);
|
||||
|
||||
if (i.hover == HOVERED_SET_INSTANCE) {
|
||||
return vec4<f32>(mix(color.rgb, g.set_hover.rgb * color.a, g.set_hover.a), color.a);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// The scene behind transmissive surfaces: everything but them (what they refract).
|
||||
@@ -373,17 +386,23 @@ fn fs_opaque(i: VOut, @builtin(front_facing) front: bool) -> @location(0) vec4<f
|
||||
return c;
|
||||
}
|
||||
|
||||
// The depth of field / subsurface G-buffer: rgb the scattering diffuse light (when the blur is
|
||||
// on), a the view depth (the clear value 0 marks the background).
|
||||
// G-buffer RGB holds scattering light and alpha holds view depth
|
||||
// Zero depth marks the background
|
||||
// Negative depth marks the hovered set when subsurface blur is active
|
||||
@fragment
|
||||
fn fs_gbuf(i: VOut, @builtin(front_facing) front: bool) -> @location(0) vec4<f32> {
|
||||
let z = max(dot(i.wpos - g.eye.xyz, g.fwd.xyz), 1e-4);
|
||||
var z = max(dot(i.wpos - g.eye.xyz, g.fwd.xyz), 1e-4);
|
||||
var sss = vec3<f32>(0.0);
|
||||
|
||||
if (g.scatter.w > 0.5) {
|
||||
sss = shade_mesh(i, front).sss;
|
||||
if (i.hover == HOVERED_SET_INSTANCE) {
|
||||
z = -z;
|
||||
}
|
||||
} else if (textureSample(t_base, samp, i.uv).a < hash12(i.clip.xy)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
return vec4<f32>(sss, z);
|
||||
}
|
||||
|
||||
|
||||
@@ -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), y accumulation sample, zw -
|
||||
e: vec4<f32>, // x orthographic camera, y accumulation sample, z hover tint opacity for the scattering composite, w -
|
||||
back_top: vec4<f32>, // rgb background color at the top of the view (linear), a -
|
||||
back_bottom: vec4<f32>, // rgb background color at the bottom of the view (linear), a -
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user