2021-01-18 08:13:52 +00:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
layout (set = 0, binding = 1) uniform sampler2D Texture;
|
2021-01-23 04:51:09 +00:00
|
|
|
layout (set = 0, binding = 2) uniform sampler2D GlowMap;
|
|
|
|
layout (set = 0, binding = 3) uniform sampler2D LightMap;
|
2021-01-23 11:42:53 +00:00
|
|
|
layout (set = 0, binding = 4) uniform sampler2DArray SkySheet;
|
|
|
|
layout (set = 0, binding = 5) uniform samplerCube SkyCube;
|
2021-01-18 08:13:52 +00:00
|
|
|
|
|
|
|
layout (push_constant) uniform PushConstants {
|
|
|
|
vec4 fog;
|
2021-01-23 14:58:34 +00:00
|
|
|
float time;
|
2022-05-21 08:48:45 +00:00
|
|
|
float alpha;
|
2021-01-18 08:13:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
layout (location = 0) in vec4 tl_st;
|
2021-01-19 16:25:54 +00:00
|
|
|
layout (location = 1) in vec3 direction;
|
2021-01-18 08:13:52 +00:00
|
|
|
|
|
|
|
layout (location = 0) out vec4 frag_color;
|
|
|
|
|
|
|
|
layout (constant_id = 0) const bool doWarp = false;
|
|
|
|
layout (constant_id = 1) const bool doLight = true;
|
|
|
|
layout (constant_id = 2) const bool doSkyCube = false;
|
|
|
|
layout (constant_id = 3) const bool doSkySheet = false;
|
|
|
|
|
|
|
|
const float PI = 3.14159265;
|
|
|
|
const float SPEED = 20.0;
|
|
|
|
const float CYCLE = 128.0;
|
|
|
|
const float FACTOR = PI * 2.0 / CYCLE;
|
|
|
|
const vec2 BIAS = vec2 (1.0, 1.0);
|
|
|
|
const float SCALE = 8.0;
|
|
|
|
|
|
|
|
vec2
|
|
|
|
warp_st (vec2 st, float time)
|
|
|
|
{
|
|
|
|
vec2 angle = st.ts * CYCLE / 2.0;
|
|
|
|
vec2 phase = vec2 (time, time) * SPEED;
|
|
|
|
return st + (sin ((angle + phase) * FACTOR) + BIAS) / SCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
fogBlend (vec4 color)
|
|
|
|
{
|
|
|
|
float az = fog.a * gl_FragCoord.z / gl_FragCoord.w;
|
|
|
|
vec3 fog_color = fog.rgb;
|
|
|
|
float fog_factor = exp (-az * az);
|
|
|
|
|
|
|
|
return vec4 (mix (fog_color.rgb, color.rgb, fog_factor), color.a);
|
|
|
|
}
|
2021-01-23 11:42:53 +00:00
|
|
|
|
2021-01-18 08:13:52 +00:00
|
|
|
vec4
|
|
|
|
sky_sheet (vec3 dir, float time)
|
|
|
|
{
|
|
|
|
float len;
|
|
|
|
vec2 flow = vec2 (1.0, 1.0);
|
|
|
|
vec2 base;
|
|
|
|
vec3 st1, st2;
|
|
|
|
vec4 c1, c2, c;
|
|
|
|
|
|
|
|
dir.z *= 3.0;
|
|
|
|
len = dot (dir, dir);
|
|
|
|
len = SCALE * inversesqrt (len);
|
|
|
|
base = dir.yx * vec2(1.0, -1.0) * len;
|
|
|
|
|
|
|
|
st1 = vec3 (base + flow * time / 8.0, 0);
|
|
|
|
st2 = vec3 (base + flow * time / 16.0, 1);
|
|
|
|
|
|
|
|
c1 = texture (SkySheet, st1);
|
|
|
|
c2 = texture (SkySheet, st2);
|
|
|
|
|
|
|
|
c = vec4 (mix (c2.rgb, c1.rgb, c1.a), max (c1.a, c2.a));
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
2021-01-21 05:37:39 +00:00
|
|
|
|
2021-01-18 08:13:52 +00:00
|
|
|
vec4
|
|
|
|
sky_cube (vec3 dir, float time)
|
|
|
|
{
|
|
|
|
// NOTE: quake's world is right-handed with Z up and X forward, but
|
|
|
|
// Vulkan's cube maps are left-handed with Y up and Z forward. The
|
|
|
|
// rotation to X foward is done by the Sky matrix so all that's left
|
|
|
|
// to do here is swizzle the Y and Z coordinates
|
|
|
|
return texture (SkyCube, dir.xzy);
|
|
|
|
}
|
2021-01-21 05:37:39 +00:00
|
|
|
|
2021-01-18 08:13:52 +00:00
|
|
|
vec4
|
|
|
|
sky_color (vec3 dir, float time)
|
|
|
|
{
|
|
|
|
if (!doSkySheet) {
|
2021-01-20 17:13:40 +00:00
|
|
|
return vec4 (1, 0, 1, 1);
|
|
|
|
//return sky_cube (dir, time);
|
2021-01-18 08:13:52 +00:00
|
|
|
} if (!doSkyCube) {
|
|
|
|
return sky_sheet (dir, time);
|
|
|
|
} else {
|
2021-01-21 05:37:39 +00:00
|
|
|
// can see through the sheet (may look funny when looking down)
|
2021-01-18 08:13:52 +00:00
|
|
|
// maybe have 4 sheet layers instead of 2?
|
|
|
|
vec4 c1 = sky_sheet (dir, time);
|
|
|
|
vec4 c2 = sky_cube (dir, time);
|
2021-01-21 05:37:39 +00:00
|
|
|
return vec4 (mix (c2.rgb, c1.rgb, c1.a), max (c1.a, c2.a));
|
2021-01-20 17:13:40 +00:00
|
|
|
return vec4 (1, 0, 1, 1);
|
2021-01-18 08:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-23 11:42:53 +00:00
|
|
|
|
2021-01-18 08:13:52 +00:00
|
|
|
void
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
vec4 c;
|
|
|
|
vec2 t_st = tl_st.xy;
|
|
|
|
vec2 l_st = tl_st.zw;
|
|
|
|
|
|
|
|
if (doWarp) {
|
|
|
|
t_st = warp_st (t_st, time);
|
|
|
|
}
|
2021-01-23 11:42:53 +00:00
|
|
|
if (doSkyCube || doSkySheet) {
|
2021-01-18 08:13:52 +00:00
|
|
|
c = sky_color (direction, time);
|
|
|
|
} else {
|
2021-01-19 16:25:54 +00:00
|
|
|
c = texture (Texture, t_st);
|
2021-01-23 11:42:53 +00:00
|
|
|
if (doLight) {
|
|
|
|
c *= vec4 (texture (LightMap, l_st).xyz, 1);
|
|
|
|
}
|
|
|
|
c += texture (GlowMap, t_st);
|
2021-01-18 08:13:52 +00:00
|
|
|
}
|
2021-01-21 17:20:32 +00:00
|
|
|
frag_color = c;//fogBlend (c);
|
2021-01-18 08:13:52 +00:00
|
|
|
}
|