Shader event being laggy #444
-
| I get a like a 4~5 second freeze whenever this event gets triggered, causing massive rate dip. HScript: //
import funkin.backend.shaders.CustomShader;
public var badAppleBG:FlxSprite;
public var bfshader:CustomShader;
public var gfshader:CustomShader;
public var dadshader:CustomShader;
public var isEnabled;
public var fadeTime;
public var backgroundColor;
public var dadColor;
public var dchealth;
public var bfColor;
public var bfchealth;
public var gfColor;
public var gfchealth;
function postCreate()
{
	bfshader = new CustomShader('badapplecharactershader');
	gfshader = new CustomShader('badapplecharactershader');
	dadshader = new CustomShader('badapplecharactershader');
	boyfriend.shader = bfshader;
	gf.shader = gfshader;
	dad.shader = dadshader;
	bfshader.intensity = 0;
	gfshader.intensity = 0;
	dadshader.intensity = 0;
	insert(3, boyfriend);
	insert(3, gf);
	insert(3, dad);
	badAppleBG = new FlxSprite(0, 0).makeGraphic(FlxG.width * 10, FlxG.height * 10, FlxColor.WHITE);
	badAppleBG.alpha = 0;
	badAppleBG.screenCenter();
	badAppleBG.blend = 3;
	badAppleBG.cameras = [camGame];
	insert(2, badAppleBG);
}
public function hexToVec4(hex:Int):Array<Float>
{
	var r = ((hex >> 16) & 0xFF) / 255.0;
	var g = ((hex >> 8) & 0xFF) / 255.0;
	var b = (hex & 0xFF) / 255.0;
	return [r, g, b, 1.0];
}
function onEvent(e)
{
	if (e.event.name == "Bad Apple")
	{
		var params = e.event.params;
		isEnabled = params[0];
		fadeTime = params[1];
		backgroundColor = params[2];
		dadColor = params[3];
		dchealth = params[4];
		bfColor = params[5];
		bfchealth = params[6];
		gfColor = params[7];
		gfchealth = params[8];
		switch (isEnabled)
		{
			case true:
				badAppleBG.color = backgroundColor;
				bfshader.targetColor = hexToVec4((bfchealth != true) ? bfColor : boyfriend.iconColor);
				gfshader.targetColor = hexToVec4((gfchealth != true) ? gfColor : gf.iconColor);
				dadshader.targetColor = hexToVec4((dchealth != true) ? dadColor : dad.iconColor);
				if (fadeTime > 0)
				{
					FlxTween.tween(badAppleBG, {alpha: 1}, fadeTime);
					for (ihatecoding in [bfshader, gfshader, dadshader])
					{
						FlxTween.tween(ihatecoding, {"intensity": 1.0}, fadeTime);
					}
				}
				else
				{
					badAppleBG.alpha = 1;
					for (shittybastard in [bfshader, gfshader, dadshader])
					{
						shittybastard.intensity = 1.0;
					}
				}
			case false:
				if (fadeTime > 0)
				{
					FlxTween.tween(badAppleBG, {alpha: 0}, fadeTime);
					for (ballsack in [bfshader, gfshader, dadshader])
					{
						FlxTween.tween(ballsack, {"intensity": 0.0}, fadeTime);
					}
				}
				else
				{
					badAppleBG.alpha = 0;
					for (pleasedontcrash in [bfshader, gfshader, dadshader])
					{
						pleasedontcrash.intensity = 0.0;
					}
				}
		}
	}
}JSon: {
	"params": [
		{
			"name": "Enabled",
			"type": "Bool",
			"defaultValue": true
		},
		{
			"name": "Fade Duration",
			"type": "Float(0.00, 60, 0.01, 2)",
			"defaultValue": 1.0
		},
		{
			"name": "Background Color",
			"type": "ColorWheel",
			"defaultValue": "#FFFFFF"
		},
		{
			"name": "Dad Color",
			"type": "ColorWheel",
			"defaultValue": "#000000"
		},
		{
			"name": "Dad Healthicon Color?",
			"type": "Bool",
			"defaultValue": false
		},
		{
			"name": "BF Color",
			"type": "ColorWheel",
			"defaultValue": "#000000"
		},
		{
			"name": "BF Healthicon Color?",
			"type": "Bool",
			"defaultValue": false
		},
		{
			"name": "GF Color",
			"type": "ColorWheel",
			"defaultValue": "#000000"
		},
		{
			"name": "GF Healthicon Color?",
			"type": "Bool",
			"defaultValue": false
		}
	]
}Shader: #pragma header
uniform vec3 targetColor;
uniform float intensity;
void main()
{
    vec4 originalColor = texture2D(bitmap, openfl_TextureCoordv);
    vec3 blendedColor = mix(originalColor.rgb, targetColor.rgb, originalColor.a * intensity);
    vec4 newColor = vec4(blendedColor, originalColor.a);
    gl_FragColor = newColor;
} | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            NeeEoo
          
      
      
        Nov 15, 2024 
      
    
    Replies: 1 comment 1 reply
-
| badAppleBG = new FlxSprite(0, 0).makeGraphic(FlxG.width * 10, FlxG.height * 10, FlxColor.WHITE); badAppleBG = new FlxSprite(0, 0).makeSolid(FlxG.width * 10, FlxG.height * 10, FlxColor.WHITE); | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        THEkatinamicrowave
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
badAppleBG = new FlxSprite(0, 0).makeGraphic(FlxG.width * 10, FlxG.height * 10, FlxColor.WHITE);
badAppleBG = new FlxSprite(0, 0).makeSolid(FlxG.width * 10, FlxG.height * 10, FlxColor.WHITE);