2020-05-18 10:56:22 +02:00
|
|
|
#[vertex]
|
2020-04-11 19:43:12 +02:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
2021-04-13 22:01:43 +02:00
|
|
|
#VERSION_DEFINES
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
#ifdef has_VK_KHR_multiview
|
|
|
|
#extension GL_EXT_multiview : enable
|
|
|
|
#define ViewIndex gl_ViewIndex
|
|
|
|
#else // has_VK_KHR_multiview
|
|
|
|
#define ViewIndex 0
|
|
|
|
#endif // has_VK_KHR_multiview
|
|
|
|
#endif //MULTIVIEW
|
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
#define FLAG_FLIP_Y (1 << 0)
|
|
|
|
#define FLAG_USE_SECTION (1 << 1)
|
|
|
|
#define FLAG_FORCE_LUMINANCE (1 << 2)
|
|
|
|
#define FLAG_ALPHA_TO_ZERO (1 << 3)
|
|
|
|
#define FLAG_SRGB (1 << 4)
|
|
|
|
#define FLAG_ALPHA_TO_ONE (1 << 5)
|
|
|
|
#define FLAG_LINEAR (1 << 6)
|
|
|
|
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
layout(location = 0) out vec3 uv_interp;
|
|
|
|
#else
|
2020-04-11 19:43:12 +02:00
|
|
|
layout(location = 0) out vec2 uv_interp;
|
2021-12-14 02:44:12 +01:00
|
|
|
#endif
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2022-02-11 18:40:24 +01:00
|
|
|
layout(push_constant, std430) uniform Params {
|
2020-04-11 19:43:12 +02:00
|
|
|
vec4 section;
|
|
|
|
vec2 pixel_size;
|
2022-11-17 21:36:47 +01:00
|
|
|
float luminance_multiplier;
|
|
|
|
uint flags;
|
2022-11-10 21:07:54 +01:00
|
|
|
|
|
|
|
vec4 color;
|
2020-04-11 19:43:12 +02:00
|
|
|
}
|
|
|
|
params;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0));
|
2021-12-14 02:44:12 +01:00
|
|
|
uv_interp.xy = base_arr[gl_VertexIndex];
|
|
|
|
#ifdef MULTIVIEW
|
|
|
|
uv_interp.z = ViewIndex;
|
|
|
|
#endif
|
|
|
|
vec2 vpos = uv_interp.xy;
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_USE_SECTION)) {
|
2020-04-14 05:05:21 +02:00
|
|
|
vpos = params.section.xy + vpos * params.section.zw;
|
2020-04-11 19:43:12 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 05:05:21 +02:00
|
|
|
gl_Position = vec4(vpos * 2.0 - 1.0, 0.0, 1.0);
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_FLIP_Y)) {
|
2020-04-11 19:43:12 +02:00
|
|
|
uv_interp.y = 1.0 - uv_interp.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 10:56:22 +02:00
|
|
|
#[fragment]
|
2020-04-11 19:43:12 +02:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
2021-04-13 22:01:43 +02:00
|
|
|
#VERSION_DEFINES
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
#ifdef has_VK_KHR_multiview
|
|
|
|
#extension GL_EXT_multiview : enable
|
|
|
|
#define ViewIndex gl_ViewIndex
|
|
|
|
#else // has_VK_KHR_multiview
|
|
|
|
#define ViewIndex 0
|
|
|
|
#endif // has_VK_KHR_multiview
|
|
|
|
#endif //MULTIVIEW
|
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
#define FLAG_FLIP_Y (1 << 0)
|
|
|
|
#define FLAG_USE_SECTION (1 << 1)
|
|
|
|
#define FLAG_FORCE_LUMINANCE (1 << 2)
|
|
|
|
#define FLAG_ALPHA_TO_ZERO (1 << 3)
|
|
|
|
#define FLAG_SRGB (1 << 4)
|
|
|
|
#define FLAG_ALPHA_TO_ONE (1 << 5)
|
|
|
|
#define FLAG_LINEAR (1 << 6)
|
|
|
|
|
2022-02-11 18:40:24 +01:00
|
|
|
layout(push_constant, std430) uniform Params {
|
2020-04-11 19:43:12 +02:00
|
|
|
vec4 section;
|
|
|
|
vec2 pixel_size;
|
2022-11-17 21:36:47 +01:00
|
|
|
float luminance_multiplier;
|
|
|
|
uint flags;
|
2022-11-10 21:07:54 +01:00
|
|
|
|
|
|
|
vec4 color;
|
2020-05-18 10:56:22 +02:00
|
|
|
}
|
|
|
|
params;
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2022-12-12 23:10:06 +01:00
|
|
|
#ifndef MODE_SET_COLOR
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
layout(location = 0) in vec3 uv_interp;
|
|
|
|
#else
|
2020-04-11 19:43:12 +02:00
|
|
|
layout(location = 0) in vec2 uv_interp;
|
2021-12-14 02:44:12 +01:00
|
|
|
#endif
|
2020-04-11 19:43:12 +02:00
|
|
|
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2DArray source_color;
|
|
|
|
#ifdef MODE_TWO_SOURCES
|
|
|
|
layout(set = 1, binding = 0) uniform sampler2DArray source_depth;
|
|
|
|
layout(location = 1) out float depth;
|
|
|
|
#endif /* MODE_TWO_SOURCES */
|
2022-02-11 12:33:54 +01:00
|
|
|
#else /* MULTIVIEW */
|
2020-04-11 19:43:12 +02:00
|
|
|
layout(set = 0, binding = 0) uniform sampler2D source_color;
|
2020-06-25 15:33:28 +02:00
|
|
|
#ifdef MODE_TWO_SOURCES
|
|
|
|
layout(set = 1, binding = 0) uniform sampler2D source_color2;
|
2021-12-14 02:44:12 +01:00
|
|
|
#endif /* MODE_TWO_SOURCES */
|
|
|
|
#endif /* MULTIVIEW */
|
2022-12-12 23:10:06 +01:00
|
|
|
#endif /* !SET_COLOR */
|
2021-12-14 02:44:12 +01:00
|
|
|
|
2020-04-11 19:43:12 +02:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2020-06-25 15:33:28 +02:00
|
|
|
vec3 linear_to_srgb(vec3 color) {
|
|
|
|
//if going to srgb, clamp from 0 to 1.
|
|
|
|
color = clamp(color, vec3(0.0), vec3(1.0));
|
|
|
|
const vec3 a = vec3(0.055f);
|
|
|
|
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
|
|
|
|
}
|
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
vec3 srgb_to_linear(vec3 color) {
|
|
|
|
return mix(pow((color.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), color.rgb * (1.0 / 12.92), lessThan(color.rgb, vec3(0.04045)));
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:43:12 +02:00
|
|
|
void main() {
|
2022-11-10 21:07:54 +01:00
|
|
|
#ifdef MODE_SET_COLOR
|
|
|
|
frag_color = params.color;
|
|
|
|
#else
|
|
|
|
|
2021-12-14 02:44:12 +01:00
|
|
|
#ifdef MULTIVIEW
|
|
|
|
vec3 uv = uv_interp;
|
|
|
|
#else
|
2020-04-14 05:05:21 +02:00
|
|
|
vec2 uv = uv_interp;
|
2021-12-14 02:44:12 +01:00
|
|
|
#endif
|
2020-04-14 22:05:45 +02:00
|
|
|
|
|
|
|
#ifdef MODE_PANORAMA_TO_DP
|
2021-12-14 02:44:12 +01:00
|
|
|
// Note, multiview and panorama should not be mixed at this time
|
2020-04-14 22:05:45 +02:00
|
|
|
|
|
|
|
//obtain normal from dual paraboloid uv
|
|
|
|
#define M_PI 3.14159265359
|
|
|
|
|
|
|
|
float side;
|
|
|
|
uv.y = modf(uv.y * 2.0, side);
|
|
|
|
side = side * 2.0 - 1.0;
|
|
|
|
vec3 normal = vec3(uv * 2.0 - 1.0, 0.0);
|
|
|
|
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
|
|
|
normal *= -side;
|
|
|
|
normal = normalize(normal);
|
|
|
|
|
|
|
|
//now convert normal to panorama uv
|
|
|
|
|
|
|
|
vec2 st = vec2(atan(normal.x, normal.z), acos(normal.y));
|
|
|
|
|
2020-05-18 10:56:22 +02:00
|
|
|
if (st.x < 0.0) {
|
2020-04-14 22:05:45 +02:00
|
|
|
st.x += M_PI * 2.0;
|
2020-05-18 10:56:22 +02:00
|
|
|
}
|
2020-04-14 22:05:45 +02:00
|
|
|
|
|
|
|
uv = st / vec2(M_PI * 2.0, M_PI);
|
|
|
|
|
|
|
|
if (side < 0.0) {
|
|
|
|
//uv.y = 1.0 - uv.y;
|
|
|
|
uv = 1.0 - uv;
|
|
|
|
}
|
2022-02-11 12:33:54 +01:00
|
|
|
#endif /* MODE_PANORAMA_TO_DP */
|
2021-12-14 02:44:12 +01:00
|
|
|
|
|
|
|
#ifdef MULTIVIEW
|
|
|
|
vec4 color = textureLod(source_color, uv, 0.0);
|
|
|
|
#ifdef MODE_TWO_SOURCES
|
|
|
|
// In multiview our 2nd input will be our depth map
|
|
|
|
depth = textureLod(source_depth, uv, 0.0).r;
|
|
|
|
#endif /* MODE_TWO_SOURCES */
|
|
|
|
|
2022-02-11 12:33:54 +01:00
|
|
|
#else /* MULTIVIEW */
|
2020-04-14 05:05:21 +02:00
|
|
|
vec4 color = textureLod(source_color, uv, 0.0);
|
2020-06-25 15:33:28 +02:00
|
|
|
#ifdef MODE_TWO_SOURCES
|
|
|
|
color += textureLod(source_color2, uv, 0.0);
|
2021-12-14 02:44:12 +01:00
|
|
|
#endif /* MODE_TWO_SOURCES */
|
|
|
|
#endif /* MULTIVIEW */
|
2022-02-11 12:33:54 +01:00
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_FORCE_LUMINANCE)) {
|
2020-04-11 19:43:12 +02:00
|
|
|
color.rgb = vec3(max(max(color.r, color.g), color.b));
|
|
|
|
}
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_ALPHA_TO_ZERO)) {
|
2020-04-14 05:05:21 +02:00
|
|
|
color.rgb *= color.a;
|
|
|
|
}
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_SRGB)) {
|
2020-06-25 15:33:28 +02:00
|
|
|
color.rgb = linear_to_srgb(color.rgb);
|
|
|
|
}
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_ALPHA_TO_ONE)) {
|
2022-11-10 21:07:54 +01:00
|
|
|
color.a = 1.0;
|
|
|
|
}
|
2022-11-17 21:36:47 +01:00
|
|
|
if (bool(params.flags & FLAG_LINEAR)) {
|
|
|
|
color.rgb = srgb_to_linear(color.rgb);
|
|
|
|
}
|
2022-02-11 12:33:54 +01:00
|
|
|
|
2022-11-17 21:36:47 +01:00
|
|
|
frag_color = color / params.luminance_multiplier;
|
2022-11-10 21:07:54 +01:00
|
|
|
#endif // MODE_SET_COLOR
|
2020-04-11 19:43:12 +02:00
|
|
|
}
|