Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.82k stars 821 forks source link

Glow filter changes TextField font color? #983

Closed CrazyFlasher closed 6 years ago

CrazyFlasher commented 7 years ago

Hi. I need to apply red (0xFF0000) glow filter to text fields. There original color of TextFields without filter: image When I apply filter, it changes font color also. Also glow should be red instead of black:

textField.filter = new GlowFilter(0xFF0000, 40, 1, 1.0);
textField.filter.cache();

image

CrazyFlasher commented 7 years ago

When I changed context3d profile to Context3DProfile.BASELINE (previously it was Context3DProfile.BASELINE_CONSTRAINED), it became ok. image But is it the only solution? As I remember, it's better to use BASELINE_CONSTRAINED for best compatibility with older devices, or I am wrong?

jamikado commented 7 years ago

BASELINE_CONSTRAINED was really added to support older desktop graphics hardware, specifically on Windows. If you are going for mobile app release I use BASELINE at a minimum myself.

CrazyFlasher commented 7 years ago

Yes, the game is for Android and iOS especially. Thanks, Jeff!

PrimaryFeather commented 7 years ago

Yes, there is no downside in requring BASELINE on mobile — on the contrary, it will make sum things more efficient, and I have never heard of any mobile device not supporting it.

Still, it's weird that the filter doesn't work with that mode. I'll look into it!

johnridges commented 6 years ago

I would check into the use of the AGAL "seq" token in the CompositeFilter. I don't think the "seq" or "sne" tokens are supported as well as the other AGAL tokens (that's what I've heard). It would be better to use the "sge" token in this case, as it's faster in BASELINE.CONSTRAINED, better supported, and accomplishes exactly the same thing.

PrimaryFeather commented 6 years ago

It would be better to use the "sge" token in this case, as it's faster in BASELINE.CONSTRAINED, better supported, and accomplishes exactly the same thing.

Oh, I wasn't aware of this! Do you have any source for this information?

PrimaryFeather commented 6 years ago

In any case, @CrazyFlasher, could you please test if changing the line found here from

"seq ft5, v0, v0"

to

"sge ft5, v0, v0"

fixes the problem? (It's actually just a hack to produce a 1 vector in the shader without having to pass it in manually.)

BTW, I can't reproduce the problem on my system, so it's very likely that the AGAL code simply doesn't work 100% equally on your system in constrained mode.

johnridges commented 6 years ago

Here's a thread on "seq" not working on machines in software emulation:

https://stackoverflow.com/questions/41953220/agal-seq-opcode-works-on-hardware-but-doesnt-on-software-emulation-float-numb

In BASELINE.CONSTRAINED, the GPU program size is limited to 64 of what Adobe calls "ALU Instructions" (whatever those are), and I found by trial and error that most tokens (like mul or add) take 1 "ALU Instruction", but sge takes 2, and seq takes 5. Here is another (admittedly pretty old) thread on how slow the seq token is:

http://jacksondunstan.com/articles/1628

johnridges commented 6 years ago

FYI, here is a list of approximately how may "ALU instruction"s are used in each AGAL token in BASELINE_CONSTRAINED (where "C" is the number of components the instruction operates on):

abs | 1 add | 1 cos | 4+9C crs | 3 div | 1+C dp3 | 1 dp4 | 1 exp | C frc | 1 kil | 1 log | C max | 1 min | 1 mov | 1 mul | 1 m33 | 4 m34 | 4 m44 | 5 neg | 1 nrm | 7 pow | 3C rcp | C rsq | C sat | 1 seq | 5 sge | 2 sin | 4+9C slt | 2 sne | 5 sqt | 2C sub | 1

PrimaryFeather commented 6 years ago

Wow, that's super useful information! Thanks a lot for sharing!

I'll make that seqsge change right away.

johnridges commented 6 years ago

Happy to help. You might also want to change the seq token in Effect.as as well (although I suspect it's rarely executed). I think those are the only two occurrences of the seq or sne tokens in Starling.

PrimaryFeather commented 6 years ago

You're right, it's better changed there, as well. I wonder if that code has ever been executed in a real-life app, but consistency alone is worth it. :wink: