Make shadow vert shaders always contain their content but ensure they are never used when shadow maps are disabled, remove uneeded shadow frag shader

This commit is contained in:
Imbris 2021-04-27 19:04:09 -04:00 committed by Avi Weinstock
parent e8874b18c9
commit 2c074ac52b
5 changed files with 13 additions and 55 deletions

View File

@ -1,48 +0,0 @@
// NOTE: We currently do nothing, and just rely on the default shader behavior.
//
// However, in the future we might apply some depth transforms here.
#version 420 core
// #extension ARB_texture_storage : enable
#include <constants.glsl>
#define LIGHTING_TYPE LIGHTING_TYPE_REFLECTION
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_GLOSSY
#if (FLUID_MODE == FLUID_MODE_CHEAP)
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
#elif (FLUID_MODE == FLUID_MODE_SHINY)
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
#endif
#define LIGHTING_DISTRIBUTION_SCHEME LIGHTING_DISTRIBUTION_SCHEME_MICROFACET
#define LIGHTING_DISTRIBUTION LIGHTING_DISTRIBUTION_BECKMANN
// // Currently, we only need globals for the far plane.
// #include <globals.glsl>
// // Currently, we only need lights for the light position
// #include <light.glsl>
// in vec3 FragPos; // FragPos from GS (output per emitvertex)
// flat in int FragLayer;
void main()
{
// Only need to do anything with point lights, since sun and moon should already have nonlinear
// distance.
/*if (FragLayer > 0) */{
// get distance between fragment and light source
// float lightDistance = length(FragPos - lights[FragLayer & 31].light_pos.xyz);
// // // map to [0;1] range by dividing by far_plane
// lightDistance = lightDistance / screen_res.w;//FragPos.w;//screen_res.w;
// // // write this as modified depth
// // // lightDistance = -1000.0 / (lightDistance + 10000.0);
// // // lightDistance /= screen_res.w;
// gl_FragDepth = lightDistance;// / /*FragPos.w;*/screen_res.w;//-1000.0 / (lightDistance + 1000.0);//lightDistance
}
}

View File

@ -54,7 +54,6 @@ uniform u_locals {
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);
// f_pos = v_pos;
@ -66,5 +65,4 @@ void main() {
// gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w));
// shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex;
// vec4(v_pos, 0.0, 1.0);
#endif
}

View File

@ -70,7 +70,6 @@ uniform u_bones {
// out vec4 shadowMapCoord;
void main() {
#if (SHADOW_MODE == SHADOW_MODE_MAP)
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
@ -80,5 +79,4 @@ void main() {
).xyz + (model_pos - focus_off.xyz/* + vec3(0.0, 0.0, 0.0001)*/);
gl_Position = shadowMatrices * vec4(f_pos, 1.0);
#endif
}

View File

@ -124,9 +124,13 @@ impl<'frame> Drawer<'frame> {
/// Get the render mode.
pub fn render_mode(&self) -> &super::super::RenderMode { self.borrow.mode }
/// Returns None if the shadow renderer is not enabled or the pipelines are
/// not available yet
/// Returns None if the shadow renderer is not enabled at some level or the
/// pipelines are not available yet
pub fn shadow_pass(&mut self) -> Option<ShadowPassDrawer> {
if !self.borrow.mode.shadow.is_map() {
return None;
}
if let ShadowMap::Enabled(ref shadow_renderer) = self.borrow.shadow?.map {
let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device;
@ -256,13 +260,18 @@ impl<'frame> Drawer<'frame> {
}
}
/// Does nothing if the shadow pipelines are not available
/// Does nothing if the shadow pipelines are not available or shadow map
/// rendering is disabled
pub fn draw_point_shadows<'data: 'frame>(
&mut self,
matrices: &[shadow::PointLightMatrix; 126],
chunks: impl Clone
+ Iterator<Item = (&'data Model<terrain::Vertex>, &'data terrain::BoundLocals)>,
) {
if !self.borrow.mode.shadow.is_map() {
return;
}
if let Some(ShadowMap::Enabled(ref shadow_renderer)) = self.borrow.shadow.map(|s| &s.map) {
let device = self.borrow.device;
let mut encoder = self

View File

@ -630,6 +630,7 @@ fn create_ingame_and_shadow_pipelines(
terrain,
// player_shadow_pipeline,
},
// TODO: skip creating these if the shadow map setting is not enabled
shadow: ShadowPipelines {
point: Some(point_shadow),
directed: Some(terrain_directed_shadow),