From 26a98a3d9bdc5d4300e418a0cc5769b858e9bac1 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 30 Dec 2022 15:33:23 +0000 Subject: [PATCH] Use normal and material gbuffer to improve quality of SSR --- assets/voxygen/shaders/clouds-frag.glsl | 37 ++++++++++++++--- assets/voxygen/shaders/figure-frag.glsl | 2 + assets/voxygen/shaders/fluid-frag/cheap.glsl | 2 + assets/voxygen/shaders/fluid-frag/shiny.glsl | 6 ++- assets/voxygen/shaders/include/constants.glsl | 6 +++ assets/voxygen/shaders/lod-object-frag.glsl | 2 + assets/voxygen/shaders/lod-terrain-frag.glsl | 2 + assets/voxygen/shaders/particle-frag.glsl | 2 + assets/voxygen/shaders/skybox-frag.glsl | 2 + assets/voxygen/shaders/sprite-frag.glsl | 2 + assets/voxygen/shaders/terrain-frag.glsl | 2 + voxygen/src/render/mod.rs | 2 + voxygen/src/render/pipelines/clouds.rs | 16 ++++++++ voxygen/src/render/pipelines/debug.rs | 17 +++++--- voxygen/src/render/pipelines/figure.rs | 17 +++++--- voxygen/src/render/pipelines/fluid.rs | 39 ++++++++++-------- voxygen/src/render/pipelines/lod_object.rs | 17 +++++--- voxygen/src/render/pipelines/lod_terrain.rs | 17 +++++--- voxygen/src/render/pipelines/particle.rs | 41 +++++++++++-------- voxygen/src/render/pipelines/skybox.rs | 31 ++++++++------ voxygen/src/render/pipelines/sprite.rs | 41 +++++++++++-------- voxygen/src/render/pipelines/terrain.rs | 17 +++++--- voxygen/src/render/renderer.rs | 23 +++++++---- voxygen/src/render/renderer/drawer.rs | 24 +++++++---- voxygen/src/render/renderer/locals.rs | 4 ++ 25 files changed, 261 insertions(+), 110 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index b0ef33fa4e..56bd28d60e 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -46,6 +46,9 @@ uniform u_locals { mat4 all_mat_inv; }; +layout(set = 2, binding = 5) +uniform utexture2D t_src_mat; + layout(location = 0) out vec4 tgt_color; vec3 wpos_at(vec2 uv) { @@ -79,6 +82,14 @@ float depth_at(vec2 uv) { void main() { vec4 color = texture(sampler2D(t_src_color, s_src_color), uv); + uvec2 mat_sz = textureSize(usampler2D(t_src_mat, s_src_depth), 0); + uvec4 mat = texelFetch(usampler2D(t_src_mat, s_src_depth), clamp(ivec2(uv * mat_sz), ivec2(0), ivec2(mat_sz) - 1), 0); + + #ifdef EXPERIMENTAL_VIEWNORMALS + color.rgb = vec3(mat.xyz) / 255.0; + return; + #endif + #ifdef EXPERIMENTAL_BAREMINIMUM tgt_color = vec4(color.rgb, 1); return; @@ -126,8 +137,8 @@ void main() { cloud_blend = 1.0 - color.a; #if (FLUID_MODE >= FLUID_MODE_MEDIUM || REFLECTION_MODE >= REFLECTION_MODE_MEDIUM) - if (dir.z < 0.0) { - vec3 surf_norm = normalize(vec3(nz * 0.3 / (1.0 + dist * 0.1), 1)); + if (mat.a != MAT_SKY) { + vec3 surf_norm = vec3(texelFetch(usampler2D(t_src_mat, s_src_depth), clamp(ivec2(uv * mat_sz), ivec2(0), ivec2(mat_sz) - 1), 0).xyz) / 127.0 - 1.0; vec3 refl_dir = reflect(dir, surf_norm); vec4 clip = (all_mat * vec4(cam_pos.xyz + refl_dir, 1.0)); @@ -180,11 +191,27 @@ void main() { clamp((new_dist - dist * 0.5) / (dist * 0.5), 0.0, 1.0) ); + vec3 refl_col; + // Did we hit a surface during reflection? if (merge > 0.0) { - vec3 new_col = texelFetch(sampler2D(t_src_color, s_src_color), clamp(ivec2(new_uv * col_sz), ivec2(0), ivec2(col_sz) - 1), 0).rgb; - new_col = get_cloud_color(new_col.rgb, refl_dir, wpos, time_of_day.x, distance(new_wpos, wpos.xyz), 1.0); - color.rgb = mix(color.rgb, new_col, min(merge * (color.a * 2.0), 0.75)); + // Yes: grab the new material from screen space + uvec4 new_mat = texelFetch(usampler2D(t_src_mat, s_src_depth), clamp(ivec2(new_uv * col_sz), ivec2(0), ivec2(col_sz) - 1), 0); + // If it's the sky, just go determine the sky color analytically to avoid sampling the incomplete skybox + // Otherwise, pull the color from the screen-space color buffer + if (new_mat.a == MAT_SKY) { + refl_col = get_sky_color(refl_dir, time_of_day.x, wpos, vec3(-100000), 0.125, true, 1.0, true, 1.0); + } else { + refl_col = texelFetch(sampler2D(t_src_color, s_src_color), clamp(ivec2(new_uv * col_sz), ivec2(0), ivec2(col_sz) - 1), 0).rgb; + } + // Apply clouds to reflected colour + refl_col = get_cloud_color(refl_col, refl_dir, wpos, time_of_day.x, distance(new_wpos, wpos.xyz), 1.0); + } else { + // No: assume that anything off-screen is the colour of the sky + refl_col = min(get_sky_color(refl_dir, time_of_day.x, wpos - focus_off.xyz, vec3(-100000), 0.125, true, 1.0, true, 1.0), vec3(1)); + // Apply clouds to reflection + refl_col = get_cloud_color(refl_col, refl_dir, wpos, time_of_day.x, 100000.0, 1.0); } + color.rgb = mix(color.rgb, refl_col, min(color.a * 2.0, 0.75)); cloud_blend = 1; } else { #else diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 52da9e37e6..3c16722dc1 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -83,6 +83,7 @@ uniform u_bones { }; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; void main() { // vec2 texSize = textureSize(t_col_light, 0); @@ -299,4 +300,5 @@ void main() { // } tgt_color = vec4(surf_color, 1.0); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_FIGURE); } diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index 1e4f5b6a8f..a89b3308fb 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -46,6 +46,7 @@ uniform u_locals { }; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -238,4 +239,5 @@ void main() { vec4 color = vec4(surf_color, opacity); tgt_color = color; + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_FLUID); } diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index d1b64fb837..16f7e8415f 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -48,6 +48,7 @@ uniform u_locals { }; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -82,14 +83,14 @@ vec4 wave_height(vec4 posx, vec4 posy) { posy *= 0.2; const float drag_factor = 0.035; const int iters = 21; - const float scale = 25.0; + const float scale = 15.0; #else float speed = 2.0; posx *= 0.3; posy *= 0.3; const float drag_factor = 0.04; const int iters = 11; - const float scale = 5.0; + const float scale = 3.0; #endif const float iter_shift = (3.14159 * 2.0) / 7.3; @@ -427,4 +428,5 @@ void main() { vec4 color = mix(vec4(reflect_color, 1.0), vec4(vec3(0), 1.0 / (1.0 + diffuse_light * 0.25)), passthrough); */ tgt_color = color; + tgt_mat = uvec4(uvec3((norm + 1.0) * 127.0), MAT_FLUID); } diff --git a/assets/voxygen/shaders/include/constants.glsl b/assets/voxygen/shaders/include/constants.glsl index e727e49563..d8e7585311 100644 --- a/assets/voxygen/shaders/include/constants.glsl +++ b/assets/voxygen/shaders/include/constants.glsl @@ -52,6 +52,12 @@ #define MEDIUM_AIR 0 #define MEDIUM_WATER 1 +#define MAT_SKY 0 +#define MAT_BLOCK 1 +#define MAT_FLUID 2 +#define MAT_FIGURE 3 +#define MAT_LOD 4 + // An arbitrary value that represents a very far distance (at least as far as the player should be able to see) without // being too far that we end up with precision issues (used in clouds and elsewhere). #define DIST_CAP 50000 diff --git a/assets/voxygen/shaders/lod-object-frag.glsl b/assets/voxygen/shaders/lod-object-frag.glsl index 9e445870b7..50660b6aa1 100644 --- a/assets/voxygen/shaders/lod-object-frag.glsl +++ b/assets/voxygen/shaders/lod-object-frag.glsl @@ -25,6 +25,7 @@ layout(location = 3) in vec3 model_pos; layout(location = 4) in float snow_cover; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -123,4 +124,5 @@ void main() { surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light); tgt_color = vec4(surf_color, 1.0); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_LOD); } diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index 4318c2967f..ffd032978d 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -31,6 +31,7 @@ layout(location = 2) in float pull_down; // in vec4 f_square; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; /// const vec4 sun_pos = vec4(0); // const vec4 light_pos[2] = vec4[](vec4(0), vec4(0)/*, vec3(00), vec3(0), vec3(0), vec3(0)*/); @@ -687,4 +688,5 @@ void main() { // color = surf_color; tgt_color = vec4(surf_color, surf_alpha); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_LOD); } diff --git a/assets/voxygen/shaders/particle-frag.glsl b/assets/voxygen/shaders/particle-frag.glsl index 83f8ff6e1c..4b061fe4b7 100644 --- a/assets/voxygen/shaders/particle-frag.glsl +++ b/assets/voxygen/shaders/particle-frag.glsl @@ -26,6 +26,7 @@ layout(location = 2) in vec4 f_col; layout(location = 3) in float f_reflect; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -106,4 +107,5 @@ void main() { // Temporarily disable particle transparency to avoid artifacts tgt_color = vec4(surf_color, 1.0 /*f_col.a*/); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_BLOCK); } diff --git a/assets/voxygen/shaders/skybox-frag.glsl b/assets/voxygen/shaders/skybox-frag.glsl index 60930b469d..704b184d25 100644 --- a/assets/voxygen/shaders/skybox-frag.glsl +++ b/assets/voxygen/shaders/skybox-frag.glsl @@ -23,6 +23,7 @@ layout(location = 0) in vec3 f_pos; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; void main() { #ifdef EXPERIMENTAL_BAREMINIMUM @@ -56,4 +57,5 @@ void main() { vec3 wpos = cam_pos.xyz + /*normalize(f_pos)*/cam_dir * dist; tgt_color = vec4(cam_attenuation * get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, wpos, 1.0, true, refractionIndex, false, 1.0), 1.0); + tgt_mat = uvec4(uvec3(0), MAT_SKY); } diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 700a5eee05..961a8e32e1 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -32,6 +32,7 @@ layout(set = 2, binding = 1) uniform sampler s_col_light; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -125,5 +126,6 @@ void main() { surf_color += f_select * (surf_color + 0.1) * vec3(0.15, 0.15, 0.15); tgt_color = vec4(surf_color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (sprite_render_distance - FADE_DIST)) / FADE_DIST, 0, 1)); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_FIGURE); //tgt_color = vec4(-f_norm, 1.0); } diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index d46de874d0..54505c8dcb 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -58,6 +58,7 @@ uniform u_locals { }; layout(location = 0) out vec4 tgt_color; +layout(location = 1) out uvec4 tgt_mat; #include #include @@ -530,5 +531,6 @@ void main() { surf_color += f_select * (surf_color + 0.1) * vec3(0.5, 0.5, 0.5); tgt_color = vec4(surf_color, f_alpha); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_BLOCK); //tgt_color = vec4(f_norm, f_alpha); } diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 650e4e7d31..24b512f083 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -527,4 +527,6 @@ pub enum ExperimentalShader { NoRainbows, /// Add extra detailing to puddles. PuddleDetails, + /// Show the normal buffers. + ViewNormals, } diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index 801728c154..2b7cc2da0c 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -88,6 +88,17 @@ impl CloudsLayout { }, count: None, }, + // Materials source + wgpu::BindGroupLayoutEntry { + binding: 5, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Uint, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, + }, ], }), } @@ -97,6 +108,7 @@ impl CloudsLayout { &self, device: &wgpu::Device, src_color: &wgpu::TextureView, + src_mat: &wgpu::TextureView, src_depth: &wgpu::TextureView, sampler: &wgpu::Sampler, depth_sampler: &wgpu::Sampler, @@ -126,6 +138,10 @@ impl CloudsLayout { binding: 4, resource: locals.buf().as_entire_binding(), }, + wgpu::BindGroupEntry { + binding: 5, + resource: wgpu::BindingResource::TextureView(src_mat), + }, ], }); diff --git a/voxygen/src/render/pipelines/debug.rs b/voxygen/src/render/pipelines/debug.rs index bd0a543042..e97f2287aa 100644 --- a/voxygen/src/render/pipelines/debug.rs +++ b/voxygen/src/render/pipelines/debug.rs @@ -130,11 +130,18 @@ impl DebugPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: Some(wgpu::BlendState::ALPHA_BLENDING), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: Some(wgpu::BlendState::ALPHA_BLENDING), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::empty(), + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/figure.rs b/voxygen/src/render/pipelines/figure.rs index 0bca9a6412..e6bdb76650 100644 --- a/voxygen/src/render/pipelines/figure.rs +++ b/voxygen/src/render/pipelines/figure.rs @@ -233,11 +233,18 @@ impl FigurePipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: None, - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index 6dc61a4239..996968d78a 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -122,22 +122,29 @@ impl FluidPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Min, - }, - }), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Min, + }, + }), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/lod_object.rs b/voxygen/src/render/pipelines/lod_object.rs index 23be60873f..f73097ef6e 100644 --- a/voxygen/src/render/pipelines/lod_object.rs +++ b/voxygen/src/render/pipelines/lod_object.rs @@ -137,11 +137,18 @@ impl LodObjectPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: Some(wgpu::BlendState::REPLACE), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: Some(wgpu::BlendState::REPLACE), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/lod_terrain.rs b/voxygen/src/render/pipelines/lod_terrain.rs index 8d02835706..af09104365 100644 --- a/voxygen/src/render/pipelines/lod_terrain.rs +++ b/voxygen/src/render/pipelines/lod_terrain.rs @@ -252,11 +252,18 @@ impl LodTerrainPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: None, - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index 62d5f89d88..7b3274329e 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -245,23 +245,30 @@ impl ParticlePipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - // TODO: use a constant and/or pass in this format on pipeline construction - format: wgpu::TextureFormat::Rgba16Float, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - }), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + // TODO: use a constant and/or pass in this format on pipeline construction + format: wgpu::TextureFormat::Rgba16Float, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + }), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/skybox.rs b/voxygen/src/render/pipelines/skybox.rs index a3e9e6a863..78c5610ee0 100644 --- a/voxygen/src/render/pipelines/skybox.rs +++ b/voxygen/src/render/pipelines/skybox.rs @@ -91,18 +91,25 @@ impl SkyboxPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent::REPLACE, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::Zero, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - }), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent::REPLACE, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::Zero, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + }), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 8a467050b7..e60cc1f0ad 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -325,23 +325,30 @@ impl SpritePipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - // TODO: can we remove sprite transparency? - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - }), - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + // TODO: can we remove sprite transparency? + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + }), + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index 1230a67c55..8602f2804f 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -276,11 +276,18 @@ impl TerrainPipeline { fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba16Float, - blend: None, - write_mask: wgpu::ColorWrite::ALL, - }], + targets: &[ + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba16Float, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8Uint, + blend: None, + write_mask: wgpu::ColorWrite::ALL, + }, + ], }), }); diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 0df243b60c..9c5238a088 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -85,6 +85,7 @@ struct Views { _win_depth: wgpu::TextureView, tgt_color: wgpu::TextureView, + tgt_mat: wgpu::TextureView, tgt_depth: wgpu::TextureView, bloom_tgts: Option<[wgpu::TextureView; bloom::NUM_SIZES]>, @@ -480,6 +481,7 @@ impl Renderer { clouds_locals, postprocess_locals, &views.tgt_color, + &views.tgt_mat, &views.tgt_depth, views.bloom_tgts.as_ref().map(|tgts| locals::BloomParams { locals: bloom_sizes.map(|size| { @@ -688,6 +690,7 @@ impl Renderer { &self.device, &self.layouts, &self.views.tgt_color, + &self.views.tgt_mat, &self.views.tgt_depth, bloom_params, &self.views.tgt_color_pp, @@ -802,7 +805,7 @@ impl Renderer { let sample_count = pipeline_modes.aa.samples(); let levels = 1; - let color_view = |width, height| { + let color_view = |width, height, format| { let tex = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -813,13 +816,13 @@ impl Renderer { mip_level_count: levels, sample_count, dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba16Float, + format, usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::RENDER_ATTACHMENT, }); tex.create_view(&wgpu::TextureViewDescriptor { label: None, - format: Some(wgpu::TextureFormat::Rgba16Float), + format: Some(format), dimension: Some(wgpu::TextureViewDimension::D2), // TODO: why is this not Color? aspect: wgpu::TextureAspect::All, @@ -830,8 +833,10 @@ impl Renderer { }) }; - let tgt_color_view = color_view(width, height); - let tgt_color_pp_view = color_view(width, height); + let tgt_color_view = color_view(width, height, wgpu::TextureFormat::Rgba16Float); + let tgt_color_pp_view = color_view(width, height, wgpu::TextureFormat::Rgba16Float); + + let tgt_mat_view = color_view(width, height, wgpu::TextureFormat::Rgba8Uint); let mut size_shift = 0; // TODO: skip creating bloom stuff when it is disabled @@ -842,10 +847,9 @@ impl Renderer { size }); - let bloom_tgt_views = pipeline_modes - .bloom - .is_on() - .then(|| bloom_sizes.map(|size| color_view(size.x, size.y))); + let bloom_tgt_views = pipeline_modes.bloom.is_on().then(|| { + bloom_sizes.map(|size| color_view(size.x, size.y, wgpu::TextureFormat::Rgba16Float)) + }); let tgt_depth_tex = device.create_texture(&wgpu::TextureDescriptor { label: None, @@ -899,6 +903,7 @@ impl Renderer { ( Views { tgt_color: tgt_color_view, + tgt_mat: tgt_mat_view, tgt_depth: tgt_depth_view, bloom_tgts: bloom_tgt_views, tgt_color_pp: tgt_color_pp_view, diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index b4f750a792..b0f7fef9a0 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -223,14 +223,24 @@ impl<'frame> Drawer<'frame> { let mut render_pass = encoder.scoped_render_pass("first_pass", device, &wgpu::RenderPassDescriptor { label: Some("first pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: &self.borrow.views.tgt_color, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), - store: true, + color_attachments: &[ + wgpu::RenderPassColorAttachment { + view: &self.borrow.views.tgt_color, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), + store: true, + }, }, - }], + wgpu::RenderPassColorAttachment { + view: &self.borrow.views.tgt_mat, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), + store: true, + }, + }, + ], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { view: &self.borrow.views.tgt_depth, depth_ops: Some(wgpu::Operations { diff --git a/voxygen/src/render/renderer/locals.rs b/voxygen/src/render/renderer/locals.rs index e590396e2c..6134fbdd39 100644 --- a/voxygen/src/render/renderer/locals.rs +++ b/voxygen/src/render/renderer/locals.rs @@ -29,6 +29,7 @@ impl Locals { clouds_locals: Consts, postprocess_locals: Consts, tgt_color_view: &wgpu::TextureView, + tgt_mat_view: &wgpu::TextureView, tgt_depth_view: &wgpu::TextureView, bloom: Option, tgt_color_pp_view: &wgpu::TextureView, @@ -38,6 +39,7 @@ impl Locals { let clouds_bind = layouts.clouds.bind( device, tgt_color_view, + tgt_mat_view, tgt_depth_view, sampler, depth_sampler, @@ -77,6 +79,7 @@ impl Locals { // Call when these are recreated and need to be rebound // e.g. resizing tgt_color_view: &wgpu::TextureView, + tgt_mat_view: &wgpu::TextureView, tgt_depth_view: &wgpu::TextureView, bloom: Option, tgt_color_pp_view: &wgpu::TextureView, @@ -86,6 +89,7 @@ impl Locals { self.clouds_bind = layouts.clouds.bind( device, tgt_color_view, + tgt_mat_view, tgt_depth_view, sampler, depth_sampler,