ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
water_hq_03_rain_ripples.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file water_hq_03_rain_ripples.frag
5 * @brief Vulkan fragment shader: water hq 03 rain ripples.
6 */
7layout(set = 0, binding = 1, std140) uniform SpriteExtended {
8 vec4 mouse;
9 vec4 u0;
10 vec4 u1;
11 vec4 u2;
12 vec4 u3;
13 vec4 custom_uniforms[16];
14 vec4 audio_bands;
15 vec4 audio_history;
17#define time_f ext.u2.y
18
19layout(location = 0) in vec2 tc;
20layout(location = 0) out vec4 color;
21layout(set = 0, binding = 0) uniform sampler2D samp;
22
23
24/**
25 * @brief Evaluates hash21 for this shader effect.
26 * @param p Input value for the calculation.
27 * @return Computed float value.
28 */
29float hash21(vec2 p) {
30 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
31}
32/**
33 * @brief Evaluates safeUV for this shader effect.
34 * @param p Input value for the calculation.
35 * @return Computed vec2 value.
36 */
37vec2 safeUV(vec2 p) {
38 return 1.0 - abs(mod(p, 2.0) - 1.0);
39}
40
41/**
42 * @brief Evaluates rainLayer for this shader effect.
43 * @param uv Input value for the calculation.
44 * @param scale Input value for the calculation.
45 * @param seed Input value for the calculation.
46 * @return Computed vec2 value.
47 */
48vec2 rainLayer(vec2 uv, float scale, float seed) {
49 vec2 p = uv * scale;
50 vec2 id = floor(p);
51 vec2 f = fract(p) - 0.5;
52 float rnd = hash21(id + seed);
53 vec2 center = vec2(hash21(id + seed + 3.1), hash21(id + seed + 8.7)) - 0.5;
54 vec2 d = f - center * 0.65;
55 float age = fract(time_f * (0.28 + rnd * 0.18) + rnd);
56 float r = length(d);
57 float ring = exp(-90.0 * abs(r - age * 0.48)) * (1.0 - age);
58 return normalize(d + vec2(1e-5)) * ring / scale;
59}
60
61/**
62 * @brief Executes the fragment shader entry point.
63 */
64void main(void) {
65 vec2 ripple = rainLayer(tc, 7.0, 1.0) + rainLayer(tc + 0.17, 11.0, 19.0);
66 vec4 src = texture(samp, safeUV(tc + ripple * 0.72));
67 float sparkle = clamp(length(ripple) * 36.0, 0.0, 1.0);
68 color = vec4(src.rgb + vec3(0.10, 0.15, 0.18) * sparkle, texture(samp, tc).a);
69}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
ext
Definition 3high.frag:16
void main(void)
Executes the fragment shader entry point.
Definition 3high.frag:47
#define time_f
Definition 3high.frag:19
vec3 ripple(ivec2 p, ivec2 size)
Evaluates ripple for this shader effect.
#define seed
Definition air-bowl.frag:20
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
vec2 safeUV(vec2 p)
Evaluates safeUV for this shader effect.
vec2 rainLayer(vec2 uv, float scale, float seed)
Evaluates rainLayer for this shader effect.