Shader cleanup - applies DRY to various shaders in the game (#23294)

shader cleanup - applies DRY to various shaders in the game
This commit is contained in:
deathride58
2024-01-03 03:35:25 -05:00
committed by GitHub
parent 0e18d54cf7
commit ef1cba70b3
6 changed files with 15 additions and 82 deletions

View File

@@ -14,48 +14,44 @@ const highp float CenterColorRadius = 250.0; // radius of the gradient used to t
const highp float CenterColorMinDist = 0.2; // minimum distance from the center of the screen for the color to appear at all
const highp float CenterColorPow = 1.25; // the exponent used for the color's center
// hash(), noise(), and hsv2rgb_smooth() were converted from shadertoy examples, which were released under the MIT License:
// noise() and hsv2rgb_smooth() were converted from shadertoy examples, which were released under the MIT License:
// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// https://www.youtube.com/c/InigoQuilez
// https://iquilezles.org
highp vec2 hash( highp vec2 p ) {
p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}
highp float noise( highp vec2 p ) {
const highp float K1 = 0.366025404;
const highp float K2 = 0.211324865;
highp vec2 i = floor( p + (p.x+p.y)*K1 );
highp vec2 i = floor( p + (p.x+p.y)*K1 );
highp vec2 a = p - i + (i.x+i.y)*K2;
highp float m = step(a.y,a.x);
highp vec2 o = vec2(m,1.0-m);
highp vec2 b = a - o + K2;
highp vec2 c = a - 1.0 + 2.0*K2;
highp vec2 c = a - 1.0 + 2.0*K2;
highp vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
highp vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
highp vec3 n = h*h*h*h*vec3( dot(a,zRandom(i+0.0)), dot(b,zRandom(i+o)), dot(c,zRandom(i+1.0)));
return dot( n, vec3(70.0) );
}
highp vec3 hsv2rgb_smooth( highp vec3 c ) {
highp vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}
highp float mixNoise(highp vec2 point, highp float phase) {
highp float time = TIME * TimeScale + phase;
highp float a = noise( NoiseScale * point - time);
highp float a = noise( NoiseScale * point - time);
highp float b = noise( NoiseScale * point + time );
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);
return pow(clamp((length(center - coord) / radius) - dist, 0.0, 1.0), power);
}
void fragment() {