ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ice.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file ice.frag
5 * @brief Vulkan fragment shader: ice.
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 iResolution ext.u0.zw
18#define time_f ext.u2.y
19
20layout(location = 0) out vec4 color;
21layout(location = 0) in vec2 tc;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23
24
25
26/**
27 * @brief Evaluates noise for this shader effect.
28 * @param p Input value for the calculation.
29 * @return Computed float value.
30 */
31float noise(vec2 p) {
32 return fract(sin(dot(p, vec2(12.9898,78.233))) * 43758.5453);
33}
34
35/**
36 * @brief Evaluates smoothNoise for this shader effect.
37 * @param p Input value for the calculation.
38 * @return Computed float value.
39 */
40float smoothNoise(vec2 p) {
41 vec2 i = floor(p);
42 vec2 f = fract(p);
43
44 float a = noise(i);
45 float b = noise(i + vec2(1.0, 0.0));
46 float c = noise(i + vec2(0.0, 1.0));
47 float d = noise(i + vec2(1.0, 1.0));
48
49 vec2 u = f * f * (3.0 - 2.0 * f);
50 return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b - c + a) * u.x * u.y;
51}
52
53/**
54 * @brief Evaluates fbm for this shader effect.
55 * @param p Input value for the calculation.
56 * @return Computed float value.
57 */
58float fbm(vec2 p) {
59 float total = 0.0;
60 float amplitude = 1.0;
61 float frequency = 1.0;
62
63 for(int i = 0; i < 5; i++) {
64 total += smoothNoise(p * frequency) * amplitude;
65 amplitude *= 0.5;
66 frequency *= 2.0;
67 }
68
69 return total;
70}
71
72/**
73 * @brief Executes the fragment shader entry point.
74 */
75void main(void) {
76 float distortionStrength = 0.02;
77 vec2 distortion = vec2(
78 fbm(tc * 10.0 + time_f) - 0.5,
79 fbm(tc * 10.0 - time_f) - 0.5
80 );
81
82 vec2 distortedTC = tc + distortion * distortionStrength;
83
84 color = texture(samp, distortedTC);
85}
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
float fbm(vec2 point)
Evaluates fbm for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
float smoothNoise(vec2 uv)
Evaluates smoothNoise for this shader effect.
#define frequency
Definition ol.frag:13