Fixed point glow with no clouds

This commit is contained in:
Joshua Barretto 2022-01-19 11:29:19 +00:00 committed by Imbris
parent fd4c4adae9
commit fcd25648fe
5 changed files with 52 additions and 39 deletions

View File

@ -22,6 +22,8 @@
#include <srgb.glsl>
#include <cloud.glsl>
#include <light.glsl>
// This *MUST* come after `cloud.glsl`: it contains a function that depends on `cloud.glsl` when clouds are enabled
#include <point_glow.glsl>
layout(set = 1, binding = 0)
uniform texture2D t_src_color;

View File

@ -201,45 +201,9 @@ float dist_to_step(float dist, float quality) {
return pow(dist / STEP_SCALE * quality, 0.5);
}
vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color, const float factor) {
#ifndef EXPERIMENTAL_NOPOINTGLOW
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;
// Project light_pos to dir line
float t = max(dot(light_pos - wpos, dir), 0);
vec3 nearest = wpos + dir * min(t, max_dist);
//if (t > max_dist) { continue; }
vec3 difference = light_pos - nearest;
#if (CLOUD_MODE >= CLOUD_MODE_HIGH)
vec3 _unused;
float unused2;
float spread = 1.0 / (1.0 + cloud_at(nearest, 0.0, _unused, unused2).z * 0.005);
#else
const float spread = 1.0;
#endif
float distance_2 = dot(difference, difference);
if (distance_2 > 100000.0) {
continue;
}
float strength = pow(attenuation_strength_real(difference), spread);
vec3 light_color = srgb_to_linear(L.light_col.rgb) * strength * L.light_col.a;
const float LIGHT_AMBIANCE = 0.025;
color += light_color
* 0.025
// Constant, *should* const fold
* pow(factor, 0.65);
}
#endif
return color;
}
// This *MUST* go here: when clouds are enabled, it relies on the declaration of `clouds_at` above. Sadly, GLSL doesn't
// consistently support forward declarations (not surprising, it's designed for single-pass compilers).
#include <point_glow.glsl>
vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of_day, float max_dist, const float quality) {
// Limit the marching distance to reduce maximum jumps

View File

@ -0,0 +1,44 @@
#ifndef POINT_GLOW_GLSL
#define POINT_GLOW_GLSL
vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color, const float factor) {
#ifndef EXPERIMENTAL_NOPOINTGLOW
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;
// Project light_pos to dir line
float t = max(dot(light_pos - wpos, dir), 0);
vec3 nearest = wpos + dir * min(t, max_dist);
//if (t > max_dist) { continue; }
vec3 difference = light_pos - nearest;
#if (CLOUD_MODE >= CLOUD_MODE_HIGH)
vec3 _unused;
float unused2;
float spread = 1.0 / (1.0 + cloud_at(nearest, 0.0, _unused, unused2).z * 0.005);
#else
const float spread = 1.0;
#endif
float distance_2 = dot(difference, difference);
if (distance_2 > 100000.0) {
continue;
}
float strength = pow(attenuation_strength_real(difference), spread);
vec3 light_color = srgb_to_linear(L.light_col.rgb) * strength * L.light_col.a;
const float LIGHT_AMBIANCE = 0.025;
color += light_color
* 0.025
// Constant, *should* const fold
* pow(factor, 0.65);
}
#endif
return color;
}
#endif

View File

@ -141,6 +141,7 @@ impl ShaderModules {
let random = shaders.get("include.random").unwrap();
let lod = shaders.get("include.lod").unwrap();
let shadows = shaders.get("include.shadows").unwrap();
let point_glow = shaders.get("include.point_glow").unwrap();
// We dynamically add extra configuration settings to the constants file.
let mut constants = format!(
@ -241,6 +242,7 @@ impl ShaderModules {
"lod.glsl" => lod.0.to_owned(),
"anti-aliasing.glsl" => anti_alias.0.to_owned(),
"cloud.glsl" => cloud.0.to_owned(),
"point_glow.glsl" => point_glow.0.to_owned(),
other => {
return Err(format!(
"Include {} in {} is not defined",

View File

@ -37,6 +37,7 @@ impl assets::Compound for Shaders {
"include.random",
"include.lod",
"include.shadows",
"include.point_glow",
"antialias.none",
"antialias.fxaa",
"antialias.msaa-x4",