From e974ebfebdd8c452769215a643a7d7e961b88a78 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Sun, 13 Dec 2020 12:33:29 +0100 Subject: [PATCH] More frustration with shadows. --- assets/voxygen/shaders/include/globals.glsl | 1 + assets/voxygen/shaders/include/shadows.glsl | 6 +++++- .../voxygen/shaders/light-shadows-directed-vert.glsl | 2 +- voxygen/src/render/pipelines/mod.rs | 7 +++++-- voxygen/src/render/pipelines/shadow.rs | 12 ++++++------ voxygen/src/render/renderer.rs | 2 +- voxygen/src/render/renderer/drawer.rs | 2 +- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/assets/voxygen/shaders/include/globals.glsl b/assets/voxygen/shaders/include/globals.glsl index a44a0fa768..47f038b31f 100644 --- a/assets/voxygen/shaders/include/globals.glsl +++ b/assets/voxygen/shaders/include/globals.glsl @@ -24,6 +24,7 @@ layout(std140, set = 0, binding = 0) uniform u_globals { // 1 - ThirdPerson uint cam_mode; float sprite_render_distance; + float gloabls_dummy; // Fix alignment. }; // Specifies the pattern used in the player dithering diff --git a/assets/voxygen/shaders/include/shadows.glsl b/assets/voxygen/shaders/include/shadows.glsl index 80892dee69..58a69cf0ab 100644 --- a/assets/voxygen/shaders/include/shadows.glsl +++ b/assets/voxygen/shaders/include/shadows.glsl @@ -44,7 +44,7 @@ float VectorToDepth (vec3 Vec) // float NormZComp = 1.0 - shadow_proj_factors.y / shadow_proj_factors.x / LocalZcomp; // -(1 + 2n/(f-n)) - 2(1 + n/(f-n)) * n/z // -(1 + n/(f-n)) - (1 + n/(f-n)) * n/z - // f/(f-n) - f + // f/(f-n) - fn/(f-n)/z float NormZComp = shadow_proj_factors.x - shadow_proj_factors.y / LocalZcomp; // NormZComp = -1000.0 / (NormZComp + 10000.0); // return (NormZComp + 1.0) * 0.5; @@ -75,6 +75,8 @@ float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, / { float currentDepth = VectorToDepth(fragToLight);// + bias; + // currentDepth = -currentDepth * 0.5 + 0.5; + float visibility = texture(samplerCubeShadow(t_point_shadow_maps, s_point_shadow_maps), vec4(fragToLight, currentDepth));// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/); /* if (visibility == 1.0 || visibility == 0.0) { return visibility; @@ -166,6 +168,8 @@ float ShadowCalculationDirected(in vec3 fragPos)//in vec4 /*light_pos[2]*/sun_po // vec3 fragPos = sun_pos.xyz;// / sun_pos.w;//light_pos[lightIndex].xyz; // sun_pos.z += sun_pos.w * bias; vec4 sun_pos = texture_mat/*shadowMatrices*/ * vec4(fragPos, 1.0); + // sun_pos.xy = 0.5 * sun_pos.w + sun_pos.xy * 0.5; + // sun_pos.xy = sun_pos.ww - sun_pos.xy; // sun_pos.xyz /= abs(sun_pos.w); // sun_pos.w = sign(sun_pos.w); // sun_pos.xy = (sun_pos.xy + 1.0) * 0.5; diff --git a/assets/voxygen/shaders/light-shadows-directed-vert.glsl b/assets/voxygen/shaders/light-shadows-directed-vert.glsl index 1b83bc38a4..0f27c0dbc2 100644 --- a/assets/voxygen/shaders/light-shadows-directed-vert.glsl +++ b/assets/voxygen/shaders/light-shadows-directed-vert.glsl @@ -56,7 +56,7 @@ const int EXTRA_NEG_Z = 32768; void main() { #if (SHADOW_MODE == SHADOW_MODE_MAP) vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z)); - vec3 f_pos = f_chunk_pos + model_offs - focus_off.xyz; + vec3 f_pos = f_chunk_pos + (model_offs - focus_off.xyz); // f_pos = v_pos; // vec3 f_pos = f_chunk_pos + model_offs; diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index a20395a507..babdc39638 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -58,6 +58,8 @@ pub struct Globals { ambiance: f32, cam_mode: u32, sprite_render_distance: f32, + /// To keep 16-byte-aligned. + globals_dummy: f32, } #[repr(C)] @@ -140,6 +142,7 @@ impl Globals { ambiance, cam_mode: cam_mode as u32, sprite_render_distance, + globals_dummy: 0.0, } } @@ -417,7 +420,7 @@ impl GlobalsLayouts { binding: 0, visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { filterable: true }, + sample_type: wgpu::TextureSampleType::Depth, view_dimension: wgpu::TextureViewDimension::Cube, multisampled: false, }, @@ -437,7 +440,7 @@ impl GlobalsLayouts { binding: 2, visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { filterable: true }, + sample_type: wgpu::TextureSampleType::Depth, view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, diff --git a/voxygen/src/render/pipelines/shadow.rs b/voxygen/src/render/pipelines/shadow.rs index f81b31bb0f..8acd71c668 100644 --- a/voxygen/src/render/pipelines/shadow.rs +++ b/voxygen/src/render/pipelines/shadow.rs @@ -161,10 +161,10 @@ impl ShadowFigurePipeline { module: vs_module, entry_point: "main", }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { module: fs_module, entry_point: "main", - }), + })*/None, rasterization_state: Some(wgpu::RasterizationStateDescriptor { front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Front, @@ -237,10 +237,10 @@ impl ShadowPipeline { module: vs_module, entry_point: "main", }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { module: fs_module, entry_point: "main", - }), + })*/None, rasterization_state: Some(wgpu::RasterizationStateDescriptor { front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Front, @@ -315,10 +315,10 @@ impl PointShadowPipeline { module: vs_module, entry_point: "main", }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { module: fs_module, entry_point: "main", - }), + })*/None, rasterization_state: Some(wgpu::RasterizationStateDescriptor { front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Front, diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 9a8159191c..4a4e4fe5b0 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -2106,7 +2106,7 @@ fn create_pipelines( let figure_vert_mod = create_shader("figure-vert", ShaderKind::Vertex)?; - let terrain_point_shadow_vert_mod = create_shader("point-light-shadows-vert", ShaderKind::Vertex)?; + // let terrain_point_shadow_vert_mod = create_shader("Point-light-shadows-vert", ShaderKind::Vertex)?; let terrain_directed_shadow_vert_mod = create_shader("light-shadows-directed-vert", ShaderKind::Vertex)?; diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index dd934d967b..48bb8b27e8 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -172,7 +172,7 @@ impl<'a> Drawer<'a> { label: Some("Point shadow cubemap face"), format: None, dimension: Some(wgpu::TextureViewDimension::D2), - aspect: wgpu::TextureAspect::All, + aspect: wgpu::TextureAspect::DepthOnly, base_mip_level: 0, level_count: None, base_array_layer: face,