mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Bad impl of volumetric point lights
This commit is contained in:
parent
afef73e90d
commit
e7af860764
@ -70,7 +70,7 @@ uniform u_bones {
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
#include <cloud.glsl>
|
||||
//#include <cloud.glsl>
|
||||
#include <light.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
|
@ -50,7 +50,7 @@ uniform sampler2D t_waves;
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
#include <cloud.glsl>
|
||||
//#include <cloud.glsl>
|
||||
#include <light.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
@ -179,7 +179,7 @@ void main() {
|
||||
// Squared to account for prior saturation.
|
||||
float f_light = 1.0;// pow(f_light, 1.5);
|
||||
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/beam_view_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
|
||||
reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
//reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
reflect_color *= f_light;
|
||||
// /*const */vec3 water_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
|
||||
// /*const */vec3 water_color = srgb_to_linear(vec3(0.8, 0.9, 1.0));
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <random.glsl>
|
||||
#include <lod.glsl>
|
||||
#include <light.glsl>
|
||||
|
||||
float falloff(float x) {
|
||||
return pow(max(x > 0.577 ? (0.3849 / x - 0.1) : (0.9 - x * x), 0.0), 4);
|
||||
@ -234,5 +235,31 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
emission * density_integrals.y;
|
||||
}
|
||||
|
||||
for (uint i = 0u; i < light_shadow_count.x; i ++) {
|
||||
// Only access the array once
|
||||
Light L = lights[i];
|
||||
|
||||
vec3 light_pos = L.light_pos.xyz;// - focus_off.xyz;
|
||||
|
||||
float dist = max_dist;
|
||||
float len_sq = pow(dist, 2);
|
||||
float t = (dot(light_pos - origin, dir * dist) / len_sq);
|
||||
t = clamp(t, 0, 1);
|
||||
|
||||
vec3 nearest = origin.xyz + dir * dist * t;
|
||||
|
||||
// Pre-calculate difference between light and fragment
|
||||
vec3 difference = light_pos - nearest;
|
||||
vec3 emission;
|
||||
float vapor = cloud_at(nearest, dist * t, emission).z;
|
||||
|
||||
float strength = attenuation_strength(difference) * 10.0 * vapor;
|
||||
|
||||
// Multiply the vec3 only once
|
||||
vec3 color = srgb_to_linear(L.light_col.rgb) * (strength * L.light_col.a);
|
||||
|
||||
surf_color += color;
|
||||
}
|
||||
|
||||
return surf_color;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#define HAS_LOD_FULL_INFO
|
||||
|
||||
#include <globals.glsl>
|
||||
#include <cloud.glsl>
|
||||
//#include <cloud.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
@ -648,7 +648,7 @@ void main() {
|
||||
float passthrough = dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag);
|
||||
|
||||
vec3 reflect_color = get_sky_color(reflect_ray, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
|
||||
reflect_color = get_cloud_color(reflect_color, reflect_ray, cam_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
//reflect_color = get_cloud_color(reflect_color, reflect_ray, cam_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
|
||||
const float REFLECTANCE = 0.5;
|
||||
surf_color = illuminate(max_light, view_dir, f_col * emitted_light, reflect_color * REFLECTANCE + water_color * reflected_light);
|
||||
|
@ -20,7 +20,6 @@
|
||||
// Note: The sampler uniform is declared here because it differs for MSAA
|
||||
#include <anti-aliasing.glsl>
|
||||
#include <srgb.glsl>
|
||||
#include <cloud.glsl>
|
||||
|
||||
//uniform sampler2D src_depth;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
super::{Mesh, Pipeline, TgtColorFmt, TgtDepthStencilFmt, Tri},
|
||||
Globals,
|
||||
Globals, shadow, Light, Shadow,
|
||||
};
|
||||
use gfx::{
|
||||
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
|
||||
@ -23,6 +23,11 @@ gfx_defines! {
|
||||
|
||||
locals: gfx::ConstantBuffer<Locals> = "u_locals",
|
||||
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
||||
lights: gfx::ConstantBuffer<Light> = "u_lights",
|
||||
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
|
||||
|
||||
point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
|
||||
directed_shadow_maps: gfx::TextureSampler<f32> = "t_directed_shadow_maps",
|
||||
|
||||
map: gfx::TextureSampler<[f32; 4]> = "t_map",
|
||||
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
|
||||
@ -32,6 +37,7 @@ gfx_defines! {
|
||||
depth_sampler: gfx::TextureSampler<<TgtDepthStencilFmt as gfx::format::Formatted>::View> = "src_depth",
|
||||
|
||||
noise: gfx::TextureSampler<f32> = "t_noise",
|
||||
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows",
|
||||
|
||||
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
|
||||
}
|
||||
|
@ -165,57 +165,65 @@ impl assets::Compound for Shaders {
|
||||
_: &assets::AssetCache<S>,
|
||||
_: &str,
|
||||
) -> Result<Shaders, assets::Error> {
|
||||
let load = |name| match AssetExt::load(name) {
|
||||
Ok(asset) => Ok(asset),
|
||||
Err(err) => {
|
||||
println!("When loading {}...", name);
|
||||
Err(err)
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Shaders {
|
||||
constants: AssetExt::load("voxygen.shaders.include.constants")?,
|
||||
globals: AssetExt::load("voxygen.shaders.include.globals")?,
|
||||
sky: AssetExt::load("voxygen.shaders.include.sky")?,
|
||||
light: AssetExt::load("voxygen.shaders.include.light")?,
|
||||
srgb: AssetExt::load("voxygen.shaders.include.srgb")?,
|
||||
random: AssetExt::load("voxygen.shaders.include.random")?,
|
||||
lod: AssetExt::load("voxygen.shaders.include.lod")?,
|
||||
shadows: AssetExt::load("voxygen.shaders.include.shadows")?,
|
||||
constants: load("voxygen.shaders.include.constants")?,
|
||||
globals: load("voxygen.shaders.include.globals")?,
|
||||
sky: load("voxygen.shaders.include.sky")?,
|
||||
light: load("voxygen.shaders.include.light")?,
|
||||
srgb: load("voxygen.shaders.include.srgb")?,
|
||||
random: load("voxygen.shaders.include.random")?,
|
||||
lod: load("voxygen.shaders.include.lod")?,
|
||||
shadows: load("voxygen.shaders.include.shadows")?,
|
||||
|
||||
anti_alias_none: AssetExt::load("voxygen.shaders.antialias.none")?,
|
||||
anti_alias_fxaa: AssetExt::load("voxygen.shaders.antialias.fxaa")?,
|
||||
anti_alias_msaa_x4: AssetExt::load("voxygen.shaders.antialias.msaa-x4")?,
|
||||
anti_alias_msaa_x8: AssetExt::load("voxygen.shaders.antialias.msaa-x8")?,
|
||||
anti_alias_msaa_x16: AssetExt::load("voxygen.shaders.antialias.msaa-x16")?,
|
||||
cloud_none: AssetExt::load("voxygen.shaders.include.cloud.none")?,
|
||||
cloud_regular: AssetExt::load("voxygen.shaders.include.cloud.regular")?,
|
||||
figure_vert: AssetExt::load("voxygen.shaders.figure-vert")?,
|
||||
anti_alias_none: load("voxygen.shaders.antialias.none")?,
|
||||
anti_alias_fxaa: load("voxygen.shaders.antialias.fxaa")?,
|
||||
anti_alias_msaa_x4: load("voxygen.shaders.antialias.msaa-x4")?,
|
||||
anti_alias_msaa_x8: load("voxygen.shaders.antialias.msaa-x8")?,
|
||||
anti_alias_msaa_x16: load("voxygen.shaders.antialias.msaa-x16")?,
|
||||
cloud_none: load("voxygen.shaders.include.cloud.none")?,
|
||||
cloud_regular: load("voxygen.shaders.include.cloud.regular")?,
|
||||
figure_vert: load("voxygen.shaders.figure-vert")?,
|
||||
|
||||
terrain_point_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-vert")?,
|
||||
terrain_directed_shadow_vert: AssetExt::load(
|
||||
terrain_point_shadow_vert: load("voxygen.shaders.light-shadows-vert")?,
|
||||
terrain_directed_shadow_vert: load(
|
||||
"voxygen.shaders.light-shadows-directed-vert",
|
||||
)?,
|
||||
figure_directed_shadow_vert: AssetExt::load(
|
||||
figure_directed_shadow_vert: load(
|
||||
"voxygen.shaders.light-shadows-figure-vert",
|
||||
)?,
|
||||
directed_shadow_frag: AssetExt::load("voxygen.shaders.light-shadows-directed-frag")?,
|
||||
directed_shadow_frag: load("voxygen.shaders.light-shadows-directed-frag")?,
|
||||
|
||||
skybox_vert: AssetExt::load("voxygen.shaders.skybox-vert")?,
|
||||
skybox_frag: AssetExt::load("voxygen.shaders.skybox-frag")?,
|
||||
figure_frag: AssetExt::load("voxygen.shaders.figure-frag")?,
|
||||
terrain_vert: AssetExt::load("voxygen.shaders.terrain-vert")?,
|
||||
terrain_frag: AssetExt::load("voxygen.shaders.terrain-frag")?,
|
||||
fluid_vert: AssetExt::load("voxygen.shaders.fluid-vert")?,
|
||||
fluid_frag_cheap: AssetExt::load("voxygen.shaders.fluid-frag.cheap")?,
|
||||
fluid_frag_shiny: AssetExt::load("voxygen.shaders.fluid-frag.shiny")?,
|
||||
sprite_vert: AssetExt::load("voxygen.shaders.sprite-vert")?,
|
||||
sprite_frag: AssetExt::load("voxygen.shaders.sprite-frag")?,
|
||||
particle_vert: AssetExt::load("voxygen.shaders.particle-vert")?,
|
||||
particle_frag: AssetExt::load("voxygen.shaders.particle-frag")?,
|
||||
ui_vert: AssetExt::load("voxygen.shaders.ui-vert")?,
|
||||
ui_frag: AssetExt::load("voxygen.shaders.ui-frag")?,
|
||||
lod_terrain_vert: AssetExt::load("voxygen.shaders.lod-terrain-vert")?,
|
||||
lod_terrain_frag: AssetExt::load("voxygen.shaders.lod-terrain-frag")?,
|
||||
clouds_vert: AssetExt::load("voxygen.shaders.clouds-vert")?,
|
||||
clouds_frag: AssetExt::load("voxygen.shaders.clouds-frag")?,
|
||||
postprocess_vert: AssetExt::load("voxygen.shaders.postprocess-vert")?,
|
||||
postprocess_frag: AssetExt::load("voxygen.shaders.postprocess-frag")?,
|
||||
player_shadow_frag: AssetExt::load("voxygen.shaders.player-shadow-frag")?,
|
||||
light_shadows_geom: AssetExt::load("voxygen.shaders.light-shadows-geom")?,
|
||||
light_shadows_frag: AssetExt::load("voxygen.shaders.light-shadows-frag")?,
|
||||
skybox_vert: load("voxygen.shaders.skybox-vert")?,
|
||||
skybox_frag: load("voxygen.shaders.skybox-frag")?,
|
||||
figure_frag: load("voxygen.shaders.figure-frag")?,
|
||||
terrain_vert: load("voxygen.shaders.terrain-vert")?,
|
||||
terrain_frag: load("voxygen.shaders.terrain-frag")?,
|
||||
fluid_vert: load("voxygen.shaders.fluid-vert")?,
|
||||
fluid_frag_cheap: load("voxygen.shaders.fluid-frag.cheap")?,
|
||||
fluid_frag_shiny: load("voxygen.shaders.fluid-frag.shiny")?,
|
||||
sprite_vert: load("voxygen.shaders.sprite-vert")?,
|
||||
sprite_frag: load("voxygen.shaders.sprite-frag")?,
|
||||
particle_vert: load("voxygen.shaders.particle-vert")?,
|
||||
particle_frag: load("voxygen.shaders.particle-frag")?,
|
||||
ui_vert: load("voxygen.shaders.ui-vert")?,
|
||||
ui_frag: load("voxygen.shaders.ui-frag")?,
|
||||
lod_terrain_vert: load("voxygen.shaders.lod-terrain-vert")?,
|
||||
lod_terrain_frag: load("voxygen.shaders.lod-terrain-frag")?,
|
||||
clouds_vert: load("voxygen.shaders.clouds-vert")?,
|
||||
clouds_frag: load("voxygen.shaders.clouds-frag")?,
|
||||
postprocess_vert: load("voxygen.shaders.postprocess-vert")?,
|
||||
postprocess_frag: load("voxygen.shaders.postprocess-frag")?,
|
||||
player_shadow_frag: load("voxygen.shaders.player-shadow-frag")?,
|
||||
light_shadows_geom: load("voxygen.shaders.light-shadows-geom")?,
|
||||
light_shadows_frag: load("voxygen.shaders.light-shadows-frag")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1803,9 +1811,28 @@ impl Renderer {
|
||||
&mut self,
|
||||
model: &Model<clouds::CloudsPipeline>,
|
||||
globals: &Consts<Globals>,
|
||||
global: &GlobalModel,
|
||||
locals: &Consts<clouds::Locals>,
|
||||
lod: &lod_terrain::LodData,
|
||||
) {
|
||||
let (point_shadow_maps, directed_shadow_maps) =
|
||||
if let Some(shadow_map) = &mut self.shadow_map {
|
||||
(
|
||||
(
|
||||
shadow_map.point_res.clone(),
|
||||
shadow_map.point_sampler.clone(),
|
||||
),
|
||||
(
|
||||
shadow_map.directed_res.clone(),
|
||||
shadow_map.directed_sampler.clone(),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
(self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
|
||||
(self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
|
||||
)
|
||||
};
|
||||
self.encoder.draw(
|
||||
&gfx::Slice {
|
||||
start: model.vertex_range().start,
|
||||
@ -1819,6 +1846,9 @@ impl Renderer {
|
||||
vbuf: model.vbuf.clone(),
|
||||
locals: locals.buf.clone(),
|
||||
globals: globals.buf.clone(),
|
||||
lights: global.lights.buf.clone(),
|
||||
shadows: global.shadows.buf.clone(),
|
||||
light_shadows: global.shadow_mats.buf.clone(),
|
||||
map: (lod.map.srv.clone(), lod.map.sampler.clone()),
|
||||
alt: (lod.alt.srv.clone(), lod.alt.sampler.clone()),
|
||||
horizon: (lod.horizon.srv.clone(), lod.horizon.sampler.clone()),
|
||||
@ -1826,6 +1856,8 @@ impl Renderer {
|
||||
depth_sampler: (self.tgt_depth_res.clone(), self.sampler.clone()),
|
||||
noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
|
||||
tgt_color: self.tgt_color_view_pp.clone(),
|
||||
point_shadow_maps,
|
||||
directed_shadow_maps,
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1944,17 +1976,31 @@ fn create_pipelines(
|
||||
_ => shaders.cloud_regular,
|
||||
};
|
||||
|
||||
|
||||
let mut include_ctx = IncludeContext::new();
|
||||
include_ctx.include("constants.glsl", &constants);
|
||||
include_ctx.include("globals.glsl", &shaders.globals.read().0);
|
||||
include_ctx.include("shadows.glsl", &shaders.shadows.read().0);
|
||||
include_ctx.include("sky.glsl", &shaders.sky.read().0);
|
||||
include_ctx.include("light.glsl", &shaders.light.read().0);
|
||||
include_ctx.include("srgb.glsl", &shaders.srgb.read().0);
|
||||
include_ctx.include("random.glsl", &shaders.random.read().0);
|
||||
include_ctx.include("lod.glsl", &shaders.lod.read().0);
|
||||
include_ctx.include("anti-aliasing.glsl", &anti_alias.read().0);
|
||||
include_ctx.include("cloud.glsl", &cloud.read().0);
|
||||
|
||||
let mut guard = |name: &str, code: &str| {
|
||||
let define = name
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
c if c.is_ascii_alphanumeric() => c,
|
||||
_ => '_',
|
||||
})
|
||||
.collect::<String>();
|
||||
let code = format!("#ifndef {}\n#define {}\n{}\n#endif", define, define, code);
|
||||
include_ctx.include(name, &code);
|
||||
};
|
||||
|
||||
guard("constants.glsl", &constants);
|
||||
guard("globals.glsl", &shaders.globals.read().0);
|
||||
guard("shadows.glsl", &shaders.shadows.read().0);
|
||||
guard("sky.glsl", &shaders.sky.read().0);
|
||||
guard("light.glsl", &shaders.light.read().0);
|
||||
guard("srgb.glsl", &shaders.srgb.read().0);
|
||||
guard("random.glsl", &shaders.random.read().0);
|
||||
guard("lod.glsl", &shaders.lod.read().0);
|
||||
guard("anti-aliasing.glsl", &anti_alias.read().0);
|
||||
guard("cloud.glsl", &cloud.read().0);
|
||||
|
||||
// Construct a pipeline for rendering skyboxes
|
||||
let skybox_pipeline = create_pipeline(
|
||||
|
@ -1097,6 +1097,7 @@ impl Scene {
|
||||
renderer.render_clouds(
|
||||
&self.clouds.model,
|
||||
&global.globals,
|
||||
global,
|
||||
&self.clouds.locals,
|
||||
self.lod.get_data(),
|
||||
);
|
||||
|
@ -434,6 +434,7 @@ impl Scene {
|
||||
renderer.render_clouds(
|
||||
&self.clouds.model,
|
||||
&self.data.globals,
|
||||
&self.data,
|
||||
&self.clouds.locals,
|
||||
&self.lod,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user