FosterFramework / Foster

A small C# game framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Drawing transparent textures

codecat opened this issue · comments

I seem to be unable to draw transparent textures properly. The transparency byte is 11 according to Aseprite, but it shows as almost opaque:

image

From my XNA days I remember there was some kind of "premultiplied alpha" setting that can be used for rendering to fix something similar - does Foster have anything like that that I'm missing?

Batcher uses 'premultiplied alpha' blending mode, but I'm not sure if Aseprite premultiplies images by default.

Try to premultiply images:

 Aseprite sp = new Aseprite("Content/Sprites/test.ase");
 var image = sp.RenderFrame(0);
 image.Premultiply();
 _tex = new Texture(image);

Calling Premultiply() seemed to work! I am actually just using png's though, not .ase files for rendering these.

Image = new Image(path);
Image.Premultiply();

Is that the intended workflow, to call Premultiply() if needed?

I think Foster should automatically call it, since Batcher uses premultiplied blending by default.

@NoelFB

Often the premultiply process is applied in a pre-build step to make loading at runtime faster. If images automatically performed this step on-load it would break any images that have already had this process applied (and also be much slower if you don't care about premultiplying the image).

So yes, it's currently all intentional. I'm not against making this process more clear, though, and perhaps adding more ways to simplify the process. It might also be nice to make a normal non-premultiplied blend option that can be used if you don't want to use the premultiply blending.

I see, that makes sense! Is there any information on the process of premultiplying images outside of at runtime?

Generally

Is there any information on the process of premultiplying images outside of at runtime?

Generally you can just apply the premultiply and then save it as a .png/.qoi again. Or alternatively save it in some custom format for faster loading.

With the addition of NonPremultiplied blendmode I think I'll close this but later on when there's more docs making this clearer would be good.