HaxeFlixel / HaxeFlixel/flixel

Camera shaders don't update after resizing the window

Open
#3,463 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

There is an issue with cameras and filters where shader coordinates won't properly update after resizing the window. In the provided example, half of the screen is black while the other half is purple. After resizing the window a couple times, the half is no longer centered. Resizing the window vertically seems to have a more dramatic effect.

You can press the A key to run a hack that seems to resolve the issue. I'm not sure how or why it works, I found it in the #flixel channel on the Haxe discord.

Observed on hashlink (Windows).

package;

import flixel.FlxG;
import flixel.FlxState;
import flixel.graphics.tile.FlxGraphicsShader;
import openfl.filters.ShaderFilter;

class TestShader extends FlxGraphicsShader
{
	@:glFragmentSource('
	#pragma header

	void main()
	{
		vec4 b = vec4(1.0);
		if (openfl_TextureCoordv.x >= 0.5)
		{
			b = vec4(1.0, 0.0, 1.0, 1.0);
		}
		else
		{
			b = vec4(0.0, 0.0, 0.0, 1.0);
		}

		gl_FragColor = b;
	}
	')
	public function new()
	{
		super();
	}
}

class PlayState extends FlxState
{
	override public function create()
	{
		super.create();
		FlxG.camera.filters = [new ShaderFilter(new Shader())];
	}

	override public function update(elapsed:Float)
	{
		super.update(elapsed);

		if (FlxG.keys.justPressed.A)
		{
			// hack to fix this issue, shared around on discord
			@:privateAccess
			{
				FlxG.camera.flashSprite.__cacheBitmap = null;
				FlxG.camera.flashSprite.__cacheBitmapData = null;
			}
		}
	}
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided camera and ShaderFilter reproduction on HashLink/Windows, then trace how camera filters and shader coordinates are handled during window resizing. Verify the behavior by resizing repeatedly, including vertically; done means the shader halves remain correctly centered without pressing A or clearing private cache fields.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.