mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/sobel' into 'master'
Add experimental sobel filter See merge request veloren/veloren!3113
This commit is contained in:
commit
fc3da4bfce
@ -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)));
|
// 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() {
|
void main() {
|
||||||
/* if (medium.x == 1u) {
|
/* 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);
|
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
|
#endif
|
||||||
|
|
||||||
vec4 aa_color = aa_apply(t_src_color, s_src_color, uv * screen_res.xy, screen_res.xy);
|
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
|
// Bloom
|
||||||
#ifdef BLOOM_FACTOR
|
#ifdef BLOOM_FACTOR
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{AdminCommandState, EguiAction, EguiActions, EguiWindows};
|
use crate::{AdminCommandState, EguiAction, EguiActions};
|
||||||
use common::cmd::ChatCommand;
|
use common::cmd::ChatCommand;
|
||||||
use egui::{CollapsingHeader, CtxRef, Resize, Slider, Ui, Vec2, Window};
|
use egui::{CollapsingHeader, CtxRef, Resize, Slider, Ui, Vec2, Window};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@ -17,11 +17,11 @@ lazy_static! {
|
|||||||
pub fn draw_admin_commands_window(
|
pub fn draw_admin_commands_window(
|
||||||
ctx: &CtxRef,
|
ctx: &CtxRef,
|
||||||
state: &mut AdminCommandState,
|
state: &mut AdminCommandState,
|
||||||
windows: &mut EguiWindows,
|
open: &mut bool,
|
||||||
egui_actions: &mut EguiActions,
|
egui_actions: &mut EguiActions,
|
||||||
) {
|
) {
|
||||||
Window::new("Admin Commands")
|
Window::new("Admin Commands")
|
||||||
.open(&mut windows.admin_commands)
|
.open(open)
|
||||||
.default_width(400.0)
|
.default_width(400.0)
|
||||||
.default_height(600.0)
|
.default_height(600.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
|
29
voxygen/egui/src/experimental_shaders.rs
Normal file
29
voxygen/egui/src/experimental_shaders.rs
Normal 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,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
@ -5,6 +5,7 @@ compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at on
|
|||||||
|
|
||||||
mod admin;
|
mod admin;
|
||||||
mod character_states;
|
mod character_states;
|
||||||
|
mod experimental_shaders;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
use client::{Client, Join, World, WorldExt};
|
use client::{Client, Join, World, WorldExt};
|
||||||
@ -21,7 +22,7 @@ use egui::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
admin::draw_admin_commands_window, character_states::draw_char_state_group,
|
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::{
|
use common::{
|
||||||
cmd::ChatCommand,
|
cmd::ChatCommand,
|
||||||
@ -100,6 +101,7 @@ pub struct EguiWindows {
|
|||||||
egui_memory: bool,
|
egui_memory: bool,
|
||||||
frame_time: bool,
|
frame_time: bool,
|
||||||
ecs_entities: bool,
|
ecs_entities: bool,
|
||||||
|
experimental_shaders: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for EguiInnerState {
|
impl Default for EguiInnerState {
|
||||||
@ -131,6 +133,7 @@ pub enum EguiDebugShapeAction {
|
|||||||
pub enum EguiAction {
|
pub enum EguiAction {
|
||||||
ChatCommand { cmd: ChatCommand, args: Vec<String> },
|
ChatCommand { cmd: ChatCommand, args: Vec<String> },
|
||||||
DebugShape(EguiDebugShapeAction),
|
DebugShape(EguiDebugShapeAction),
|
||||||
|
SetExperimentalShader(String, bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -147,6 +150,7 @@ pub fn maintain(
|
|||||||
client: &Client,
|
client: &Client,
|
||||||
debug_info: Option<EguiDebugInfo>,
|
debug_info: Option<EguiDebugInfo>,
|
||||||
added_cylinder_shape_id: Option<u64>,
|
added_cylinder_shape_id: Option<u64>,
|
||||||
|
experimental_shaders: Vec<(String, bool)>,
|
||||||
) -> EguiActions {
|
) -> EguiActions {
|
||||||
#[cfg(not(feature = "use-dyn-lib"))]
|
#[cfg(not(feature = "use-dyn-lib"))]
|
||||||
{
|
{
|
||||||
@ -156,6 +160,7 @@ pub fn maintain(
|
|||||||
client,
|
client,
|
||||||
debug_info,
|
debug_info,
|
||||||
added_cylinder_shape_id,
|
added_cylinder_shape_id,
|
||||||
|
experimental_shaders,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +176,7 @@ pub fn maintain(
|
|||||||
&Client,
|
&Client,
|
||||||
Option<EguiDebugInfo>,
|
Option<EguiDebugInfo>,
|
||||||
Option<u64>,
|
Option<u64>,
|
||||||
|
Vec<(String, bool)>,
|
||||||
) -> EguiActions,
|
) -> EguiActions,
|
||||||
> = unsafe { lib.get(MAINTAIN_EGUI_FN) }.unwrap_or_else(|e| {
|
> = unsafe { lib.get(MAINTAIN_EGUI_FN) }.unwrap_or_else(|e| {
|
||||||
panic!(
|
panic!(
|
||||||
@ -189,6 +195,7 @@ pub fn maintain(
|
|||||||
client,
|
client,
|
||||||
debug_info,
|
debug_info,
|
||||||
added_cylinder_shape_id,
|
added_cylinder_shape_id,
|
||||||
|
experimental_shaders,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,6 +207,7 @@ pub fn maintain_egui_inner(
|
|||||||
client: &Client,
|
client: &Client,
|
||||||
debug_info: Option<EguiDebugInfo>,
|
debug_info: Option<EguiDebugInfo>,
|
||||||
added_cylinder_shape_id: Option<u64>,
|
added_cylinder_shape_id: Option<u64>,
|
||||||
|
experimental_shaders: Vec<(String, bool)>,
|
||||||
) -> EguiActions {
|
) -> EguiActions {
|
||||||
platform.begin_frame();
|
platform.begin_frame();
|
||||||
let ctx = &platform.context();
|
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.admin_commands, "Admin Commands");
|
||||||
ui.checkbox(&mut windows.ecs_entities, "ECS Entities");
|
ui.checkbox(&mut windows.ecs_entities, "ECS Entities");
|
||||||
ui.checkbox(&mut windows.frame_time, "Frame Time");
|
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();
|
ui.end_row();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let margin = ui.visuals().clip_rect_margin;
|
let margin = ui.visuals().clip_rect_margin;
|
||||||
|
|
||||||
let current_scroll = ui.clip_rect().top() - ui.min_rect().top() + 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(
|
draw_admin_commands_window(
|
||||||
ctx,
|
ctx,
|
||||||
&mut egui_state.admin_command_state,
|
&mut egui_state.admin_command_state,
|
||||||
&mut windows,
|
&mut windows.admin_commands,
|
||||||
&mut egui_actions,
|
&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(previous) = previous_selected_entity {
|
||||||
if let Some(debug_shape_id) = previous.debug_shape_id {
|
if let Some(debug_shape_id) = previous.debug_shape_id {
|
||||||
egui_actions
|
egui_actions
|
||||||
|
@ -417,13 +417,29 @@ struct OtherModes {
|
|||||||
///
|
///
|
||||||
/// You can enable these using Voxygen's `settings.ron`. See
|
/// You can enable these using Voxygen's `settings.ron`. See
|
||||||
/// [here](https://book.veloren.net/players/voxygen.html#experimental-shaders) for more information.
|
/// [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 {
|
pub enum ExperimentalShader {
|
||||||
/// Add brick-like normal mapping to the world.
|
/// Add brick-like normal mapping to the world.
|
||||||
Brickloren,
|
Brickloren,
|
||||||
/// Remove the default procedural noise from terrain.
|
/// Remove the default procedural noise from terrain.
|
||||||
NoNoise,
|
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,
|
CurvedWorld,
|
||||||
/// Adds extra detail to distant LoD (Level of Detail) terrain procedurally.
|
/// Adds extra detail to distant LoD (Level of Detail) terrain procedurally.
|
||||||
ProceduralLodDetail,
|
ProceduralLodDetail,
|
||||||
|
@ -1103,14 +1103,19 @@ impl PlayState for SessionState {
|
|||||||
// Maintain egui (debug interface)
|
// Maintain egui (debug interface)
|
||||||
#[cfg(feature = "egui-ui")]
|
#[cfg(feature = "egui-ui")]
|
||||||
if global_state.settings.interface.egui_enabled() {
|
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.client.borrow_mut(),
|
||||||
&mut self.scene,
|
&mut self.scene,
|
||||||
debug_info.map(|debug_info| EguiDebugInfo {
|
debug_info.map(|debug_info| EguiDebugInfo {
|
||||||
frame_time: debug_info.frame_time,
|
frame_time: debug_info.frame_time,
|
||||||
ping_ms: debug_info.ping_ms,
|
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
|
// Look for changes in the localization files
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
scene::{DebugShape, DebugShapeId, Scene},
|
scene::{DebugShape, DebugShapeId, Scene},
|
||||||
|
session::settings_change::{Graphics, SettingsChange},
|
||||||
|
settings::Settings,
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
use client::Client;
|
use client::Client;
|
||||||
@ -35,15 +37,34 @@ impl EguiState {
|
|||||||
client: &mut Client,
|
client: &mut Client,
|
||||||
scene: &mut Scene,
|
scene: &mut Scene,
|
||||||
debug_info: Option<EguiDebugInfo>,
|
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(
|
let egui_actions = voxygen_egui::maintain(
|
||||||
&mut self.platform,
|
&mut self.platform,
|
||||||
&mut self.egui_inner_state,
|
&mut self.egui_inner_state,
|
||||||
client,
|
client,
|
||||||
debug_info,
|
debug_info,
|
||||||
self.new_debug_shape_id.take(),
|
self.new_debug_shape_id.take(),
|
||||||
|
experimental_shaders,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut new_render_mode = None;
|
||||||
|
|
||||||
egui_actions
|
egui_actions
|
||||||
.actions
|
.actions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -68,6 +89,23 @@ impl EguiState {
|
|||||||
.set_context(DebugShapeId(id), pos, color, identity_ori);
|
.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))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user