The state of shaders and filters?

After a major upgrade (openfl 2.x -> 4.x) I discovered that filter support seems to be kind of in limbo.

After browsing it seems like there is some loose support for it- OpenFl 4.0.0 Shader example

In particular, the ability to write:

bitmap.filters = [ new ShaderFilter (shader) ];

But I’m very bad with shaders in general, so I’m not sure where to get started on writing/finding a glow shader replacement? I use a black glow filter on a lot of the text in my game to make it pop from the background. If there are no solutions I may have to downgrade my openFL :frowning:

While I do work with shaders in my own game, I don’t use OpenFL’s Shader class, so I can’t help with that right now.

But as long as you’re copying your text to a bitmap, why not do this?

public static function createOutlinedText(source:TextField,
        destination:BitmapData, ?outlineWidth:Int = 4, ?outlineQuality:Int = 6):Void {
    var matrix:Matrix = new Matrix();
    var color:ColorTransform = new ColorTransform(0, 0, 0);
    
    for(i in 0...outlineQuality) {
        var angle:Float = i / outlineQuality * Math.PI * 2;
        matrix.identity();
        matrix.translate(outlineWidth * (1 + Math.cos(angle)),
                        outlineWidth * (1 + Math.sin(angle)));
        destination.draw(source, matrix, color);
    }
    
    matrix.identity();
    matrix.translate(outlineWidth, outlineWidth);
    destination.draw(source, matrix);
}

In other words, draw six black copies of the text, all offset slightly in a different direction. Then draw one white copy in the center.

This will take a tiny bit longer to set up, but then it will render faster because it doesn’t have to redraw the filter each time.


Alternatively, applyFilter() might support your GlowFilter.

Ah, hrm. The main issue here is that I’m working on updates for a shipped game. I never really render my text explicitly to bitmaps, but all throughout my code base I have statements like this sprinkled:

txtGold.filters = [Utilities.glowOutlineText];

I’d need a way to listen for changes to the content of the textfield and re-draw when necessary. Could get messy considering how many text fields I use this for and how they all nest differently into various displayobjectcontainers.

I’ve also noticed any attempts to set an object’s color transform no longer work:

backing.transform.colorTransform = new ColorTransform(.3, .3, 1.2, 1);

applyfilter might work in some cases but it seems that it applies it directly to the bitmapdata itself, so this wouldn’t work in a case where a bitmapdata is instanced multiple times into different bitmaps. I may be able to try the color matrix filter as suggested here: ColorTransform as a part of Transform

will have to think on this a bit tomorrow.

I’m afraid it probably isn’t going to work, in that case. Last I heard, filters only work on bitmaps.

Though before giving up, maybe ask Joshua for a status update, and maybe offer to help with the implementation.

This part is easy: text fields dispatch Event.CHANGE whenever their text changes. There’s also TextEvent.TEXT_INPUT for input fields.

Why? Do you want the outline in some cases but not others?

Sometimes I use filters to indicate special status conditions. If there are five enemy rats on the screen, and you poison one of them, using applyFilter to turn one green would turn them all green. I use glow filters for a different effect like that too.

EDIT: So it appears that I can still use a colormatrix filter on a per-object basis, so that might be a saving grace here. more testing ahead.

EDIT 2: The color matrix filter only seems to work on individual objects, not collections of objects. oof.

That makes sense.

I guess the one remaining option is to switch to Starling, which supports filters, and which uses a display list like what you’re used to.

The downside is that - as far as I know - it isn’t compatible with the SWF library. You have to use spritesheets instead. If you’re already using spritesheets, this isn’t a problem, but if you’re animating in Flash and exporting SWFs, then you’d have to rethink your export process.

I think downgrading might be my best bet for now.

I’ll ask a quick question here, if this is more of an issue I’ll try another topic (though I’m kind of spamming you guys lately)

I changed openfl, lime, and hxcpp back to their original installations. Now when I build for windows I get

Error: Could not find include file "C:/HaxeToolkit/haxe/lib/hxcpp/3,2,102/src/hx/libs/std/Build.xml"
Build halted with errors.

