diff --git a/assets/shaders/engine/editorWaveforms.frag b/assets/shaders/engine/editorWaveforms.frag index 7a424adb..789c3c20 100644 --- a/assets/shaders/engine/editorWaveforms.frag +++ b/assets/shaders/engine/editorWaveforms.frag @@ -19,13 +19,13 @@ uniform ivec2 waveformSize; uniform bool lowDetail; float getAmplitude(vec2 pixel) { - float pixelID = floor((pixel.y+pixelOffset)/3.); + float pixelID = floor((pixel.y+pixelOffset)/3.0); // TODO: INVESTIGATE THE 1.+ AND WHY IT WORKS (SRSLY I GOT NO CLUE) -lunar - vec2 wavePixel = vec2(mod(pixelID,waveformSize.x), 1.+floor(pixelID/waveformSize.x)); + vec2 wavePixel = vec2(mod(pixelID,waveformSize.x), 1.0+floor(pixelID/waveformSize.x)); vec4 waveData = texture2D(waveformTexture, wavePixel / waveformSize); - switch (int(mod(wavePixel.x, 3.))) { + switch (int(mod(wavePixel.x, 3.0))) { case 0: return waveData.r; break; case 1: return waveData.g; break; case 2: return waveData.b; break; @@ -33,70 +33,57 @@ float getAmplitude(vec2 pixel) { return 0.; } +float getAmpWidth(float amplitude) { + return (1.0-amplitude) * textureRes.x; +} + bool inWaveForm(vec2 pixel, float width) { - float widthdiv2 = width/2.; + float widthdiv2 = width/2.0; return pixel.x > widthdiv2 && pixel.x < textureRes.x-widthdiv2; } +float getHightlight(float ampwidth) { + float remapCoord = (ampwidth/textureRes.x)/2.0; + float mappedCoord = map(openfl_TextureCoordv.x, remapCoord, 1.0-remapCoord, 0.0, 1.0); + return 1.-(abs(mappedCoord-0.5)*2.0); +} + +void outlineWaveform(vec2 pixel, vec2 offset) { + float amplitude = getAmplitude(pixel - offset); + float ampwidth = (1.-amplitude) * textureRes.x; + + if (!inWaveForm(pixel, ampwidth)) + gl_FragColor -= outlinecolor*mix(0.5, .8, amplitude); +} + void highDetailWaveform(vec2 pixel, float amplitude, float ampwidth) { - if (inWaveForm(pixel, ampwidth)) { - vec3 gradientColor = mix(gradient1, gradient2, openfl_TextureCoordv.x); - gradientColor *= pixel.y+pixelOffset>playerPosition ? .7 : 1.; + vec3 gradientColor = mix(gradient1, gradient2, openfl_TextureCoordv.x); + gradientColor *= pixel.y+pixelOffset>playerPosition ? 0.7 : 1.0; + gradientColor = mix(gradientColor, gradientColor * vec3(1.8), map(getHightlight(amplitude), 0.0, 1.0, 0.5, 1.0)); - float remapCoord = (amplitude/textureRes.x)/2.; + float ampwidthHighlight = getAmpWidth(amplitude*(1.0/3.0)); + if (inWaveForm(pixel, ampwidthHighlight)) + gradientColor = mix(gradientColor, gradientColor * vec3(1.8), map(getHightlight(ampwidthHighlight), 0.0, 1.0, 0.5, 1.0)); + + gl_FragColor = vec4(vec3(gradientColor * mix(0.5, 0.8, amplitude))*openfl_Alphav, openfl_Alphav); - float mappedCoord = map(openfl_TextureCoordv.x, remapCoord, 1.-remapCoord, 0., 1.); - float hightlightAmount = 1.-(abs(mappedCoord-0.5)*2.); - - gradientColor = mix(gradientColor, gradientColor * vec3(1.8), map(hightlightAmount, 0., 1., .5, 1.)); - - float ampwidthHighlight = (1.-(amplitude*(1./3.))) * textureRes.x; - if (inWaveForm(pixel, ampwidthHighlight)) { - float remapCoord = (ampwidthHighlight/textureRes.x)/2.; - - float mappedCoord = map(openfl_TextureCoordv.x, remapCoord, 1.-remapCoord, 0., 1.); - float hightlightAmount = 1.-(abs(mappedCoord-0.5)*2.); - - gradientColor = mix(gradientColor, gradientColor * vec3(1.8), map(hightlightAmount, 0., 1., .5, 1.)); - } - - gl_FragColor = vec4(vec3(gradientColor * mix(0.5, .8, amplitude))*openfl_Alphav, openfl_Alphav); - - float lastAmplitude = getAmplitude(pixel - vec2(0., -1.)); - float lastAmpwidth = (1.-lastAmplitude) * textureRes.x; - - if (!inWaveForm(pixel, lastAmpwidth)) - gl_FragColor -= outlinecolor*mix(0.5, .8, amplitude); - - float nextAmplitude = getAmplitude(pixel - vec2(0., 1.)); - float nextAmpwidth = (1.-nextAmplitude) * textureRes.x; - - if (!inWaveForm(pixel, nextAmpwidth)) - gl_FragColor -= outlinecolor*mix(0.5, .8, amplitude); - - if (!inWaveForm(pixel, ampwidth+2.) && amplitude > 0.) - gl_FragColor -= outlinecolor; - } + outlineWaveform(pixel, vec2(0.0, -1.0)); + outlineWaveform(pixel, vec2(0.0, 1.0)); } void lowDetailWaveform(vec2 pixel, float amplitude, float ampwidth) { - if (inWaveForm(pixel, ampwidth)) { - vec3 color = lowdetailcol; - color *= pixel.y+pixelOffset>playerPosition ? .7 : 1.; - - gl_FragColor = vec4(color, 1.); - } + gl_FragColor = vec4(lowdetailcol * (pixel.y+pixelOffset>playerPosition ? 0.7 : 1.0), 1.0); } void main() { vec2 pixel = openfl_TextureCoordv * textureRes; - float amplitude = getAmplitude(pixel); - float ampwidth = (1.-amplitude) * textureRes.x; + float ampwidth = getAmpWidth(amplitude); - if (lowDetail) - lowDetailWaveform(pixel, amplitude, ampwidth); - else - highDetailWaveform(pixel, amplitude, ampwidth); + gl_FragColor = vec4(0.0); + if (!inWaveForm(pixel, ampwidth)) return; + + if (lowDetail) lowDetailWaveform(pixel, amplitude, ampwidth); + else highDetailWaveform(pixel, amplitude, ampwidth); } \ No newline at end of file