ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
bend2mouse.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file bend2mouse.frag
5 * @brief Vulkan fragment shader: bend2mouse.
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 iMouse ext.mouse
18#define iResolution ext.u0.zw
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 Executes the fragment shader entry point.
28 */
29void main(void) {
30 vec2 uv = tc;
31 vec2 center = vec2(0.5);
32 vec2 dragEffect = vec2(0.0);
33
34 if (iMouse.z > 0.0) { // Only when mouse is dragged
35 // Convert mouse coordinates to UV space
36 vec2 clickPos = iMouse.zw / iResolution.xy;
37 vec2 currentPos = iMouse.xy / iResolution.xy;
38
39 // Calculate drag vector components
40 vec2 dragVec = currentPos - clickPos;
41 float dragStrength = length(dragVec) * 2.0;
42 vec2 dragDir = normalize(dragVec + vec2(0.0001));
43
44 // Calculate position relative to click
45 vec2 uvOffset = uv - clickPos;
46 float distFromClick = length(uvOffset);
47
48 // Create directional distortion components
49 float parallel = dot(uvOffset, dragDir);
50 float perp = dot(uvOffset, vec2(-dragDir.y, dragDir.x));
51
52 // Apply stretching in drag direction
53 parallel *= 1.0 + dragStrength;
54
55 // Add wave effects based on drag direction
56 float wave = sin(parallel * 20.0 - dragStrength * 10.0) * 0.02;
57 float vortex = tan(perp * 15.0 + dragStrength * 5.0) * 0.01;
58
59 // Combine distortion effects
60 dragEffect = vec2(
61 parallel * dragDir.x - perp * dragDir.y,
62 parallel * dragDir.y + perp * dragDir.x
63 ) * (1.0 + wave + vortex);
64
65 // Add click-centered bubble effect
66 float bubble = smoothstep(0.2, 0.1, distFromClick);
67 dragEffect += bubble * dragVec * 0.5;
68 }
69
70 // Apply final texture sampling with distortion
71 color = texture(samp, uv + dragEffect);
72}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
#define iMouse
Definition 3high.frag:17
ext
Definition 3high.frag:16
void main(void)
Executes the fragment shader entry point.
Definition 3high.frag:47
#define iResolution
Definition 3high.frag:18
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
float bubble(vec2 p, vec2 c, float r)
Evaluates bubble for this shader effect.
vec2 vortex(vec2 uv, vec2 c, float t)
Evaluates vortex for this shader effect.
Definition huei_af2.frag:80