Merge branch 'zesterer/experimental-shaders' into 'master'

More experimental shaders

See merge request veloren/veloren!3958
This commit is contained in:
Joshua Barretto 2023-05-31 18:51:31 +00:00
commit 21075638bd
9 changed files with 69 additions and 3 deletions

View File

@ -0,0 +1,8 @@
vec4 aa_apply(
texture2D tex, sampler smplr,
texture2D depth_tex, sampler depth_smplr,
vec2 fragCoord,
vec2 resolution
) {
return texture(sampler2D(tex, smplr), fragCoord / resolution);
}

View File

@ -4,5 +4,5 @@ vec4 aa_apply(
vec2 fragCoord,
vec2 resolution
) {
return texture(sampler2D(tex, smplr), fragCoord / resolution);
return texelFetch(sampler2D(tex, smplr), ivec2(fragCoord * textureSize(sampler2D(tex, smplr), 0).xy / resolution), 0);
}

View File

@ -95,6 +95,10 @@ void main() {
tgt_color = vec4(mat_colors[mat.a % 5u], 1);
return;
#endif
#ifdef EXPERIMENTAL_VIEWDEPTH
tgt_color = vec4(vec3(pow(clamp(depth_at(uv) / 524288.0, 0, 1), 0.3)), 1);
return;
#endif
#ifdef EXPERIMENTAL_BAREMINIMUM
tgt_color = vec4(color.rgb, 1);

View File

@ -27,6 +27,13 @@ float hash_two(uvec2 q) {
return float(n) * (1.0 / float(0xffffffffU));
}
float hash_three(uvec3 q) {
q *= uvec3(M1, M2, M3);
uint n = q.x ^ q.y ^ q.z;
n = n * (n ^ (n >> 15));
return float(n) * (1.0 / float(0xffffffffU));
}
float hash_fast(uvec3 q) {
q *= uvec3(M1, M2, M3);

View File

@ -166,6 +166,23 @@ vec3 aa_sample(vec2 uv, vec2 off) {
}
#endif
#ifdef EXPERIMENTAL_COLORDITHERING
float dither(ivec2 p, float level) {
// Bayer dithering
int dither[8][8] = {
{ 0, 32, 8, 40, 2, 34, 10, 42}, /* 8x8 Bayer ordered dithering */
{48, 16, 56, 24, 50, 18, 58, 26}, /* pattern. Each input pixel */
{12, 44, 4, 36, 14, 46, 6, 38}, /* is scaled to the 0..63 range */
{60, 28, 52, 20, 62, 30, 54, 22}, /* before looking in this table */
{ 3, 35, 11, 43, 1, 33, 9, 41}, /* to determine the action. */
{51, 19, 59, 27, 49, 17, 57, 25},
{15, 47, 7, 39, 13, 45, 5, 37},
{63, 31, 55, 23, 61, 29, 53, 21}
};
return step((dither[p.x % 8][p.y % 8]+1) * 0.016, level);
}
#endif
void main() {
#ifdef EXPERIMENTAL_BAREMINIMUM
tgt_color = vec4(texture(sampler2D(t_src_color, s_src_color), uv).rgb, 1);
@ -314,5 +331,16 @@ void main() {
#endif
#endif
#ifdef EXPERIMENTAL_NEWSPAPER
float nz = hash_three(uvec3(uvec2(uv * screen_res.xy), tick.x * dot(fract(uv * 10) + 5, vec2(1)) * 0.2));
nz = (nz > 0.5) ? (pow(nz * 2 - 1, 1.5) * 0.5 + 0.5) : (pow(nz * 2, 1/1.5) * 0.5);
final_color.rgb = vec3(step(nz, length(final_color.rgb))) * vec3(1, 0.5, 0.3);
#else
#ifdef EXPERIMENTAL_COLORDITHERING
float d = dither(ivec2(uv * screen_res.xy), sqrt(length(final_color.rgb) * 0.25));
final_color.rgb = vec3(d) * sqrt(normalize(final_color.rgb));
#endif
#endif
tgt_color = vec4(final_color.rgb, 1);
}

View File

@ -879,6 +879,7 @@ impl<'a> Widget for Video<'a> {
// interaction with greedy meshing, and may eventually be removed.
let mode_list = [
AaMode::None,
AaMode::Bilinear,
AaMode::Fxaa,
/* AaMode::MsaaX4,
AaMode::MsaaX8,
@ -887,7 +888,8 @@ impl<'a> Widget for Video<'a> {
AaMode::Hqx,
];
let mode_label_list = [
"No anti-aliasing",
"None",
"Bilinear",
"FXAA",
/* "MSAA x4",
"MSAA x8",

View File

@ -108,6 +108,15 @@ pub enum AaMode {
/// Screen-space technique that uses a combination of FXAA and
/// nearest-neighbour sample retargeting to produce crisp, clean upscaling.
FxUpscale,
/// Bilinear filtering.
///
/// Linear interpolation of the color buffer in each axis to determine the
/// pixel.
Bilinear,
/// Nearest-neighbour filtering.
///
/// The colour of each pixel is determined by the colour of the spatially
/// closest texel in the color buffer.
#[serde(other)]
None,
}
@ -115,7 +124,7 @@ pub enum AaMode {
impl AaMode {
pub fn samples(&self) -> u32 {
match self {
AaMode::None | AaMode::Fxaa | AaMode::Hqx | AaMode::FxUpscale => 1,
AaMode::None | AaMode::Bilinear | AaMode::Fxaa | AaMode::Hqx | AaMode::FxUpscale => 1,
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,
@ -515,6 +524,8 @@ pub enum ExperimentalShader {
ViewNormals,
/// Show gbuffer materials.
ViewMaterials,
/// Show gbuffer depth.
ViewDepth,
/// Rather than fading out screen-space reflections at view space borders,
/// smear screen space to cover the reflection vector.
SmearReflections,
@ -526,4 +537,8 @@ pub enum ExperimentalShader {
/// Prefer using physically-based values for various rendering parameters,
/// where possible.
Photorealistic,
/// A noisy newspaper effect.
Newspaper,
/// A colorful dithering effect.
ColorDithering,
}

View File

@ -258,6 +258,7 @@ impl ShaderModules {
let anti_alias = shaders
.get(match pipeline_modes.aa {
AaMode::None => "antialias.none",
AaMode::Bilinear => "antialias.bilinear",
AaMode::Fxaa => "antialias.fxaa",
AaMode::MsaaX4 => "antialias.msaa-x4",
AaMode::MsaaX8 => "antialias.msaa-x8",

View File

@ -38,6 +38,7 @@ impl assets::Compound for Shaders {
"include.point_glow",
"include.fxaa",
"antialias.none",
"antialias.bilinear",
"antialias.fxaa",
"antialias.msaa-x4",
"antialias.msaa-x8",