Merge pull request #619 from FunkinCrew/freeplay-dad-smoother

freeplay bg nicer AA and proper sizing
This commit is contained in:
Cameron Taylor 2024-06-11 16:16:13 -04:00 committed by GitHub
commit 47d5c4d141
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 70 additions and 25 deletions

View file

@ -6,15 +6,28 @@ class AngleMask extends FlxShader
{
@:glFragmentSource('
#pragma header
uniform vec2 endPosition;
void main()
{
vec4 base = texture2D(bitmap, openfl_TextureCoordv);
vec2 uv = openfl_TextureCoordv.xy;
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
// ====== GAMMA CORRECTION ====== //
// Helps with color mixing -- good to have by default in almost any shader
// See https://www.shadertoy.com/view/lscSzl
vec3 gamma(in vec3 color) {
return pow(color, vec3(1.0 / 2.2));
}
vec4 mainPass(vec2 fragCoord) {
vec4 base = texture2D(bitmap, fragCoord);
vec2 uv = fragCoord.xy;
vec2 start = vec2(0.0, 0.0);
vec2 end = vec2(endPosition.x / openfl_TextureSize.x, 1.0);
@ -29,10 +42,35 @@ class AngleMask extends FlxShader
float uvA = atan(uv.y, uv.x);
if (uvA < angle)
gl_FragColor = base;
return base;
else
gl_FragColor = vec4(0.0);
return vec4(0.0);
}
vec4 antialias(vec2 fragCoord) {
const float AA_STAGES = 2.0;
const float AA_TOTAL_PASSES = AA_STAGES * AA_STAGES + 1.0;
const float AA_JITTER = 0.5;
// Run the shader multiple times with a random subpixel offset each time and average the results
vec4 color = mainPass(fragCoord);
for (float x = 0.0; x < AA_STAGES; x++)
{
for (float y = 0.0; y < AA_STAGES; y++)
{
vec2 offset = AA_JITTER * (2.0 * hash22(vec2(x, y)) - 1.0) / openfl_TextureSize.xy;
color += mainPass(fragCoord + offset);
}
}
return color / AA_TOTAL_PASSES;
}
void main() {
vec4 col = antialias(openfl_TextureCoordv);
// col.xyz = gamma(col.xyz);
gl_FragColor = col;
}')
public function new()
{

View file

@ -458,15 +458,20 @@ class FreeplayState extends MusicBeatSubState
add(dj);
bgDad = new FlxSprite(pinkBack.width * 0.75, 0).loadGraphic(Paths.image('freeplay/freeplayBGdad'));
bgDad.setGraphicSize(0, FlxG.height);
bgDad.updateHitbox();
bgDad = new FlxSprite(pinkBack.width * 0.74, 0).loadGraphic(Paths.image('freeplay/freeplayBGdad'));
bgDad.shader = new AngleMask();
bgDad.visible = false;
var blackOverlayBullshitLOLXD:FlxSprite = new FlxSprite(FlxG.width).makeGraphic(Std.int(bgDad.width), Std.int(bgDad.height), FlxColor.BLACK);
add(blackOverlayBullshitLOLXD); // used to mask the text lol!
// this makes the texture sizes consistent, for the angle shader
bgDad.setGraphicSize(0, FlxG.height);
blackOverlayBullshitLOLXD.setGraphicSize(0, FlxG.height);
bgDad.updateHitbox();
blackOverlayBullshitLOLXD.updateHitbox();
exitMovers.set([blackOverlayBullshitLOLXD, bgDad],
{
x: FlxG.width * 1.5,
@ -475,7 +480,7 @@ class FreeplayState extends MusicBeatSubState
});
add(bgDad);
FlxTween.tween(blackOverlayBullshitLOLXD, {x: pinkBack.width * 0.76}, 0.7, {ease: FlxEase.quintOut});
FlxTween.tween(blackOverlayBullshitLOLXD, {x: pinkBack.width * 0.74}, 0.7, {ease: FlxEase.quintOut});
blackOverlayBullshitLOLXD.shader = bgDad.shader;
@ -971,13 +976,15 @@ class FreeplayState extends MusicBeatSubState
grpCapsules.members[curSelected].ranking.scale.set(20, 20);
grpCapsules.members[curSelected].blurredRanking.scale.set(20, 20);
if (fromResults?.newRank != null) {
if (fromResults?.newRank != null)
{
grpCapsules.members[curSelected].ranking.animation.play(fromResults.newRank.getFreeplayRankIconAsset(), true);
}
FlxTween.tween(grpCapsules.members[curSelected].ranking, {"scale.x": 1, "scale.y": 1}, 0.1);
if (fromResults?.newRank != null) {
if (fromResults?.newRank != null)
{
grpCapsules.members[curSelected].blurredRanking.animation.play(fromResults.newRank.getFreeplayRankIconAsset(), true);
}
FlxTween.tween(grpCapsules.members[curSelected].blurredRanking, {"scale.x": 1, "scale.y": 1}, 0.1);