hxcpp 3.2.102 is indeed the version I downgraded to, and when I checked the folder I don’t even see /hx/libs, let alone /hx/libs/std/Build.xml

I am however using a newer version of haxe itself

Did something in the upgrade process change a path somewhere that I need to revert?

It would be nice if there was a stack trace or a line number or something. This error could have been thrown from one of three different functions in this file, and those three functions could have been called from a whole bunch of other places.

Two of the functions involve parsing XML, so maybe you could search for an XML file containing “<include name="${HXCPP}/src/hx/libs/std/Build.xml" />,” or “<include name="C:/HaxeToolkit/haxe/lib/hxcpp/3,2,102/src/hx/libs/std/Build.xml" />,” or maybe just “Build.xml” if you don’t want to risk missing anything. I guess you’d search for this within hxcpp, Lime, and your project’s bin or Export directory.

If it’s in your bin/Export directory, the answer is to do a clean build.

If you can’t find it, then maybe it isn’t worth going back to the old hxcpp version. Just use the latest version (which does have src/hx/libs/std/Build.xml) and it’ll probably work.

Mixing the newest hxcpp 3.3.49 with lime 2.1.0 and openfl 2.2.5 produces this on a clean windows build:

Error: While running :cl.exe -Iinclude -nologo -DHX_WINDOWS -GR -O2 -Oy- -c -EHs -GS- -arch:SSE -IC:/HaxeToolkit/haxe/lib/hxcpp/3,3,49/include -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=330 -D_CRT_SECURE_NO_DEPRECATE -D_ALLOW_MSC_VER_MISMATCH -D_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH -wd4996 -Ie:/VS8//PlatformSDK/Include -MT -Yuhxcpp.h /FpJ:/HAXE/SodaDungeon/bin/windows/cpp/obj/obj/msvc16-ncxp/__pch/haxe/hxcpp.pch ./src/openfl/geom/Matrix3D.cpp -FoJ:/HAXE/SodaDungeon/bin/windows/cpp/obj/obj/msvc16-ncxp/aa7d8192_Matrix3D.obj
Matrix3D.cpp
./src/openfl/geom/Matrix3D.cpp(695) : error C2039: 'StaticCast' : is not a member of 'Array<ELEM_>'
        with
        [
            ELEM_=Dynamic
        ]
./src/openfl/geom/Matrix3D.cpp(695) : error C2059: syntax error : ')'

Sorry, I really wish I wasn’t so helpless with these issues, it’s just that every twist and turn seems to produce something brand new that I have absolutely no knowledge of.

Huh. I’ve never had trouble with updating hxcpp, so I guess I assumed it wasn’t an issue.

I see two options here:

  1. Revert hxcpp and try to solve the “could not find include file” error.
  2. Update Lime to 2.9.1 and OpenFL to 3.6.1.

For option 1, I’d try making a sample project and seeing if you get the error there. This will tell you if the error is somehow related to your project.

I suggest option 2 because those are the latest versions that support legacy, which means filters will still work. And since they’re newer, they should work with hxcpp 3.3.49.

So far so good

hxcpp 3.3.49 + lime 2.9.1 + openfl 3.6.1 seem to all play nice together. Windows + flash export still work, filters still in-tact. Just need to confirm that my android export still works.

EDIT: Android export is still good as well. I think I’m in the clear for now, but I can’t be too sure.

At any rate, thanks for the help. Sorry that the upgrade process was a bit of a wild goose chase, but the net result was still being able to update to the newest and most stable versions that allowed me to export my old project properly.

Glad it’s working.

For the record, I’m in the same boat as you - I still rely on legacy mode and don’t really have the time to upgrade. On the other hand, I think the new version has all the features I need, since I don’t rely on filters. The problem is that a lot of my code was written to fill in the gaps in OpenFL’s old Stage3D implementation, and now that Stage3D is better supported, my code isn’t quite compatible.

Any updates on this?
I’m trying to move some of my projects from legacy mode to the latest OpenFL, and GlowFilter is one of the features I use.