veloren/assets/voxygen/shaders/clouds-frag.glsl

80 lines
2.3 KiB
Plaintext
Raw Normal View History

#version 420 core
2020-11-15 22:18:35 +00:00
#include <constants.glsl>
#define LIGHTING_TYPE (LIGHTING_TYPE_TRANSMISSION | LIGHTING_TYPE_REFLECTION)
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_SPECULAR
#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
// Must come before includes
#define IS_POSTPROCESS
2020-11-15 22:18:35 +00:00
#include <globals.glsl>
// Note: The sampler uniform is declared here because it differs for MSAA
#include <anti-aliasing.glsl>
#include <srgb.glsl>
#include <cloud.glsl>
2022-01-18 21:09:30 +00:00
#include <light.glsl>
2022-01-19 11:29:19 +00:00
// This *MUST* come after `cloud.glsl`: it contains a function that depends on `cloud.glsl` when clouds are enabled
#include <point_glow.glsl>
2020-11-15 22:18:35 +00:00
layout(set = 1, binding = 0)
uniform texture2D t_src_color;
layout(set = 1, binding = 1)
uniform sampler s_src_color;
2020-11-15 22:18:35 +00:00
layout(set = 1, binding = 2)
uniform texture2D t_src_depth;
layout(set = 1, binding = 3)
uniform sampler s_src_depth;
2020-11-15 22:18:35 +00:00
layout(location = 0) in vec2 uv;
layout (std140, set = 1, binding = 4)
2020-11-15 22:18:35 +00:00
uniform u_locals {
mat4 proj_mat_inv;
mat4 view_mat_inv;
};
layout(location = 0) out vec4 tgt_color;
2020-11-15 22:18:35 +00:00
vec3 wpos_at(vec2 uv) {
2020-12-06 17:43:31 +00:00
float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x;
2020-11-15 22:18:35 +00:00
mat4 inv = view_mat_inv * proj_mat_inv;//inverse(all_mat);
vec4 clip_space = vec4((uv * 2.0 - 1.0) * vec2(1, -1), buf_depth, 1.0);
2020-11-15 22:18:35 +00:00
vec4 view_space = inv * clip_space;
view_space /= view_space.w;
if (buf_depth == 0.0) {
2020-11-15 22:18:35 +00:00
vec3 direction = normalize(view_space.xyz);
return direction.xyz * 524288.0625 + cam_pos.xyz;
2020-11-15 22:18:35 +00:00
} else {
return view_space.xyz;
}
}
void main() {
vec4 color = texture(sampler2D(t_src_color, s_src_color), uv);
2020-11-15 22:18:35 +00:00
2022-01-18 21:09:30 +00:00
vec3 wpos = wpos_at(uv);
float dist = distance(wpos, cam_pos.xyz);
vec3 dir = (wpos - cam_pos.xyz) / dist;
// Apply clouds
color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0);
#if (CLOUD_MODE == CLOUD_MODE_NONE)
2022-01-21 00:50:14 +00:00
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb);
2020-11-15 22:18:35 +00:00
#endif
tgt_color = vec4(color.rgb, 1);
}