From: deathride58 Date: Sat, 23 Dec 2023 18:36:56 +0000 (-0500) Subject: Fixes GLES2 crashing when compiling the drug shader (#22899) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=9870c7f9eb23cc8559c37d8744c7b7945b32d055;p=space-station-14.git Fixes GLES2 crashing when compiling the drug shader (#22899) fixes drug shader not compiling in gles2 and also applies DRY --- diff --git a/Resources/Textures/Shaders/rainbow.swsl b/Resources/Textures/Shaders/rainbow.swsl index a96d2fdb31..7a1009eaa6 100644 --- a/Resources/Textures/Shaders/rainbow.swsl +++ b/Resources/Textures/Shaders/rainbow.swsl @@ -54,6 +54,10 @@ highp float mixNoise(highp vec2 point, highp float phase) { return mix(a,b,0.5); } +highp float genGradient(highp vec2 center, highp vec2 coord, highp float radius, highp float dist, highp float power) { + return pow(min(max((length(center - coord) / radius) - dist, 0.0), 1.0), power); +} + void fragment() { highp vec2 coord = FRAGCOORD.xy * SCREEN_PIXEL_SIZE.xy; highp vec2 aspect = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); @@ -61,13 +65,13 @@ void fragment() { // warp the screen. highp vec2 offset = vec2(mixNoise(coord, 0.), mixNoise(coord, 5.)); - highp float centergradient = pow(clamp((length(center - FRAGCOORD.xy) / CenterRadius) - CenterMinDist, 0.0, 1.0), CenterPow); + highp float centergradient = genGradient(center, FRAGCOORD.xy, CenterRadius, CenterMinDist, CenterPow); COLOR = zTextureSpec(SCREEN_TEXTURE, coord + effectScale * (DistortionScale * centergradient) * offset); // apply rainbow effect. highp float hue = 1. + mixNoise(coord, 10.); highp vec3 color = hsv2rgb_smooth(vec3(hue,1.0,1.0)); - highp float centercolor = pow(clamp((length(center - FRAGCOORD.xy) / CenterColorRadius) - CenterColorMinDist, 0.0, 1.0), CenterColorPow); + highp float centercolor = genGradient(center, FRAGCOORD.xy, CenterColorRadius, CenterColorMinDist, CenterColorPow); highp float coloration = pow((COLOR.x + COLOR.y + COLOR.z) * BaseColorMult, BaseColorPow) * centercolor; COLOR.xyz = mix(COLOR.xyz, color, MaxColorMix * effectScale * effectScale * coloration); }