2022-02-20 01:08:53 +01:00
|
|
|
/* clang-format off */
|
|
|
|
#[modes]
|
|
|
|
|
|
|
|
mode_background =
|
|
|
|
mode_half_res = #define USE_HALF_RES_PASS
|
|
|
|
mode_quarter_res = #define USE_QUARTER_RES_PASS
|
|
|
|
mode_cubemap = #define USE_CUBEMAP_PASS
|
|
|
|
mode_cubemap_half_res = #define USE_CUBEMAP_PASS \n#define USE_HALF_RES_PASS
|
|
|
|
mode_cubemap_quarter_res = #define USE_CUBEMAP_PASS \n#define USE_QUARTER_RES_PASS
|
|
|
|
|
|
|
|
#[specializations]
|
|
|
|
|
2023-01-28 05:03:00 +01:00
|
|
|
USE_MULTIVIEW = false
|
|
|
|
USE_INVERTED_Y = true
|
2024-01-19 06:14:36 +01:00
|
|
|
APPLY_TONEMAPPING = true
|
2023-01-28 05:03:00 +01:00
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
#[vertex]
|
|
|
|
|
2022-05-16 20:56:03 +02:00
|
|
|
layout(location = 0) in vec2 vertex_attrib;
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
out vec2 uv_interp;
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
void main() {
|
2023-01-28 05:03:00 +01:00
|
|
|
#ifdef USE_INVERTED_Y
|
2023-02-21 06:11:05 +01:00
|
|
|
uv_interp = vertex_attrib;
|
2023-01-28 05:03:00 +01:00
|
|
|
#else
|
2023-02-21 06:11:05 +01:00
|
|
|
// We're doing clockwise culling so flip the order
|
|
|
|
uv_interp = vec2(vertex_attrib.x, vertex_attrib.y * -1.0);
|
2023-01-28 05:03:00 +01:00
|
|
|
#endif
|
2023-02-21 06:11:05 +01:00
|
|
|
gl_Position = vec4(uv_interp, 1.0, 1.0);
|
2022-02-20 01:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
#[fragment]
|
|
|
|
|
|
|
|
#define M_PI 3.14159265359
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
#include "tonemap_inc.glsl"
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
in vec2 uv_interp;
|
|
|
|
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
uniform samplerCube radiance; //texunit:-1
|
|
|
|
#ifdef USE_CUBEMAP_PASS
|
|
|
|
uniform samplerCube half_res; //texunit:-2
|
|
|
|
uniform samplerCube quarter_res; //texunit:-3
|
2023-01-28 05:03:00 +01:00
|
|
|
#elif defined(USE_MULTIVIEW)
|
|
|
|
uniform sampler2DArray half_res; //texunit:-2
|
|
|
|
uniform sampler2DArray quarter_res; //texunit:-3
|
2022-02-20 01:08:53 +01:00
|
|
|
#else
|
|
|
|
uniform sampler2D half_res; //texunit:-2
|
|
|
|
uniform sampler2D quarter_res; //texunit:-3
|
|
|
|
#endif
|
|
|
|
|
2022-04-03 18:56:43 +02:00
|
|
|
layout(std140) uniform GlobalShaderUniformData { //ubo:1
|
|
|
|
vec4 global_shader_uniforms[MAX_GLOBAL_SHADER_UNIFORMS];
|
2022-02-20 01:08:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DirectionalLightData {
|
|
|
|
vec4 direction_energy;
|
|
|
|
vec4 color_size;
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
2022-05-16 20:56:03 +02:00
|
|
|
layout(std140) uniform DirectionalLights { //ubo:4
|
2022-02-20 01:08:53 +01:00
|
|
|
DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
|
|
|
}
|
|
|
|
directional_lights;
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
2022-05-16 20:56:03 +02:00
|
|
|
layout(std140) uniform MaterialUniforms{ //ubo:3
|
2022-02-20 01:08:53 +01:00
|
|
|
|
|
|
|
#MATERIAL_UNIFORMS
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
};
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
2022-04-30 00:34:01 +02:00
|
|
|
/* clang-format on */
|
2022-02-20 01:08:53 +01:00
|
|
|
#GLOBALS
|
|
|
|
|
|
|
|
#ifdef USE_CUBEMAP_PASS
|
|
|
|
#define AT_CUBEMAP_PASS true
|
|
|
|
#else
|
|
|
|
#define AT_CUBEMAP_PASS false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_HALF_RES_PASS
|
|
|
|
#define AT_HALF_RES_PASS true
|
|
|
|
#else
|
|
|
|
#define AT_HALF_RES_PASS false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_QUARTER_RES_PASS
|
|
|
|
#define AT_QUARTER_RES_PASS true
|
|
|
|
#else
|
|
|
|
#define AT_QUARTER_RES_PASS false
|
|
|
|
#endif
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
// mat4 is a waste of space, but we don't have an easy way to set a mat3 uniform for now
|
|
|
|
uniform mat4 orientation;
|
|
|
|
uniform vec4 projection;
|
|
|
|
uniform vec3 position;
|
|
|
|
uniform float time;
|
2024-01-19 06:14:36 +01:00
|
|
|
uniform float sky_energy_multiplier;
|
2022-08-01 01:20:24 +02:00
|
|
|
uniform float luminance_multiplier;
|
2022-04-30 00:34:01 +02:00
|
|
|
|
2022-05-16 20:56:03 +02:00
|
|
|
uniform float fog_aerial_perspective;
|
|
|
|
uniform vec3 fog_light_color;
|
|
|
|
uniform float fog_sun_scatter;
|
|
|
|
uniform bool fog_enabled;
|
|
|
|
uniform float fog_density;
|
|
|
|
uniform float z_far;
|
|
|
|
uniform uint directional_light_count;
|
|
|
|
|
2023-01-28 05:03:00 +01:00
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
layout(std140) uniform MultiviewData { // ubo:5
|
|
|
|
highp mat4 projection_matrix_view[MAX_VIEWS];
|
|
|
|
highp mat4 inv_projection_matrix_view[MAX_VIEWS];
|
|
|
|
highp vec4 eye_offset[MAX_VIEWS];
|
|
|
|
}
|
|
|
|
multiview_data;
|
|
|
|
#endif
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2022-09-13 19:39:04 +02:00
|
|
|
#ifdef USE_DEBANDING
|
|
|
|
// https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare
|
|
|
|
vec3 interleaved_gradient_noise(vec2 pos) {
|
|
|
|
const vec3 magic = vec3(0.06711056f, 0.00583715f, 52.9829189f);
|
|
|
|
float res = fract(magic.z * fract(dot(pos, magic.xy))) * 2.0 - 1.0;
|
|
|
|
return vec3(res, -res, res) / 255.0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
void main() {
|
|
|
|
vec3 cube_normal;
|
2023-01-28 05:03:00 +01:00
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
// In multiview our projection matrices will contain positional and rotational offsets that we need to properly unproject.
|
|
|
|
vec4 unproject = vec4(uv_interp.x, uv_interp.y, 1.0, 1.0);
|
|
|
|
vec4 unprojected = multiview_data.inv_projection_matrix_view[ViewIndex] * unproject;
|
|
|
|
cube_normal = unprojected.xyz / unprojected.w;
|
|
|
|
cube_normal += multiview_data.eye_offset[ViewIndex].xyz;
|
|
|
|
#else
|
2022-02-20 01:08:53 +01:00
|
|
|
cube_normal.z = -1.0;
|
|
|
|
cube_normal.x = (uv_interp.x + projection.x) / projection.y;
|
|
|
|
cube_normal.y = (-uv_interp.y - projection.z) / projection.w;
|
2023-01-28 05:03:00 +01:00
|
|
|
#endif
|
2022-02-20 01:08:53 +01:00
|
|
|
cube_normal = mat3(orientation) * cube_normal;
|
|
|
|
cube_normal = normalize(cube_normal);
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
vec2 uv = gl_FragCoord.xy; // uv_interp * 0.5 + 0.5;
|
2022-02-20 01:08:53 +01:00
|
|
|
|
2022-05-16 20:56:03 +02:00
|
|
|
vec2 panorama_coords = vec2(atan(cube_normal.x, -cube_normal.z), acos(cube_normal.y));
|
2022-02-20 01:08:53 +01:00
|
|
|
|
|
|
|
if (panorama_coords.x < 0.0) {
|
|
|
|
panorama_coords.x += M_PI * 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
panorama_coords /= vec2(M_PI * 2.0, M_PI);
|
|
|
|
|
|
|
|
vec3 color = vec3(0.0, 0.0, 0.0);
|
|
|
|
float alpha = 1.0; // Only available to subpasses
|
|
|
|
vec4 half_res_color = vec4(1.0);
|
|
|
|
vec4 quarter_res_color = vec4(1.0);
|
|
|
|
vec4 custom_fog = vec4(0.0);
|
|
|
|
|
|
|
|
#ifdef USE_CUBEMAP_PASS
|
|
|
|
#ifdef USES_HALF_RES_COLOR
|
2023-05-26 23:35:16 +02:00
|
|
|
half_res_color = texture(samplerCube(half_res, SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), cube_normal);
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
|
|
|
#ifdef USES_QUARTER_RES_COLOR
|
2023-05-26 23:35:16 +02:00
|
|
|
quarter_res_color = texture(samplerCube(quarter_res, SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), cube_normal);
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef USES_HALF_RES_COLOR
|
2023-01-28 05:03:00 +01:00
|
|
|
#ifdef USE_MULTIVIEW
|
2023-05-26 23:35:16 +02:00
|
|
|
half_res_color = textureLod(sampler2DArray(half_res, SAMPLER_LINEAR_CLAMP), vec3(uv, ViewIndex), 0.0);
|
2023-01-28 05:03:00 +01:00
|
|
|
#else
|
2023-05-26 23:35:16 +02:00
|
|
|
half_res_color = textureLod(sampler2D(half_res, SAMPLER_LINEAR_CLAMP), uv, 0.0);
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
2023-01-28 05:03:00 +01:00
|
|
|
#endif
|
2022-02-20 01:08:53 +01:00
|
|
|
#ifdef USES_QUARTER_RES_COLOR
|
2023-01-28 05:03:00 +01:00
|
|
|
#ifdef USE_MULTIVIEW
|
2023-05-26 23:35:16 +02:00
|
|
|
quarter_res_color = textureLod(sampler2DArray(quarter_res, SAMPLER_LINEAR_CLAMP), vec3(uv, ViewIndex), 0.0);
|
2023-01-28 05:03:00 +01:00
|
|
|
#else
|
2023-05-26 23:35:16 +02:00
|
|
|
quarter_res_color = textureLod(sampler2D(quarter_res, SAMPLER_LINEAR_CLAMP), uv, 0.0);
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
2023-01-28 05:03:00 +01:00
|
|
|
#endif
|
2022-02-20 01:08:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#CODE : SKY
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-19 06:14:36 +01:00
|
|
|
color *= sky_energy_multiplier;
|
2022-08-01 01:20:24 +02:00
|
|
|
|
2022-05-16 20:56:03 +02:00
|
|
|
// Convert to Linear for tonemapping so color matches scene shader better
|
|
|
|
color = srgb_to_linear(color);
|
2022-04-30 00:34:01 +02:00
|
|
|
color *= exposure;
|
2024-01-19 06:14:36 +01:00
|
|
|
#ifdef APPLY_TONEMAPPING
|
2022-04-30 00:34:01 +02:00
|
|
|
color = apply_tonemapping(color, white);
|
2024-01-19 06:14:36 +01:00
|
|
|
#endif
|
2022-04-30 00:34:01 +02:00
|
|
|
color = linear_to_srgb(color);
|
2022-02-20 01:08:53 +01:00
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
#ifdef USE_BCS
|
|
|
|
color = apply_bcs(color, bcs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_COLOR_CORRECTION
|
|
|
|
color = apply_color_correction(color, color_correction);
|
|
|
|
#endif
|
|
|
|
|
2024-01-19 06:14:36 +01:00
|
|
|
frag_color.rgb = color * luminance_multiplier;
|
2022-04-30 00:34:01 +02:00
|
|
|
frag_color.a = alpha;
|
2022-09-13 19:39:04 +02:00
|
|
|
|
|
|
|
#ifdef USE_DEBANDING
|
2024-01-19 06:14:36 +01:00
|
|
|
frag_color.rgb += interleaved_gradient_noise(gl_FragCoord.xy) * sky_energy_multiplier * luminance_multiplier;
|
2022-09-13 19:39:04 +02:00
|
|
|
#endif
|
2022-02-20 01:08:53 +01:00
|
|
|
}
|