From f5e0cb00459b5d8e7bd0b65eb92851807665e427 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 2 Mar 2022 00:54:20 -0500 Subject: [PATCH] Addressed review comments --- assets/voxygen/shaders/trail-frag.glsl | 71 +------------------ voxygen/src/render/pipelines/clouds.rs | 17 ++++- voxygen/src/render/pipelines/trail.rs | 17 ++++- voxygen/src/render/renderer.rs | 3 +- voxygen/src/render/renderer/drawer.rs | 25 +++---- .../src/render/renderer/pipeline_creation.rs | 5 -- 6 files changed, 48 insertions(+), 90 deletions(-) diff --git a/assets/voxygen/shaders/trail-frag.glsl b/assets/voxygen/shaders/trail-frag.glsl index 1d6eb9061e..eef9fbe9f9 100644 --- a/assets/voxygen/shaders/trail-frag.glsl +++ b/assets/voxygen/shaders/trail-frag.glsl @@ -34,77 +34,10 @@ void main() { vec3 trail_color = vec3(.55, .92, 1.0); float trail_alpha = 0.05; // Controls how much light affects alpha variation. TODO: Maybe a better name? - float light_variable = 1.0; - - #ifdef EXPERIMENTAL_BAREMINIMUM - tgt_color = vec4(trail_color, trail_alpha); - return; - #endif - - // Using this as norm seems to work, so... - vec3 f_norm = vec3(0, 0, -1); - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - vec3 view_dir = -cam_to_frag; - -#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE == FLUID_MODE_SHINY) - float f_alt = alt_at(f_pos.xy); -#elif (SHADOW_MODE == SHADOW_MODE_NONE || FLUID_MODE == FLUID_MODE_CHEAP) - float f_alt = f_pos.z; -#endif - -#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP) - vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); - float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); -#elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0; -#endif - float moon_shade_frac = 1.0; - - float point_shadow = shadow_at(f_pos, f_norm); - DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, f_pos); - DirectionalLight moon_info = get_moon_info(moon_dir, point_shadow * moon_shade_frac); - - float alpha = 1.0; - const float n2 = 1.5; - const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2); - const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2); - const float R_s2s1 = pow((1.0 - 1.3325) / (1.0 + 1.3325), 2); - const float R_s1s2 = pow((1.3325 - 1.0) / (1.3325 + 1.0), 2); - float R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x); - - vec3 k_a = vec3(1.0); - vec3 k_d = vec3(1.0); - vec3 k_s = vec3(R_s); - - vec3 emitted_light, reflected_light; - - // TODO: Look into using the same light parameter that is used for figures - // Comment on this method copy-pasted from particle shader: - // This is a bit of a hack. Because we can't find the volumetric lighting of each particle (they don't talk to the - // CPU) we need to some how find an approximation of how much the sun is blocked. We do this by fading out the sun - // as the particle moves underground. This isn't perfect, but it does at least mean that particles don't look like - // they're exposed to the sun when in dungeons - const float SUN_FADEOUT_DIST = 20.0; - sun_info.block *= clamp((f_pos.z - f_alt) / SUN_FADEOUT_DIST + 1, 0, 1); - - // To account for prior saturation. - float max_light = 0.0; - - vec3 cam_attenuation = vec3(1); - float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1)); - vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); - #if (FLUID_MODE == FLUID_MODE_SHINY) - cam_attenuation = - medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); - #endif - - max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); - - max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + float light_variable = 0.075; // Make less faint at day (relative to night) by adding light to alpha. Probably hacky but looks fine. - trail_alpha += max_light * light_variable; + trail_alpha += get_sun_brightness() * light_variable; tgt_color = vec4(trail_color, trail_alpha); } diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index 7796f47689..95e03f65dc 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -180,7 +180,22 @@ impl CloudsPipeline { polygon_mode: wgpu::PolygonMode::Fill, conservative: false, }, - depth_stencil: None, + depth_stencil: Some(wgpu::DepthStencilState { + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::Always, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, + read_mask: !0, + write_mask: 0, + }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + }), multisample: wgpu::MultisampleState { count: samples, mask: !0, diff --git a/voxygen/src/render/pipelines/trail.rs b/voxygen/src/render/pipelines/trail.rs index 335419261f..5584db3a61 100644 --- a/voxygen/src/render/pipelines/trail.rs +++ b/voxygen/src/render/pipelines/trail.rs @@ -93,7 +93,22 @@ impl TrailPipeline { polygon_mode: wgpu::PolygonMode::Fill, conservative: false, }, - depth_stencil: None, + depth_stencil: Some(wgpu::DepthStencilState { + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::GreaterEqual, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, + read_mask: !0, + write_mask: 0, + }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + }), multisample: wgpu::MultisampleState { count: samples, mask: !0, diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 9fea3ee13a..1ce1db0668 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -9,8 +9,7 @@ mod shadow_map; use locals::Locals; use pipeline_creation::{ - IngameAndShadowPipelines, InterfacePipelines, PipelineCreation, Pipelines, SecondPassPipelines, - ShadowPipelines, + IngameAndShadowPipelines, InterfacePipelines, PipelineCreation, Pipelines, ShadowPipelines, }; use shaders::Shaders; use shadow_map::{ShadowMap, ShadowMapRenderer}; diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index ac3616c4f6..5db119816a 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -4,8 +4,8 @@ use super::{ instances::Instances, model::{DynamicModel, Model, SubModel}, pipelines::{ - blit, bloom, debug, figure, fluid, lod_terrain, particle, shadow, skybox, sprite, - terrain, trail, ui, ColLights, GlobalsBindGroup, ShadowTexturesBindGroup, + blit, bloom, clouds, debug, figure, fluid, lod_terrain, particle, shadow, skybox, + sprite, terrain, trail, ui, ColLights, GlobalsBindGroup, ShadowTexturesBindGroup, }, }, Renderer, ShadowMap, ShadowMapRenderer, @@ -214,11 +214,6 @@ impl<'frame> Drawer<'frame> { /// Returns None if the clouds pipeline is not available pub fn second_pass(&mut self) -> Option { - let pipelines = super::SecondPassPipelines { - clouds: &self.borrow.pipelines.all()?.clouds, - trail: &self.borrow.pipelines.all()?.trail, - }; - let encoder = self.encoder.as_mut().unwrap(); let device = self.borrow.device; let mut render_pass = @@ -232,7 +227,11 @@ impl<'frame> Drawer<'frame> { store: true, }, }], - depth_stencil_attachment: None, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.borrow.views.tgt_depth, + depth_ops: None, + stencil_ops: None, + }), }); render_pass.set_bind_group(0, &self.globals.bind_group, &[]); @@ -240,7 +239,8 @@ impl<'frame> Drawer<'frame> { Some(SecondPassDrawer { render_pass, borrow: &self.borrow, - pipelines, + clouds_pipeline: &self.borrow.pipelines.all()?.clouds, + trail_pipeline: &self.borrow.pipelines.all()?.trail, }) } @@ -931,13 +931,14 @@ impl<'pass_ref, 'pass: 'pass_ref> FluidDrawer<'pass_ref, 'pass> { pub struct SecondPassDrawer<'pass> { render_pass: OwningScope<'pass, wgpu::RenderPass<'pass>>, borrow: &'pass RendererBorrow<'pass>, - pipelines: super::SecondPassPipelines<'pass>, + clouds_pipeline: &'pass clouds::CloudsPipeline, + trail_pipeline: &'pass trail::TrailPipeline, } impl<'pass> SecondPassDrawer<'pass> { pub fn draw_clouds(&mut self) { self.render_pass - .set_pipeline(&self.pipelines.clouds.pipeline); + .set_pipeline(&self.clouds_pipeline.pipeline); self.render_pass .set_bind_group(1, &self.borrow.locals.clouds_bind.bind_group, &[]); self.render_pass.draw(0..3, 0..1); @@ -946,7 +947,7 @@ impl<'pass> SecondPassDrawer<'pass> { pub fn draw_trails(&mut self) -> Option> { let mut render_pass = self.render_pass.scope("trails", self.borrow.device); - render_pass.set_pipeline(&self.pipelines.trail.pipeline); + render_pass.set_pipeline(&self.trail_pipeline.pipeline); set_quad_index_buffer::(&mut render_pass, self.borrow); render_pass.set_bind_group(1, &self.borrow.shadow?.bind.bind_group, &[]); diff --git a/voxygen/src/render/renderer/pipeline_creation.rs b/voxygen/src/render/renderer/pipeline_creation.rs index d54eec34df..a4e8e34126 100644 --- a/voxygen/src/render/renderer/pipeline_creation.rs +++ b/voxygen/src/render/renderer/pipeline_creation.rs @@ -33,11 +33,6 @@ pub struct Pipelines { pub blit: blit::BlitPipeline, } -pub struct SecondPassPipelines<'a> { - pub clouds: &'a clouds::CloudsPipeline, - pub trail: &'a trail::TrailPipeline, -} - /// Pipelines that are needed to render 3D stuff in-game /// Use to decouple interface pipeline creation when initializing the renderer pub struct IngamePipelines {