YOUR ACCOUNT

Login or Register to post new topics or replies
rgoer
Posts: 46
I use filterforge for creation of fx textures for game development. A lot of the time, I will "pack" multiple single-channel data textures into a single output texture. I often have multiple noises which are used by a single pixel shader going into the R, G, B, and A channels of a single texture, for example.

If I try and set up my FF filters such that I can export my textures "straight from filterforge", I get bad alpha premultiplication problems.

Two scenarios:

1. A filter has three different greyscale perlin noise nodes being fed into the respective red, green, and blue channel inputs of an "assemble rgb" node. The output of "assemble rgb" is going straight into the final result. I create a new image in FF, and fill it with rgba 0,0,0,0 (completely transparent). A FF tga export (24-bit) of this filter on my transparent image gives me an rgb tga with my red, green, and blue channels exactly as I expect them.

2. A similar filter has a fourth perlin noise being fed into the "new alpha" input of a "set alpha" node (the source of this "set alpha" is the "assemble rgb" from the previous example). The output of this "set alpha" is going straight into the final result. I create a new image in FF, and fill it with rgba 0,0,0,0 (completely transparent). A FF tga export (32-bit with alpha) of this filter on my transparent image gives me an rgba tga with my red, green, and blue channels premultiplied by my alpha! WTF!?

Of course I can work around this issue by just doing the image packing "by hand" in photoshop, but it would be swell if the FF export was the last thing I had to do before dds conversion smile;)
  Details E-Mail
KGtheway2B
KGtheway2B

Posts: 660
Filters: 34
Wow, I'm surprised I never noticed this. It does something similar with PNG's which is what I typically export.

Attached an example for kicks and giggles. Selector bar: RGBA, R, G, B, A

Trying it out.ffxml
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Just tried it -- TGA export doesn't premultiply Alpha. Here's the filter I'm using:

Alpha Premultiplication.ffxml
  Details E-Mail
rgoer
Posts: 46
In your filter, premultiplication is avoided, that is a relief. However, I am still seeing premultiplication in my filter. I attached a simple case which demonstrates the problem.

premult.ffxml
  Details E-Mail
rgoer
Posts: 46
When I try KGtheway2B's filter, I also see premultiplication.

Is there something wrong with the setup used in "Trying it out.ffxml" and "premult.ffxml" that causes us to have this issue? What exactly is "Alpha Premultiplication.ffxml" doing differently that allows it to avoid this?

Edit: for the sake of completeness, my export process is

1. File -> New Image...
2. Width and Height set
3. Fill color set to r=0, g=0, b=0, alpha=0
4. "Save Image As..."
5. File name set
6. Save as type: TGA
7. TGA Options "Depth" set to "32 bit with alpha channel"
8. TGA Options "Flip Row Order" unchecked
9. I now have a TGA with premultiplied alpha when using my own filters or KGtheway2B's filter, but not Vladimir's filter
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Rgoer -- I investigated things a bit further. What you found is most likely a bug, and a very interesting one.

The TGA export does not perform premultiplication. However, if your Alpha channel has regions with the brightness of exactly zero, the RGB for these areas are exported as a flat color. My first test filter I posted above didn't catch it because it used a gradient with no zero-alpha areas.

Most likely this is a bug and we'll look into it.

Meanwhile, there is a workaround for this. You can avoid the replacement of zero-alpha areas with flat color by setting the alpha of these areas to something like 0.01 (you can try even smaller values -- our colors are floating-point). This prevents the RGB replacement, and the alpha is still exported into an integer-color pixel format correctly, as 0.

Hope this helps a bit.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Here's a simpler workaround -- just add an External > Image component to the filter in such a way that it doesn't contribute to the final result. See the attached filter.

The workaround works because when there's an Image component in the filter tree, FF uses a different method of blending the rendered image with the original one, and this method doesn't affect the RGB values for zero-alpha areas. Here's a help article on this:
http://www.filterforge.com/more/help/...utput.html

Premult Workaround.ffxml
  Details E-Mail
rgoer
Posts: 46
Ah, I am glad to see I'm not crazy smile:)

Thank you for the workaround!
  Details E-Mail
Samantha Fuller
Posts: 8
I'm not sure if it is the same bug but i made some mods to the Bridge Support Bars filter by Darth Axel 007 and saved over a jpeg of pure Alpha i created through the FF new image menu. when i opened it in another app their were areas of bleed into the white where alpha was. I went back and did the same with the original filter and got the same bleed in . I'm new to filters, don't own Photoshop and run FF as stand alone so i don't comprend what the Premult Workaround dose or even how to use it. smile:eek:

Edited i was extremely tired to save Alpha to Jpeg smile:eek:
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,531 Posts
+36 new in 30 days!

15,347 Topics
+72 new in year!

Create an Account

Online Users Last minute:

6 unregistered users.