Update C++ opengl underlay example (#9351)

Port changes from #9341 to C++

Fixes #9348
This commit is contained in:
Simon Hausmann 2025-09-07 09:56:59 +02:00 committed by GitHub
parent 37964e0aad
commit 568d90d9ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,29 +71,54 @@ private:
const GLchar *const fragment_shader =
"#version 100\n"
"precision mediump float;\n"
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
" precision highp float;\n"
"#else\n"
" precision mediump float;\n"
"#endif\n"
"varying vec2 frag_position;\n"
"uniform float effect_time;\n"
"uniform float rotation_time;\n"
"float roundRectDistance(vec2 pos, vec2 rect_size, float radius)\n"
"{\n"
" vec2 q = abs(pos) - rect_size + radius;\n"
" return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;\n"
"const vec3 COLOR_BG_DARK = vec3(0.106, 0.106, 0.118);\n"
"const vec3 COLOR_DIAMOND = vec3(0.137, 0.149, 0.184);\n"
"const vec3 COLOR_ACCENT = vec3(0.12, 0.35, 0.75);\n"
"mat2 rotate(float angle) {\n"
" float s = sin(angle);\n"
" float c = cos(angle);\n"
" return mat2(c, -s, s, c);\n"
"}\n"
"void main() {\n"
" vec2 size = vec2(0.4, 0.5) + 0.2 * cos(effect_time / 500. + vec2(0.3, 0.2));\n"
" float radius = 0.5 * sin(effect_time / 300.);\n"
" float a = rotation_time / 800.0;\n"
" float d = roundRectDistance(mat2(cos(a), -sin(a), sin(a), cos(a)) * "
"frag_position, size, radius);\n"
" vec3 col = (d > 0.0) ? vec3(sin(d * 0.2), 0.4 * cos(effect_time / 1000.0 + d "
"* 0.8), "
"sin(d * 1.2)) : vec3(0.2 * cos(d * 0.1), 0.17 * sin(d * 0.4), 0.96 * "
"abs(sin(effect_time "
"/ 500. - d * 0.9)));\n"
" col *= 0.8 + 0.5 * sin(50.0 * d);\n"
" col = mix(col, vec3(0.9), 1.0 - smoothstep(0.0, 0.03, abs(d) ));\n"
" gl_FragColor = vec4(col, 1.0);\n"
" vec2 p_coords = frag_position;\n"
" float perspective_strength = 0.09;\n"
" float divisor = 1.0 + (-p_coords.y + 1.0) * perspective_strength;\n"
" p_coords /= divisor;\n"
" p_coords.y *= (1.0 + perspective_strength * 1.5);\n"
" const float MAX_ANGLE_DEGREES = 10.0;\n"
" float max_angle_rad = radians(MAX_ANGLE_DEGREES);\n"
" float oscillating_factor = sin(rotation_time / 1700.0);\n"
" float angle = oscillating_factor * max_angle_rad;\n"
" mat2 rotation_matrix = rotate(angle);\n"
" vec2 uv = rotation_matrix * p_coords * 6.0;\n"
" vec2 grid_id = floor(uv);\n"
" vec2 grid_uv = fract(uv) - 0.5;\n"
" float manhattan_dist = abs(grid_uv.x) + abs(grid_uv.y);\n"
" float wave_time = effect_time / 300.0;\n"
" float wave_offset = grid_id.x * 0.5 + grid_id.y * 0.15;\n"
" float accent_alpha = 0.5 + 0.5 * sin(wave_time + wave_offset);\n"
" accent_alpha = pow(accent_alpha, 2.0);\n"
" float diamond_size = 0.5;\n"
" float border_thickness = 0.03;\n"
" float diamond_fill_mask = 1.0 - smoothstep(diamond_size, diamond_size, "
"manhattan_dist);\n"
" float border_glow_mask = smoothstep(diamond_size - border_thickness, "
"diamond_size, manhattan_dist) -\n"
" smoothstep(diamond_size, diamond_size + "
"border_thickness, manhattan_dist);\n"
" vec3 final_color = COLOR_BG_DARK;\n"
" final_color = mix(final_color, COLOR_DIAMOND, diamond_fill_mask);\n"
" final_color = mix(final_color, COLOR_ACCENT, border_glow_mask * "
"accent_alpha);\n"
" gl_FragColor = vec4(final_color, 1.0);\n"
"}\n";
const GLchar *const vertex_shader = "#version 100\n"