ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
prisim_glass_triangle.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file prisim_glass_triangle.frag
5 * @brief Vulkan fragment shader: prisim glass triangle.
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// High-fidelity spectral helper for the rainbow
27/**
28 * @brief Evaluates spectrum for this shader effect.
29 * @param w Input value for the calculation.
30 * @return Computed vec3 value.
31 */
32vec3 spectrum(float w) {
33 vec3 c;
34 if (w < 0.2) c = mix(vec3(1.0, 0.0, 1.0), vec3(0.0, 0.0, 1.0), w * 5.0);
35 else if (w < 0.4) c = mix(vec3(0.0, 0.0, 1.0), vec3(0.0, 1.0, 0.0), (w - 0.2) * 5.0);
36 else if (w < 0.6) c = mix(vec3(0.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), (w - 0.4) * 5.0);
37 else if (w < 0.8) c = mix(vec3(1.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), (w - 0.6) * 5.0);
38 else c = vec3(1.0, 0.0, 0.0);
39 return c;
40}
41
42/**
43 * @brief Executes the fragment shader entry point.
44 */
45void main(void) {
46 vec2 uv = tc;
47
48 // --- GEOMETRY CALCULATION ---
49 // Apex is at (0.5, 1.0) -> Top Center
50 // Base spans from (0.0, 0.0) to (1.0, 0.0) -> Bottom corners
51
52 // Check if we are inside the triangle wedge:
53 // The slope of the sides is y = 1 - 2*abs(x - 0.5)
54 float wedge = 1.0 - 2.0 * abs(uv.x - 0.5);
55
56 // Define the "glass" area
57 if (uv.y < wedge && uv.y > 0.0) {
58 // --- INSIDE THE GLASS ---
59 vec3 accumulatedColor = vec3(0.0);
60 float dispersion = 0.12;
61 int samples = 24;
62
63 // Refraction vector: Light bends away from the top apex
64 vec2 refractDir = normalize(uv - vec2(0.5, 1.0));
65
66 for (int i = 0; i < samples; i++) {
67 float w = float(i) / float(samples - 1);
68 float shift = (w - 0.5) * dispersion;
69
70 // Apply refraction shift
71 vec2 sampleUV = uv + (refractDir * shift);
72
73 accumulatedColor += texture(samp, clamp(sampleUV, 0.0, 1.0)).rgb * spectrum(w);
74 }
75
76 // Brightness and subtle glass tint
77 vec3 finalRGB = accumulatedColor / (float(samples) * 0.5);
78 finalRGB *= 1.1;
79 finalRGB += vec3(0.03, 0.04, 0.05);
80
81 color = vec4(finalRGB, 1.0);
82
83 // Add a highlight along the slanted edges
84 float edge = smoothstep(0.015, 0.0, abs(uv.y - wedge));
85 color.rgb += edge * 0.4;
86
87 } else {
88 // --- OUTSIDE THE GLASS ---
89 color = texture(samp, uv);
90 }
91}
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
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.