2020-05-18 08:56:22 +00:00
|
|
|
#[vertex]
|
2019-08-26 20:43:58 +00:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
2021-04-13 20:01:43 +00:00
|
|
|
#VERSION_DEFINES
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
#define MAX_VIEWS 2
|
|
|
|
|
|
|
|
#if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
|
|
|
|
#extension GL_EXT_multiview : enable
|
|
|
|
#endif
|
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(location = 0) out vec2 uv_interp;
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2022-02-11 17:40:24 +00:00
|
|
|
layout(push_constant, std430) uniform Params {
|
2019-08-26 20:43:58 +00:00
|
|
|
mat3 orientation;
|
2022-12-15 11:20:06 +00:00
|
|
|
vec4 projection; // only applicable if not multiview
|
2022-07-31 23:20:24 +00:00
|
|
|
vec3 position;
|
2020-03-20 00:32:19 +00:00
|
|
|
float time;
|
2022-07-31 23:20:24 +00:00
|
|
|
vec3 pad;
|
2021-07-26 11:31:15 +00:00
|
|
|
float luminance_multiplier;
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
params;
|
2019-08-26 20:43:58 +00:00
|
|
|
|
|
|
|
void main() {
|
2023-08-05 20:55:43 +00:00
|
|
|
vec2 base_arr[3] = vec2[](vec2(-1.0, -3.0), vec2(-1.0, 1.0), vec2(3.0, 1.0));
|
2019-08-26 20:43:58 +00:00
|
|
|
uv_interp = base_arr[gl_VertexIndex];
|
2020-03-20 00:32:19 +00:00
|
|
|
gl_Position = vec4(uv_interp, 1.0, 1.0);
|
2019-08-26 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 08:56:22 +00:00
|
|
|
#[fragment]
|
2019-08-26 20:43:58 +00:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
2021-04-13 20:01:43 +00:00
|
|
|
#VERSION_DEFINES
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
#ifdef has_VK_KHR_multiview
|
|
|
|
#extension GL_EXT_multiview : enable
|
|
|
|
#define ViewIndex gl_ViewIndex
|
|
|
|
#else // has_VK_KHR_multiview
|
|
|
|
// !BAS! This needs to become an input once we implement our fallback!
|
|
|
|
#define ViewIndex 0
|
|
|
|
#endif // has_VK_KHR_multiview
|
|
|
|
#else // USE_MULTIVIEW
|
|
|
|
// Set to zero, not supported in non stereo
|
|
|
|
#define ViewIndex 0
|
|
|
|
#endif //USE_MULTIVIEW
|
|
|
|
|
2019-08-26 20:43:58 +00:00
|
|
|
#define M_PI 3.14159265359
|
2021-05-07 13:19:04 +00:00
|
|
|
#define MAX_VIEWS 2
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(location = 0) in vec2 uv_interp;
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2022-02-11 17:40:24 +00:00
|
|
|
layout(push_constant, std430) uniform Params {
|
2019-08-26 20:43:58 +00:00
|
|
|
mat3 orientation;
|
2022-12-15 11:20:06 +00:00
|
|
|
vec4 projection; // only applicable if not multiview
|
2022-07-31 23:20:24 +00:00
|
|
|
vec3 position;
|
2021-05-07 13:19:04 +00:00
|
|
|
float time;
|
2022-07-31 23:20:24 +00:00
|
|
|
vec3 pad;
|
2021-07-26 11:31:15 +00:00
|
|
|
float luminance_multiplier;
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
params;
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2023-05-26 21:35:16 +00:00
|
|
|
#include "../samplers_inc.glsl"
|
2020-03-20 00:32:19 +00:00
|
|
|
|
2022-04-03 16:56:43 +00:00
|
|
|
layout(set = 0, binding = 1, std430) restrict readonly buffer GlobalShaderUniformData {
|
2020-04-17 02:52:00 +00:00
|
|
|
vec4 data[];
|
|
|
|
}
|
2022-04-03 16:56:43 +00:00
|
|
|
global_shader_uniforms;
|
2020-04-17 02:52:00 +00:00
|
|
|
|
2022-12-15 11:20:06 +00:00
|
|
|
layout(set = 0, binding = 2, std140) uniform SkySceneData {
|
2023-06-19 12:39:46 +00:00
|
|
|
mat4 combined_reprojection[2];
|
2022-12-15 11:20:06 +00:00
|
|
|
mat4 view_inv_projections[2];
|
|
|
|
vec4 view_eye_offsets[2];
|
|
|
|
|
2022-02-23 22:54:06 +00:00
|
|
|
bool volumetric_fog_enabled; // 4 - 4
|
|
|
|
float volumetric_fog_inv_length; // 4 - 8
|
|
|
|
float volumetric_fog_detail_spread; // 4 - 12
|
|
|
|
float volumetric_fog_sky_affect; // 4 - 16
|
|
|
|
|
|
|
|
bool fog_enabled; // 4 - 20
|
|
|
|
float fog_sky_affect; // 4 - 24
|
|
|
|
float fog_density; // 4 - 28
|
|
|
|
float fog_sun_scatter; // 4 - 32
|
|
|
|
|
|
|
|
vec3 fog_light_color; // 12 - 44
|
|
|
|
float fog_aerial_perspective; // 4 - 48
|
|
|
|
|
|
|
|
float z_far; // 4 - 52
|
|
|
|
uint directional_light_count; // 4 - 56
|
|
|
|
uint pad1; // 4 - 60
|
|
|
|
uint pad2; // 4 - 64
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
2022-12-15 11:20:06 +00:00
|
|
|
sky_scene_data;
|
2020-08-18 04:12:51 +00:00
|
|
|
|
|
|
|
struct DirectionalLightData {
|
|
|
|
vec4 direction_energy;
|
|
|
|
vec4 color_size;
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
layout(set = 0, binding = 3, std140) uniform DirectionalLights {
|
|
|
|
DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
|
|
|
}
|
|
|
|
directional_lights;
|
|
|
|
|
2021-04-13 20:01:43 +00:00
|
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
2020-03-20 00:32:19 +00:00
|
|
|
layout(set = 1, binding = 0, std140) uniform MaterialUniforms{
|
2021-04-13 20:01:43 +00:00
|
|
|
#MATERIAL_UNIFORMS
|
2019-09-15 09:58:38 +00:00
|
|
|
} material;
|
|
|
|
#endif
|
|
|
|
|
2020-03-20 00:32:19 +00:00
|
|
|
layout(set = 2, binding = 0) uniform textureCube radiance;
|
2020-03-24 05:55:11 +00:00
|
|
|
#ifdef USE_CUBEMAP_PASS
|
|
|
|
layout(set = 2, binding = 1) uniform textureCube half_res;
|
|
|
|
layout(set = 2, binding = 2) uniform textureCube quarter_res;
|
2022-12-15 11:20:06 +00:00
|
|
|
#elif defined(USE_MULTIVIEW)
|
|
|
|
layout(set = 2, binding = 1) uniform texture2DArray half_res;
|
|
|
|
layout(set = 2, binding = 2) uniform texture2DArray quarter_res;
|
2020-03-24 05:55:11 +00:00
|
|
|
#else
|
2020-03-20 00:32:19 +00:00
|
|
|
layout(set = 2, binding = 1) uniform texture2D half_res;
|
|
|
|
layout(set = 2, binding = 2) uniform texture2D quarter_res;
|
2020-03-24 05:55:11 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-18 04:12:51 +00:00
|
|
|
layout(set = 3, binding = 0) uniform texture3D volumetric_fog_texture;
|
|
|
|
|
2020-03-24 05:55:11 +00:00
|
|
|
#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
|
2019-09-15 09:58:38 +00:00
|
|
|
|
2021-04-13 20:01:43 +00:00
|
|
|
#GLOBALS
|
2019-08-26 20:43:58 +00:00
|
|
|
|
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2022-09-13 17:39:04 +00: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
|
|
|
|
|
2020-08-18 04:12:51 +00:00
|
|
|
vec4 volumetric_fog_process(vec2 screen_uv) {
|
2023-06-19 12:39:46 +00:00
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
vec4 reprojected = sky_scene_data.combined_reprojection[ViewIndex] * (vec4(screen_uv * 2.0 - 1.0, 1.0, 1.0) * sky_scene_data.z_far);
|
|
|
|
vec3 fog_pos = vec3(reprojected.xy / reprojected.w, 1.0) * 0.5 + 0.5;
|
|
|
|
#else
|
2020-08-18 04:12:51 +00:00
|
|
|
vec3 fog_pos = vec3(screen_uv, 1.0);
|
2023-06-19 12:39:46 +00:00
|
|
|
#endif
|
2020-08-18 04:12:51 +00:00
|
|
|
|
2023-05-26 21:35:16 +00:00
|
|
|
return texture(sampler3D(volumetric_fog_texture, SAMPLER_LINEAR_CLAMP), fog_pos);
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 05:48:04 +00:00
|
|
|
vec4 fog_process(vec3 view, vec3 sky_color) {
|
2022-12-15 11:20:06 +00:00
|
|
|
vec3 fog_color = mix(sky_scene_data.fog_light_color, sky_color, sky_scene_data.fog_aerial_perspective);
|
2020-08-18 04:12:51 +00:00
|
|
|
|
2022-12-15 11:20:06 +00:00
|
|
|
if (sky_scene_data.fog_sun_scatter > 0.001) {
|
2020-08-18 04:12:51 +00:00
|
|
|
vec4 sun_scatter = vec4(0.0);
|
|
|
|
float sun_total = 0.0;
|
2022-12-15 11:20:06 +00:00
|
|
|
for (uint i = 0; i < sky_scene_data.directional_light_count; i++) {
|
2020-08-18 04:12:51 +00:00
|
|
|
vec3 light_color = directional_lights.data[i].color_size.xyz * directional_lights.data[i].direction_energy.w;
|
|
|
|
float light_amount = pow(max(dot(view, directional_lights.data[i].direction_energy.xyz), 0.0), 8.0);
|
2022-12-15 11:20:06 +00:00
|
|
|
fog_color += light_color * light_amount * sky_scene_data.fog_sun_scatter;
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 22:54:06 +00:00
|
|
|
return vec4(fog_color, 1.0);
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 20:43:58 +00:00
|
|
|
void main() {
|
|
|
|
vec3 cube_normal;
|
2022-12-15 11:20:06 +00: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 = sky_scene_data.view_inv_projections[ViewIndex] * unproject;
|
|
|
|
cube_normal = unprojected.xyz / unprojected.w;
|
|
|
|
cube_normal += sky_scene_data.view_eye_offsets[ViewIndex].xyz;
|
|
|
|
#else
|
2019-09-15 09:58:38 +00:00
|
|
|
cube_normal.z = -1.0;
|
2022-12-15 11:20:06 +00:00
|
|
|
cube_normal.x = (cube_normal.z * (-uv_interp.x - params.projection.x)) / params.projection.y;
|
|
|
|
cube_normal.y = -(cube_normal.z * (-uv_interp.y - params.projection.z)) / params.projection.w;
|
|
|
|
#endif
|
2019-08-26 20:43:58 +00:00
|
|
|
cube_normal = mat3(params.orientation) * cube_normal;
|
2020-03-20 00:32:19 +00:00
|
|
|
cube_normal = normalize(cube_normal);
|
|
|
|
|
|
|
|
vec2 uv = uv_interp * 0.5 + 0.5;
|
|
|
|
|
2022-03-09 03:51:43 +00:00
|
|
|
vec2 panorama_coords = vec2(atan(cube_normal.x, -cube_normal.z), acos(cube_normal.y));
|
2020-03-20 00:32:19 +00:00
|
|
|
|
|
|
|
if (panorama_coords.x < 0.0) {
|
|
|
|
panorama_coords.x += M_PI * 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
panorama_coords /= vec2(M_PI * 2.0, M_PI);
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2019-09-15 09:58:38 +00:00
|
|
|
vec3 color = vec3(0.0, 0.0, 0.0);
|
2020-03-20 00:32:19 +00:00
|
|
|
float alpha = 1.0; // Only available to subpasses
|
2020-03-24 05:55:11 +00:00
|
|
|
vec4 half_res_color = vec4(1.0);
|
|
|
|
vec4 quarter_res_color = vec4(1.0);
|
2020-08-21 03:24:46 +00:00
|
|
|
vec4 custom_fog = vec4(0.0);
|
2020-03-24 05:55:11 +00:00
|
|
|
|
|
|
|
#ifdef USE_CUBEMAP_PASS
|
2022-12-15 11:20:06 +00:00
|
|
|
|
2020-03-24 05:55:11 +00:00
|
|
|
#ifdef USES_HALF_RES_COLOR
|
2023-05-26 21:35:16 +00:00
|
|
|
half_res_color = texture(samplerCube(half_res, SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), cube_normal) / params.luminance_multiplier;
|
2020-03-24 05:55:11 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USES_QUARTER_RES_COLOR
|
2023-05-26 21:35:16 +00:00
|
|
|
quarter_res_color = texture(samplerCube(quarter_res, SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), cube_normal) / params.luminance_multiplier;
|
2020-03-24 05:55:11 +00:00
|
|
|
#endif
|
2022-12-15 11:20:06 +00:00
|
|
|
|
2020-03-24 05:55:11 +00:00
|
|
|
#else
|
2022-12-15 11:20:06 +00:00
|
|
|
|
2020-03-24 05:55:11 +00:00
|
|
|
#ifdef USES_HALF_RES_COLOR
|
2022-12-15 11:20:06 +00:00
|
|
|
#ifdef USE_MULTIVIEW
|
2023-05-26 21:35:16 +00:00
|
|
|
half_res_color = textureLod(sampler2DArray(half_res, SAMPLER_LINEAR_CLAMP), vec3(uv, ViewIndex), 0.0) / params.luminance_multiplier;
|
2022-12-15 11:20:06 +00:00
|
|
|
#else
|
2023-05-26 21:35:16 +00:00
|
|
|
half_res_color = textureLod(sampler2D(half_res, SAMPLER_LINEAR_CLAMP), uv, 0.0) / params.luminance_multiplier;
|
2022-12-15 11:20:06 +00:00
|
|
|
#endif // USE_MULTIVIEW
|
|
|
|
#endif // USES_HALF_RES_COLOR
|
|
|
|
|
2020-03-24 05:55:11 +00:00
|
|
|
#ifdef USES_QUARTER_RES_COLOR
|
2022-12-15 11:20:06 +00:00
|
|
|
#ifdef USE_MULTIVIEW
|
2023-05-26 21:35:16 +00:00
|
|
|
quarter_res_color = textureLod(sampler2DArray(quarter_res, SAMPLER_LINEAR_CLAMP), vec3(uv, ViewIndex), 0.0) / params.luminance_multiplier;
|
2022-12-15 11:20:06 +00:00
|
|
|
#else
|
2023-05-26 21:35:16 +00:00
|
|
|
quarter_res_color = textureLod(sampler2D(quarter_res, SAMPLER_LINEAR_CLAMP), uv, 0.0) / params.luminance_multiplier;
|
2022-12-15 11:20:06 +00:00
|
|
|
#endif // USE_MULTIVIEW
|
|
|
|
#endif // USES_QUARTER_RES_COLOR
|
|
|
|
|
|
|
|
#endif //USE_CUBEMAP_PASS
|
2019-09-15 09:58:38 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
2021-04-13 20:01:43 +00:00
|
|
|
#CODE : SKY
|
2019-09-15 09:58:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-31 23:20:24 +00:00
|
|
|
frag_color.rgb = color;
|
2020-03-20 00:32:19 +00:00
|
|
|
frag_color.a = alpha;
|
2020-04-11 08:20:24 +00:00
|
|
|
|
2023-04-08 07:52:33 +00:00
|
|
|
// For mobile renderer we're multiplying by 0.5 as we're using a UNORM buffer.
|
|
|
|
// For both mobile and clustered, we also bake in the exposure value for the environment and camera.
|
|
|
|
frag_color.rgb = frag_color.rgb * params.luminance_multiplier;
|
|
|
|
|
2020-08-18 04:12:51 +00:00
|
|
|
#if !defined(DISABLE_FOG) && !defined(USE_CUBEMAP_PASS)
|
|
|
|
|
2020-10-15 19:59:08 +00:00
|
|
|
// Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky.
|
2022-12-15 11:20:06 +00:00
|
|
|
if (sky_scene_data.fog_enabled) {
|
2020-08-21 05:48:04 +00:00
|
|
|
vec4 fog = fog_process(cube_normal, frag_color.rgb);
|
2022-12-15 11:20:06 +00:00
|
|
|
frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a * sky_scene_data.fog_sky_affect);
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 11:20:06 +00:00
|
|
|
if (sky_scene_data.volumetric_fog_enabled) {
|
2020-10-15 19:59:08 +00:00
|
|
|
vec4 fog = volumetric_fog_process(uv);
|
2022-12-15 11:20:06 +00:00
|
|
|
frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a * sky_scene_data.volumetric_fog_sky_affect);
|
2020-08-18 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 03:24:46 +00:00
|
|
|
if (custom_fog.a > 0.0) {
|
|
|
|
frag_color.rgb = mix(frag_color.rgb, custom_fog.rgb, custom_fog.a);
|
|
|
|
}
|
|
|
|
|
2020-08-18 04:12:51 +00:00
|
|
|
#endif // DISABLE_FOG
|
|
|
|
|
2022-07-31 23:20:24 +00:00
|
|
|
// Blending is disabled for Sky, so alpha doesn't blend.
|
|
|
|
// Alpha is used for subsurface scattering so make sure it doesn't get applied to Sky.
|
2020-04-11 08:20:24 +00:00
|
|
|
if (!AT_CUBEMAP_PASS && !AT_HALF_RES_PASS && !AT_QUARTER_RES_PASS) {
|
|
|
|
frag_color.a = 0.0;
|
|
|
|
}
|
2021-07-26 11:31:15 +00:00
|
|
|
|
2022-09-13 17:39:04 +00:00
|
|
|
#ifdef USE_DEBANDING
|
2023-04-14 09:25:33 +00:00
|
|
|
frag_color.rgb += interleaved_gradient_noise(gl_FragCoord.xy) * params.luminance_multiplier;
|
2022-09-13 17:39:04 +00:00
|
|
|
#endif
|
2019-08-26 20:43:58 +00:00
|
|
|
}
|