Instantly share code, notes, and snippets.
Last active
September 24, 2021 13:39
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save cgytrus/fc9a290b8b93f01c9580c05ea4e1de67 to your computer and use it in GitHub Desktop.
ConfiG's Geometry Dash Menu Shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shader made by ConfiG (Discord: ConfiG#9039) | |
// thanks Mat for making such a cool mod | |
precision highp float; | |
uniform vec2 resolution; | |
uniform float time; | |
uniform vec2 mouse; | |
uniform float pulse1; | |
uniform float pulse3; | |
// all the const values are settings, you can change them to your liking | |
const vec2 bgSV = vec2(0.3, 0.9); // background color saturation and value, hue is generated in runtime | |
const float bgSpeed = 0.01; // the speed of the background color scroll | |
const float bgWidth = 0.1; // the width of the background | |
const float bgRotation = 15.0; // the rotation of the background (degrees) | |
const vec2 pulseFgMouseSens = vec2(0.125, 0.06125); // foreground visualizer mouse sensitivity | |
const vec2 pulseBgMouseSens = vec2(0.0625, 0.030625); // background visualizer mouse sensitivity | |
const vec3 pulseFgColor = vec3(0.05); // foreground visualizer color (RGB) | |
const vec3 pulseBgColor = vec3(-0.06, 0.06, -0.05); // background visualizer color (HSV, added to bg color) | |
const float pulseFgCenterSmooth = 1.0; // smoothstep right edge value of the foreground visualizer | |
const float pulseFgSideSmooth = 0.4; // smoothstep left edge value of the foreground visualizer | |
const float pulseBgCenterSmooth = 1.0; // smoothstep right edge value of the background visualizer | |
const float pulseBgSideSmooth = 0.2; // smoothstep left edge value of the background visualizer | |
const float pulseFgPosition = 0.1; // vertical position of the forgeround visualizer (0 = bottom, 1 = top) | |
const float pulseBgPosition = 0.1; // vertical position of the background visualizer (0 = bottom, 1 = top) | |
const vec2 pulseFgCenterMap = vec2(0.05, 0.4); // map of the pulse value to the middle of the foreground visualizer (x = min, y = max) | |
const float pulseFgCenterMix = 0.0; // mix value between the pulse values of the middle of the foreground visualizer (higher = moves slower) | |
const vec2 pulseBgCenterMap = vec2(0.08, 0.6); // map of the pulse value to the middle of the background visualizer (x = min, y = max) | |
const float pulseBgCenterMix = 0.8; // mix value between the pulse values of the middle of the background visualizer (higher = moves slower) | |
const vec2 pulseFgSideMap = vec2(0.08, 0.08); // map of the pulse value to the sides of the foreground visualizer (x = min, y = max) | |
const float pulseFgSideMix = 0.8; // mix value between the pulse values of the sides of the foreground visualizer (higher = moves slower) | |
const vec2 pulseBgSideMap = vec2(0.08, 0.16); // map of the pulse value to the sides of the background visualizer (x = min, y = max) | |
const float pulseBgSideMix = 0.85; // mix value between the pulse values of the sides of the background visualizer (higher = moves slower) | |
vec3 hsv2rgb(vec3 c) { | |
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
} | |
float map(float value, vec2 pulseMap) { | |
return max(value * (pulseMap.y + pulseMap.x), pulseMap.x) - pulseMap.x; | |
} | |
float pulse(vec2 pulseMap, float pulseMix) { | |
return map(mix(pulse1, pulse3, pulseMix), pulseMap); | |
} | |
float triangleWave(float value) { | |
return 1.0 - abs(mod(value, 2.0) - 1.0); | |
} | |
// return value: x = x pos, y = y pos, z = value (height) | |
vec3 getPulse(vec2 coord, vec2 res, vec2 mouseCentered, vec2 mouseSens, float vertPos, float centerSmooth, float sideSmooth, | |
vec2 pulseCenterMap, float pulseCenterMix, vec2 pulseSideMap, float pulseSideMix) { | |
vec2 pulseMouse = mouseCentered * mouseSens; | |
// coord.x multiplied by 2 so that we get a full triangle, and not a half of it | |
vec2 pos = vec2(floor(coord.x * 2.0 + pulseMouse.x), floor(coord.y + pulseMouse.y - vertPos)); | |
float triangle = triangleWave(pos.x / res.x); | |
float smoothStep = smoothstep(sideSmooth, centerSmooth, triangle); | |
float pulseSideValue = pulse(pulseSideMap, pulseSideMix); | |
float pulseCenterValue = max(pulse(pulseCenterMap, pulseCenterMix), pulseSideValue); | |
float value = mix(pulseSideValue, pulseCenterValue, smoothStep); | |
return vec3(pos, value * res.y); | |
} | |
void main() { | |
vec2 mouseCentered = mouse - resolution * 0.5; | |
vec2 boxCoord = gl_FragCoord.xy / resolution.x; | |
vec3 pulseFg = getPulse(gl_FragCoord.xy, resolution, mouseCentered, pulseFgMouseSens, pulseFgPosition * resolution.y, | |
pulseFgCenterSmooth, pulseFgSideSmooth, pulseFgCenterMap, pulseFgCenterMix, pulseFgSideMap, pulseFgSideMix); | |
vec3 pulseBg = getPulse(gl_FragCoord.xy, resolution, mouseCentered, pulseBgMouseSens, pulseBgPosition * resolution.y, | |
pulseBgCenterSmooth, pulseBgSideSmooth, pulseBgCenterMap, pulseBgCenterMix, pulseBgSideMap, pulseBgSideMix); | |
vec3 color = vec3(time * bgSpeed + (boxCoord.x + boxCoord.y * tan(radians(bgRotation))) * bgWidth, bgSV); | |
// pulse values: x = x pos, y = y pos, z = value (height) | |
bool isFgPulse = pulseFg.y >= 0.0 && pulseFg.y <= pulseFg.z; | |
bool isBgPulse = pulseFg.y >= 0.0 && pulseBg.y >= 0.0 && pulseBg.y <= pulseBg.z; | |
gl_FragColor = vec4(float(!isFgPulse) * hsv2rgb(color + float(isBgPulse) * pulseBgColor) + float(isFgPulse) * pulseFgColor, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment