Merge branch 'imbris/sobel' into 'master'

Add experimental sobel filter

See merge request veloren/veloren!3113
This commit is contained in:
Imbris 2022-01-24 02:42:54 +00:00
commit fc3da4bfce
7 changed files with 136 additions and 11 deletions

View File

@ -154,6 +154,12 @@ vec3 _illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitte
// return /*srgb_to_linear*/(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma)));
}
#ifdef EXPERIMENTAL_SOBEL
vec3 aa_sample(vec2 uv, vec2 off) {
return aa_apply(t_src_color, s_src_color, uv * screen_res.xy + off, screen_res.xy).rgb;
}
#endif
void main() {
/* if (medium.x == 1u) {
uv = clamp(uv + vec2(sin(uv.y * 16.0 + tick.x), sin(uv.x * 24.0 + tick.x)) * 0.005, 0, 1);
@ -199,6 +205,22 @@ void main() {
#endif
vec4 aa_color = aa_apply(t_src_color, s_src_color, uv * screen_res.xy, screen_res.xy);
#ifdef EXPERIMENTAL_SOBEL
vec3 s[8];
s[0] = aa_sample(uv, vec2(-1, 1));
s[1] = aa_sample(uv, vec2( 0, 1));
s[2] = aa_sample(uv, vec2( 1, 1));
s[3] = aa_sample(uv, vec2(-1, 0));
s[4] = aa_sample(uv, vec2( 1, 0));
s[5] = aa_sample(uv, vec2(-1, -1));
s[6] = aa_sample(uv, vec2( 0, -1));
s[7] = aa_sample(uv, vec2( 1, -1));
vec3 gx = s[0] + s[3] * 2.0 + s[5] - s[2] - s[4] * 2 - s[7];
vec3 gy = s[0] + s[1] * 2.0 + s[2] - s[5] - s[6] * 2 - s[7];
float mag = length(gx) + length(gy);
aa_color.rgb = mix(vec3(0.9), aa_color.rgb * 0.8, clamp(1.0 - mag * 0.3, 0.0, 1.0));
#endif
// Bloom
#ifdef BLOOM_FACTOR

View File

@ -1,4 +1,4 @@
use crate::{AdminCommandState, EguiAction, EguiActions, EguiWindows};
use crate::{AdminCommandState, EguiAction, EguiActions};
use common::cmd::ChatCommand;
use egui::{CollapsingHeader, CtxRef, Resize, Slider, Ui, Vec2, Window};
use lazy_static::lazy_static;
@ -17,11 +17,11 @@ lazy_static! {
pub fn draw_admin_commands_window(
ctx: &CtxRef,
state: &mut AdminCommandState,
windows: &mut EguiWindows,
open: &mut bool,
egui_actions: &mut EguiActions,
) {
Window::new("Admin Commands")
.open(&mut windows.admin_commands)
.open(open)
.default_width(400.0)
.default_height(600.0)
.show(ctx, |ui| {

View File

@ -0,0 +1,29 @@
use crate::{EguiAction, EguiActions};
use egui::{CtxRef, Vec2, Window};
pub fn draw_experimental_shaders_window(
ctx: &CtxRef,
open: &mut bool,
egui_actions: &mut EguiActions,
experimental_shaders: &[(String, bool)],
) {
Window::new("Experimental Shaders")
.open(open)
.default_width(250.0)
.default_height(600.0)
.show(ctx, |ui| {
ui.spacing_mut().item_spacing = Vec2::new(10.0, 10.0);
experimental_shaders.iter().for_each(|(shader, enabled)| {
let mut enabled_mut = *enabled;
ui.checkbox(&mut enabled_mut, shader);
if enabled_mut != *enabled {
egui_actions.actions.push(EguiAction::SetExperimentalShader(
shader.into(),
enabled_mut,
));
}
})
});
}

View File

@ -5,6 +5,7 @@ compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at on
mod admin;
mod character_states;
mod experimental_shaders;
mod widgets;
use client::{Client, Join, World, WorldExt};
@ -21,7 +22,7 @@ use egui::{
use crate::{
admin::draw_admin_commands_window, character_states::draw_char_state_group,
widgets::two_col_row,
experimental_shaders::draw_experimental_shaders_window, widgets::two_col_row,
};
use common::{
cmd::ChatCommand,
@ -100,6 +101,7 @@ pub struct EguiWindows {
egui_memory: bool,
frame_time: bool,
ecs_entities: bool,
experimental_shaders: bool,
}
impl Default for EguiInnerState {
@ -131,6 +133,7 @@ pub enum EguiDebugShapeAction {
pub enum EguiAction {
ChatCommand { cmd: ChatCommand, args: Vec<String> },
DebugShape(EguiDebugShapeAction),
SetExperimentalShader(String, bool),
}
#[derive(Default)]
@ -147,6 +150,7 @@ pub fn maintain(
client: &Client,
debug_info: Option<EguiDebugInfo>,
added_cylinder_shape_id: Option<u64>,
experimental_shaders: Vec<(String, bool)>,
) -> EguiActions {
#[cfg(not(feature = "use-dyn-lib"))]
{
@ -156,6 +160,7 @@ pub fn maintain(
client,
debug_info,
added_cylinder_shape_id,
experimental_shaders,
)
}
@ -171,6 +176,7 @@ pub fn maintain(
&Client,
Option<EguiDebugInfo>,
Option<u64>,
Vec<(String, bool)>,
) -> EguiActions,
> = unsafe { lib.get(MAINTAIN_EGUI_FN) }.unwrap_or_else(|e| {
panic!(
@ -189,6 +195,7 @@ pub fn maintain(
client,
debug_info,
added_cylinder_shape_id,
experimental_shaders,
)
}
}
@ -200,6 +207,7 @@ pub fn maintain_egui_inner(
client: &Client,
debug_info: Option<EguiDebugInfo>,
added_cylinder_shape_id: Option<u64>,
experimental_shaders: Vec<(String, bool)>,
) -> EguiActions {
platform.begin_frame();
let ctx = &platform.context();
@ -244,6 +252,7 @@ pub fn maintain_egui_inner(
ui.checkbox(&mut windows.admin_commands, "Admin Commands");
ui.checkbox(&mut windows.ecs_entities, "ECS Entities");
ui.checkbox(&mut windows.frame_time, "Frame Time");
ui.checkbox(&mut windows.experimental_shaders, "Experimental Shaders");
});
});
@ -412,7 +421,6 @@ pub fn maintain_egui_inner(
ui.end_row();
}
});
let margin = ui.visuals().clip_rect_margin;
let current_scroll = ui.clip_rect().top() - ui.min_rect().top() + margin;
@ -434,10 +442,17 @@ pub fn maintain_egui_inner(
draw_admin_commands_window(
ctx,
&mut egui_state.admin_command_state,
&mut windows,
&mut windows.admin_commands,
&mut egui_actions,
);
draw_experimental_shaders_window(
ctx,
&mut windows.experimental_shaders,
&mut egui_actions,
&experimental_shaders,
);
if let Some(previous) = previous_selected_entity {
if let Some(debug_shape_id) = previous.debug_shape_id {
egui_actions

View File

@ -417,13 +417,29 @@ struct OtherModes {
///
/// You can enable these using Voxygen's `settings.ron`. See
/// [here](https://book.veloren.net/players/voxygen.html#experimental-shaders) for more information.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
strum::EnumIter,
strum::Display,
strum::EnumString,
)]
pub enum ExperimentalShader {
/// Add brick-like normal mapping to the world.
Brickloren,
/// Remove the default procedural noise from terrain.
NoNoise,
/// Simulated a curved world.
/// Add a sobel filter that draws lines in post-process by detecting edges
/// inbetween colors. This does perform 8 times more texture samples in
/// post-processing so there is potentially a significant performance
/// impact especially with anti aliasing enabled.
Sobel,
/// Simulate a curved world.
CurvedWorld,
/// Adds extra detail to distant LoD (Level of Detail) terrain procedurally.
ProceduralLodDetail,

View File

@ -1103,14 +1103,19 @@ impl PlayState for SessionState {
// Maintain egui (debug interface)
#[cfg(feature = "egui-ui")]
if global_state.settings.interface.egui_enabled() {
global_state.egui_state.maintain(
let settings_change = global_state.egui_state.maintain(
&mut self.client.borrow_mut(),
&mut self.scene,
debug_info.map(|debug_info| EguiDebugInfo {
frame_time: debug_info.frame_time,
ping_ms: debug_info.ping_ms,
}),
&global_state.settings,
);
if let Some(settings_change) = settings_change {
settings_change.process(global_state, self);
}
}
// Look for changes in the localization files

View File

@ -1,5 +1,7 @@
use crate::{
scene::{DebugShape, DebugShapeId, Scene},
session::settings_change::{Graphics, SettingsChange},
settings::Settings,
window::Window,
};
use client::Client;
@ -35,15 +37,34 @@ impl EguiState {
client: &mut Client,
scene: &mut Scene,
debug_info: Option<EguiDebugInfo>,
) {
settings: &Settings,
) -> Option<SettingsChange> {
use crate::render::ExperimentalShader;
use strum::IntoEnumIterator;
let experimental_shaders = ExperimentalShader::iter()
.map(|s| {
(
s.to_string(),
settings
.graphics
.render_mode
.experimental_shaders
.contains(&s),
)
})
.collect();
let egui_actions = voxygen_egui::maintain(
&mut self.platform,
&mut self.egui_inner_state,
client,
debug_info,
self.new_debug_shape_id.take(),
experimental_shaders,
);
let mut new_render_mode = None;
egui_actions
.actions
.into_iter()
@ -68,6 +89,23 @@ impl EguiState {
.set_context(DebugShapeId(id), pos, color, identity_ori);
},
},
})
EguiAction::SetExperimentalShader(shader, enabled) => {
// TODO Rust 2021
use core::convert::TryFrom;
if let Ok(shader) = ExperimentalShader::try_from(shader.as_str()) {
let shaders = &mut new_render_mode
.get_or_insert_with(|| settings.graphics.render_mode.clone())
.experimental_shaders;
if enabled {
shaders.insert(shader);
} else {
shaders.remove(&shader);
}
}
},
});
new_render_mode.map(|rm| SettingsChange::Graphics(Graphics::ChangeRenderMode(Box::new(rm))))
}
}