More frustration with shadows.

This commit is contained in:
Joshua Yanovski 2020-12-13 12:33:29 +01:00 committed by Avi Weinstock
parent ffa8f29732
commit e974ebfebd
7 changed files with 20 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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