Starling-Framework icon indicating copy to clipboard operation
Starling-Framework copied to clipboard

Allow cheap ColorMatrix effects by specialized shader code

Open henke37 opened this issue 10 years ago • 11 comments

Add the option to the QuadBatch class to use a matrix to perform color matrix operations at rendering with just one additional AGAL instruction.

henke37 avatar May 25 '14 18:05 henke37

You mean similar to the "ColorTransform" option in classic Flash, right? Thanks for the suggestion — I'll think about it! Would definitely be useful.

PrimaryFeather avatar May 26 '14 06:05 PrimaryFeather

This feature would save a lot of texture memory on mobile device for a lot of effects (lighten, darken, posterise, b&w..).

Fraggle avatar May 26 '14 07:05 Fraggle

Not ColorTransform, that is just linear equations that operate on each channel individually. I mean a full matrix where every channel can affect every other channel. Look at flash.filters.ColorMatrixFilter to see what I mean.

And while the example is a "filter", I am asking for this not as a heavy starling.filters.ColorMatrixFilter, but as a simple property on the DisplayObject class. Using a filter is overkill for something that can be done in the normal shader that draws real textures directly to the back buffer, no need for intermediary render textures here.

henke37 avatar May 26 '14 09:05 henke37

Yeah, I understand — that's what I meant, having something directly on display objects, just as the color transform class (but more versatile).

PrimaryFeather avatar May 28 '14 12:05 PrimaryFeather

The key point here is to avoid the extra costs involved with the filter. No additional draw pass, no RenderTextures, just a shader variant that does the job.

henke37 avatar Jul 18 '14 13:07 henke37

Yes, I totally understand what you mean. I'm currently considering a more flexible rendering system, and this would most probably become possible then, too.

PrimaryFeather avatar Jul 21 '14 13:07 PrimaryFeather

I'm sorry to ask but do you have any timeframe on that specific feature? I could try to do it myself but I'm really not good at agal stuff.

Fraggle avatar Sep 01 '14 14:09 Fraggle

That's hard to say, but it will probably not be very soon. My plan is to finish the Sprite3D feature, then probably implement Stencil Masks, and after that the rendering system overhaul could start, which would make this possible.

[Sorry for the late reply, I was on a vacation!]

PrimaryFeather avatar Sep 13 '14 08:09 PrimaryFeather

My description from the previous post turned out to be rather accurate, actually! 1.5 years later, you can now finally achieve that with the help of Starling's new "MeshStyles". Here's an implementation that shows you how to create such a style: ColorOffsetStyle

PrimaryFeather avatar Apr 14 '16 14:04 PrimaryFeather

  1. It's not default. Code that you need to dig out from online examples is not good enough, it needs to come with the library itself.
  2. It's not the full matrix. It is only a linear transform on each of the channels. This was for a full matrix multiplication so that you get things like hue shifting.

henke37 avatar Apr 14 '16 15:04 henke37

Okay, fair enough! It's planned to add such a class to future releases.

PrimaryFeather avatar Apr 14 '16 15:04 PrimaryFeather