-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Matrix Math from default shader #3227
Conversation
For future PRs, please edit your settings.json's formatting to include: "indentation":{
"trailingWhitespace": true
} |
mat4 colorMultiplier = mat4(0); | ||
colorMultiplier[0][0] = openfl_ColorMultiplierv.x; | ||
colorMultiplier[1][1] = openfl_ColorMultiplierv.y; | ||
colorMultiplier[2][2] = openfl_ColorMultiplierv.z; | ||
colorMultiplier[3][3] = openfl_ColorMultiplierv.w; | ||
|
||
color = clamp(openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0); | ||
color = clamp(openfl_ColorOffsetv + (color * openfl_ColorMultiplierv), 0.0, 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is openfl_ColorMultiplierv set? I tried all the following and found no difference with the old or new code:
sprite.shader.colorMultiplier.value = [1.0, 0.0, 1.0, 1.0];
sprite.color = 0xFFff00ff;
sprite.setColorTransform(1, 0, 1, 1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its handled in openfl and drawquaditem
Its the same usage as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way I can verify that whatever purpose openfl_ColorMultiplierv served before, is still working after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the * openfl_ColorMultiplierv would just make it not react to .color
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't react to .color, now, before and after this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On flxsprite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is supposed to be a simplification of the math. To replicate the same behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way I can verify that whatever purpose openfl_ColorMultiplierv served before, is still working after this change?
matrix multiplication actually.
this originally did
r, 0, 0, 0
0, g, 0, 0
0, 0, b, 0
0, 0, 0, a
(rgba is equal to xyzw, its swizzling)
matrices multiplied with a vector behave like this.
since all of the other values are 0, it just becomes [x * m11, y * m22, z * m33, w * m44]
and m11 is r, m22 is g, m33 is b, and m44 is a, the exact same values.
the matrix is just nothing but a middleman.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't know what purpose openfl_ColorMultiplierv
has because I can't seem to write any code that effects this property. Until I understand what purpose it has I can't approve any changes to its behavior
On flxsprite?
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var hue = 0.0;
override public function update(elapsed:Float):Void
{
super.update(elapsed);
sprite.color = FlxColor.fromHSB((hue += elapsed * 180) % 360, 0.5, 1.0);
}
Before my change:
https://github.com/user-attachments/assets/1ae37d92-32e9-4fc0-a94b-0bcce7ae1905
After my change:
https://github.com/user-attachments/assets/b3bb82d7-25b3-4cbb-a5a6-95a88a5b1380
The intent is for the same behaviour but now its faster If you notice no visual change pre and post change with changing sprite.color, that means its working as intended |
I see the issue, for some reason defining the shader with a fragment sorce causes package states;
class ShaderColorTestState extends flixel.FlxState
{
override public function create()
{
super.create();
final sprite = new flixel.FlxSprite().makeGraphic(100, 100);
sprite.shader = new SimpleShader();
sprite.color = 0xFFff00ff;
add(sprite);
}
}
class SimpleShader extends flixel.system.FlxAssets.FlxShader
{
@:glFragmentSource('
#pragma header
void main()
{
gl_FragColor = texture2D(bitmap, openfl_TextureCoordv);
}
')
public function new()
{
super();
}
} the above resulted in a white square, when I was expecting a magenta square, if I comment out the Thanks! |
made a new issue of the behavior specified above: #3246 |
Since the current matrix math can be simplified to a simple multiply