Addressed review comments

This commit is contained in:
Sam 2022-03-02 00:54:20 -05:00
parent 0a0fffd5ed
commit f5e0cb0045
6 changed files with 48 additions and 90 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -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,

View File

@ -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};

View File

@ -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<SecondPassDrawer> {
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<TrailDrawer<'_, 'pass>> {
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::<trail::Vertex>(&mut render_pass, self.borrow);
render_pass.set_bind_group(1, &self.borrow.shadow?.bind.bind_group, &[]);

View File

@ -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 {