chore(release): v2.0.0
This commit is contained in:
parent
a6f33284a7
commit
7fbf34ff2e
81 changed files with 16727 additions and 3280 deletions
|
|
@ -30,12 +30,20 @@ struct SceneAndBlurTargets {
|
|||
half_h: u32,
|
||||
quarter_w: u32,
|
||||
quarter_h: u32,
|
||||
eighth_w: u32,
|
||||
eighth_h: u32,
|
||||
sixteenth_w: u32,
|
||||
sixteenth_h: u32,
|
||||
scene_tex: glow::Texture,
|
||||
scene_fbo: glow::Framebuffer,
|
||||
half_tex: glow::Texture,
|
||||
half_fbo: glow::Framebuffer,
|
||||
quarter_tex: glow::Texture,
|
||||
quarter_fbo: glow::Framebuffer,
|
||||
eighth_tex: glow::Texture,
|
||||
eighth_fbo: glow::Framebuffer,
|
||||
sixteenth_tex: glow::Texture,
|
||||
sixteenth_fbo: glow::Framebuffer,
|
||||
byte_size: u64,
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +55,10 @@ impl SceneAndBlurTargets {
|
|||
let half_h = (height / 2).max(1);
|
||||
let quarter_w = (width / 4).max(1);
|
||||
let quarter_h = (height / 4).max(1);
|
||||
let eighth_w = (width / 8).max(1);
|
||||
let eighth_h = (height / 8).max(1);
|
||||
let sixteenth_w = (width / 16).max(1);
|
||||
let sixteenth_h = (height / 16).max(1);
|
||||
|
||||
let (scene_tex, scene_fbo) = create_rgba8_fbo(gl, width, height, "scene")?;
|
||||
let (half_tex, half_fbo) = match create_rgba8_fbo(gl, half_w, half_h, "blur_half") {
|
||||
|
|
@ -68,10 +80,40 @@ impl SceneAndBlurTargets {
|
|||
return Err(e);
|
||||
}
|
||||
};
|
||||
let (eighth_tex, eighth_fbo) =
|
||||
match create_rgba8_fbo(gl, eighth_w, eighth_h, "blur_eighth") {
|
||||
Ok(pair) => pair,
|
||||
Err(e) => {
|
||||
gl.delete_framebuffer(quarter_fbo);
|
||||
gl.delete_texture(quarter_tex);
|
||||
gl.delete_framebuffer(half_fbo);
|
||||
gl.delete_texture(half_tex);
|
||||
gl.delete_framebuffer(scene_fbo);
|
||||
gl.delete_texture(scene_tex);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
let (sixteenth_tex, sixteenth_fbo) =
|
||||
match create_rgba8_fbo(gl, sixteenth_w, sixteenth_h, "blur_sixteenth") {
|
||||
Ok(pair) => pair,
|
||||
Err(e) => {
|
||||
gl.delete_framebuffer(eighth_fbo);
|
||||
gl.delete_texture(eighth_tex);
|
||||
gl.delete_framebuffer(quarter_fbo);
|
||||
gl.delete_texture(quarter_tex);
|
||||
gl.delete_framebuffer(half_fbo);
|
||||
gl.delete_texture(half_tex);
|
||||
gl.delete_framebuffer(scene_fbo);
|
||||
gl.delete_texture(scene_tex);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
let byte_size = ((width as u64) * (height as u64)
|
||||
+ (half_w as u64) * (half_h as u64)
|
||||
+ (quarter_w as u64) * (quarter_h as u64))
|
||||
+ (quarter_w as u64) * (quarter_h as u64)
|
||||
+ (eighth_w as u64) * (eighth_h as u64)
|
||||
+ (sixteenth_w as u64) * (sixteenth_h as u64))
|
||||
* 4;
|
||||
|
||||
Ok(Self {
|
||||
|
|
@ -81,12 +123,20 @@ impl SceneAndBlurTargets {
|
|||
half_h,
|
||||
quarter_w,
|
||||
quarter_h,
|
||||
eighth_w,
|
||||
eighth_h,
|
||||
sixteenth_w,
|
||||
sixteenth_h,
|
||||
scene_tex,
|
||||
scene_fbo,
|
||||
half_tex,
|
||||
half_fbo,
|
||||
quarter_tex,
|
||||
quarter_fbo,
|
||||
eighth_tex,
|
||||
eighth_fbo,
|
||||
sixteenth_tex,
|
||||
sixteenth_fbo,
|
||||
byte_size,
|
||||
})
|
||||
}
|
||||
|
|
@ -98,6 +148,10 @@ impl SceneAndBlurTargets {
|
|||
gl.delete_texture(self.half_tex);
|
||||
gl.delete_framebuffer(self.quarter_fbo);
|
||||
gl.delete_texture(self.quarter_tex);
|
||||
gl.delete_framebuffer(self.eighth_fbo);
|
||||
gl.delete_texture(self.eighth_tex);
|
||||
gl.delete_framebuffer(self.sixteenth_fbo);
|
||||
gl.delete_texture(self.sixteenth_tex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -563,7 +617,14 @@ impl UiGlRenderer {
|
|||
let Some(bt) = &self.scene_blur else {
|
||||
return;
|
||||
};
|
||||
let offset = radius.clamp(0.5, 4.0);
|
||||
let r = radius.clamp(0.5, 4.0);
|
||||
let (levels, offset) = if r > 3.0 {
|
||||
(4u32, (0.95 + (r - 3.0) * 0.45).clamp(0.95, 1.5))
|
||||
} else if r > 2.0 {
|
||||
(3u32, (0.90 + (r - 2.0) * 0.45).clamp(0.90, 1.45))
|
||||
} else {
|
||||
(2u32, (0.75 + r * 0.55).clamp(0.75, 1.85))
|
||||
};
|
||||
|
||||
gl.disable(glow::BLEND);
|
||||
gl.use_program(Some(self.blur_program));
|
||||
|
|
@ -571,44 +632,47 @@ impl UiGlRenderer {
|
|||
gl.active_texture(glow::TEXTURE0);
|
||||
gl.bind_vertex_array(Some(self.fullscreen_vao));
|
||||
|
||||
// Pass 1: Downsample Full -> Half
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(bt.half_fbo));
|
||||
gl.viewport(0, 0, bt.half_w as i32, bt.half_h as i32);
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(bt.scene_tex));
|
||||
gl.uniform_2_f32(
|
||||
self.loc_blur_texel_size.as_ref(),
|
||||
1.0 / bt.width.max(1) as f32,
|
||||
1.0 / bt.height.max(1) as f32,
|
||||
);
|
||||
gl.uniform_1_f32(self.loc_blur_offset.as_ref(), offset);
|
||||
gl.uniform_1_i32(self.loc_blur_mode.as_ref(), 0);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
let run_pass = |dst_fbo: glow::Framebuffer,
|
||||
dst_w: u32,
|
||||
dst_h: u32,
|
||||
src_tex: glow::Texture,
|
||||
src_w: u32,
|
||||
src_h: u32,
|
||||
mode: i32| {
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(dst_fbo));
|
||||
gl.viewport(0, 0, dst_w as i32, dst_h as i32);
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(src_tex));
|
||||
gl.uniform_2_f32(
|
||||
self.loc_blur_texel_size.as_ref(),
|
||||
1.0 / src_w.max(1) as f32,
|
||||
1.0 / src_h.max(1) as f32,
|
||||
);
|
||||
gl.uniform_1_f32(self.loc_blur_offset.as_ref(), offset);
|
||||
gl.uniform_1_i32(self.loc_blur_mode.as_ref(), mode);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
};
|
||||
|
||||
// Pass 2: Downsample Half -> Quarter
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(bt.quarter_fbo));
|
||||
gl.viewport(0, 0, bt.quarter_w as i32, bt.quarter_h as i32);
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(bt.half_tex));
|
||||
gl.uniform_2_f32(
|
||||
self.loc_blur_texel_size.as_ref(),
|
||||
1.0 / bt.half_w.max(1) as f32,
|
||||
1.0 / bt.half_h.max(1) as f32,
|
||||
);
|
||||
gl.uniform_1_f32(self.loc_blur_offset.as_ref(), offset * 1.25);
|
||||
gl.uniform_1_i32(self.loc_blur_mode.as_ref(), 0);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
// Downsample 1: Full -> Half
|
||||
run_pass(bt.half_fbo, bt.half_w, bt.half_h, bt.scene_tex, bt.width, bt.height, 0);
|
||||
// Downsample 2: Half -> Quarter
|
||||
run_pass(bt.quarter_fbo, bt.quarter_w, bt.quarter_h, bt.half_tex, bt.half_w, bt.half_h, 0);
|
||||
|
||||
// Pass 3: Upsample Quarter -> Half (BLUR_TEXTURE_ID samples half_tex with linear filter)
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(bt.half_fbo));
|
||||
gl.viewport(0, 0, bt.half_w as i32, bt.half_h as i32);
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(bt.quarter_tex));
|
||||
gl.uniform_2_f32(
|
||||
self.loc_blur_texel_size.as_ref(),
|
||||
1.0 / bt.quarter_w.max(1) as f32,
|
||||
1.0 / bt.quarter_h.max(1) as f32,
|
||||
);
|
||||
gl.uniform_1_f32(self.loc_blur_offset.as_ref(), offset * 1.25);
|
||||
gl.uniform_1_i32(self.loc_blur_mode.as_ref(), 1);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
if levels >= 3 {
|
||||
// Downsample 3: Quarter -> Eighth
|
||||
run_pass(bt.eighth_fbo, bt.eighth_w, bt.eighth_h, bt.quarter_tex, bt.quarter_w, bt.quarter_h, 0);
|
||||
}
|
||||
if levels >= 4 {
|
||||
// Downsample 4: Eighth -> Sixteenth
|
||||
run_pass(bt.sixteenth_fbo, bt.sixteenth_w, bt.sixteenth_h, bt.eighth_tex, bt.eighth_w, bt.eighth_h, 0);
|
||||
// Upsample: Sixteenth -> Eighth
|
||||
run_pass(bt.eighth_fbo, bt.eighth_w, bt.eighth_h, bt.sixteenth_tex, bt.sixteenth_w, bt.sixteenth_h, 1);
|
||||
}
|
||||
if levels >= 3 {
|
||||
// Upsample: Eighth -> Quarter
|
||||
run_pass(bt.quarter_fbo, bt.quarter_w, bt.quarter_h, bt.eighth_tex, bt.eighth_w, bt.eighth_h, 1);
|
||||
}
|
||||
// Final Upsample: Quarter -> Half (BLUR_TEXTURE_ID samples half_tex with linear filter)
|
||||
run_pass(bt.half_fbo, bt.half_w, bt.half_h, bt.quarter_tex, bt.quarter_w, bt.quarter_h, 1);
|
||||
|
||||
gl.bind_vertex_array(None);
|
||||
gl.bind_texture(glow::TEXTURE_2D, None);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue