mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added point glow
This commit is contained in:
parent
7052aad11b
commit
391d1f6bf4
@ -21,6 +21,7 @@
|
||||
#include <anti-aliasing.glsl>
|
||||
#include <srgb.glsl>
|
||||
#include <cloud.glsl>
|
||||
#include <light.glsl>
|
||||
|
||||
layout(set = 1, binding = 0)
|
||||
uniform texture2D t_src_color;
|
||||
@ -42,7 +43,6 @@ uniform u_locals {
|
||||
|
||||
layout(location = 0) out vec4 tgt_color;
|
||||
|
||||
|
||||
vec3 wpos_at(vec2 uv) {
|
||||
float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x;
|
||||
mat4 inv = view_mat_inv * proj_mat_inv;//inverse(all_mat);
|
||||
@ -60,13 +60,17 @@ vec3 wpos_at(vec2 uv) {
|
||||
void main() {
|
||||
vec4 color = texture(sampler2D(t_src_color, s_src_color), uv);
|
||||
|
||||
vec3 wpos = wpos_at(uv);
|
||||
float dist = distance(wpos, cam_pos.xyz);
|
||||
vec3 dir = (wpos - cam_pos.xyz) / dist;
|
||||
|
||||
// Apply clouds
|
||||
#if (CLOUD_MODE != CLOUD_MODE_NONE)
|
||||
vec3 wpos = wpos_at(uv);
|
||||
float dist = distance(wpos, cam_pos.xyz);
|
||||
vec3 dir = (wpos - cam_pos.xyz) / dist;
|
||||
|
||||
color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0);
|
||||
#else
|
||||
#ifdef BLOOM_FACTOR
|
||||
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb, BLOOM_FACTOR);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(color.rgb, 1);
|
||||
|
@ -145,8 +145,8 @@ void main() {
|
||||
nmap = mix(f_norm, normalize(nmap), min(1.0 / pow(frag_dist, 0.75), 1));
|
||||
|
||||
//float suppress_waves = max(dot(), 0);
|
||||
vec3 norm = normalize(vec3(0, 0, 1) * nmap.z + b_norm * nmap.x + c_norm * nmap.y);
|
||||
// vec3 norm = f_norm;
|
||||
vec3 norm = normalize(f_norm * nmap.z + b_norm * nmap.x + c_norm * nmap.y);
|
||||
//norm = f_norm;
|
||||
|
||||
vec3 water_color = (1.0 - MU_WATER) * MU_SCATTER;
|
||||
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE == FLUID_MODE_SHINY)
|
||||
@ -177,7 +177,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, f_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
reflect_color *= f_light;
|
||||
|
||||
// Prevent the sky affecting light when underground
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <constants.glsl>
|
||||
#include <random.glsl>
|
||||
#include <light.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
float falloff(float x) {
|
||||
@ -200,6 +201,46 @@ 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;
|
||||
}
|
||||
|
||||
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
|
||||
max_dist = min(max_dist, DIST_CAP);
|
||||
@ -259,5 +300,10 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
emission * density_integrals.y * step;
|
||||
}
|
||||
|
||||
// Apply point glow
|
||||
#ifdef BLOOM_FACTOR
|
||||
surf_color = apply_point_glow(origin, dir, max_dist, surf_color, BLOOM_FACTOR);
|
||||
#endif
|
||||
|
||||
return surf_color;
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef LIGHT_GLSL
|
||||
#define LIGHT_GLSL
|
||||
|
||||
#include <srgb.glsl>
|
||||
#include <shadows.glsl>
|
||||
|
||||
@ -28,6 +31,11 @@ float attenuation_strength(vec3 rpos) {
|
||||
return max(2.0 / pow(d2 + 10, 0.35) - pow(d2 / 50000.0, 0.8), 0.0);
|
||||
}
|
||||
|
||||
float attenuation_strength_real(vec3 rpos) {
|
||||
float d2 = rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z;
|
||||
return 1.0 / (0.0 + d2);
|
||||
}
|
||||
|
||||
// // Compute attenuation due to light passing through a substance that fills an area below a horizontal plane
|
||||
// // (e.g. in most cases, water below the water surface depth).
|
||||
// //
|
||||
@ -243,3 +251,5 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve
|
||||
float lights_at(vec3 wpos, vec3 wnorm, vec3 view_dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, inout vec3 emitted_light, inout vec3 reflected_light) {
|
||||
return lights_at(wpos, wnorm, view_dir, vec3(0.0), vec3(1.0), 0.0, k_a, k_d, k_s, alpha, wnorm, 1.0, emitted_light, reflected_light);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -399,4 +399,7 @@ pub enum ExperimentalShader {
|
||||
NoNoise,
|
||||
/// Simulated a curved world.
|
||||
CurvedWorld,
|
||||
/// Remove the glow effect around point lights (this is *not* the same thing
|
||||
/// as bloom).
|
||||
NoPointGlow,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user