Request: Anti-aliased (smooth) scaled sprites with alpha channel

Started by Janik, Sat 22/10/2005 19:26:03

Previous topic - Next topic

Janik

The problem: 32-bit sprites with alpha channel don't get anti-aliased (smoothed) when they are scaled. I think that this is an old issue, but I could not find anything in the bug tracker, so perhaps it had slipped through the cracks.

I think it would be a great addition : my character sprites have an alpha channel for smoothing the edges and also for their shadow - it looks great, but when scaled down, the body of the sprite suffers a lot from the aliasing. When I make the same sprite w/o the alpha channel (24-bit color), the body looks great scaled, but the edges are not as nice and the shadow can't be done :(

If it makes it any simpler, the alpha channel itself really doesn't need to be anti-aliased - I mean that a nearest-neighbor rescaling algorithm for the alpha + bilinear blending for the color channels would give great results.

Thank you CJ!
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

Pumaman

The problem is that the anti-aliased scaling code that AGS uses destroys the alpha channel of the image, so it's not particularly easy to fix. I will look into it, however.


Janik

Thanks for considering it! I saw in one of the AGS pages that you used AASTR for anti-aliasing. I also found this, AASTR2:

http://www.allegro.cc/resource/resource-view.php?id=61&session=c62d3eca3b510ec775df9275e4319732
Direct link to the library:
http://bitblaze.com/allegro/aastr2-0.71.tar.bz2

The readme file gives a list of improvements:
QuoteAASTR2 is a modified version of AASTR that adds new features, like
dithering, alpha blending, non-integer destination rectangles,
adjustable background color, etc..

(Emphasis mine :) )

I hope this helps!
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

Pumaman


khnum

I just noticed this problem, and i relly need to anti-alias sprites with alpha channel! :'(
Can you help me? When will this problem be solved? If it'll take too much, can you at least tell me if there's a way i can solve it?


Thanks for this great program CJ!

fovmester

aaah, so that's why my sprites don't get anti aliased! Now it makes sense. Hope you can fix this, CJ! Take your time, though!  ;D

Janik

I noticed that this feature had not yet been added, so I tried to make a plugin to anti-alias alpha-channel sprites. The result, graphically, was quite good. But I ran into lots of problems:

  • I would have to redo the entire drawing of characters AND objects, to make them in order.>:(
  • I would have to trick AGS into NOT drawing the sprites on top. >:(>:(
  • And worst of all: it was super slow.  (I was doing it pixel-per-pixel) >:(>:(>:(

So I took another look at the AASTR2 library that I mentionned a few posts back. I made a few changes to the demo, compiled it, and saved the result (the image is at the bottom of this post). As you can see the stretching looks quite good, even down to 20%. I did a non-anti-aliased stretch below to show the difference. It seemed quite fast, but I did not do exhaustive tests.

The code for the antialiased stretch is like this:
Code: ags

      convert_alpha ( sprite );     
      aa_set_mode(AA_ALPHA | AA_BLEND); 
      aa_stretch_sprite(buffer, sprite, 0, 0, w, h);



Update: I did some speed tests, and for a blitting a 200x200 sprite with smoothing + antialiased edges took about 8 milliseconds (on a 3500+ AMD). That's slow :o ! With a slower computer, and maybe an extra character on screen, the framerate would be unacceptably low.

I hope I don't sound to pushy, but I'd love to see this in a future version of AGS! :)

Update: Never mind, CJ, at least until we get hardware acceleration (just kidding :) )


Here is the link to the library anyway:
http://www.allegro.cc/resource/Libraries/Graphics/AASTR2

Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

Adamski

Hi, sorry for bumping this but we've come across an asthetical problem with the current implementation of anti-aliasing (having the "smooth-scaled sprites" option checked in setup), namely that the sprites we are using which have no outline seem to develop horrible black outlines when scaled down. We're not using an alpha channel with the sprite, and I assume the black outlines appear because black is the default colour it blends to and not the background. Is there any fix that could be made here? Would updating to AASTR2 help?

I can provide a demo that shows what's going on, but I'd rather not post it in public :)

SSH

Of course, you could cache the scaled sprites in order to improve performance...
12

Shaque

I'm just a newbie with AGS, but I've been doing graphics since Jesus was a baby. I do have one suggestion though. I use antialiased sprites all the time and I import them as PNG images, originally with transparent backgrounds. Before I did this, most of the images I made with the default magenta background... only to find when they antialias, they have a pinkish line around them. I did the same using black as a background and ended up with a dark line around them. I guess when AGS antialiases the sprites, it uses the soft edge from the background of the sprites. I could be wrong, but in my opinion PNG images with transparency and pallette index 0 work best for this effect, though the game will probably bloat a little in size and performance on older machines.
Knowledge is a right, wisdom is a choice.

Janik

I hope I understand the problem you describe correctly, if by anti-aliased you mean soft edges with <100% opacity...

You have to make sure you export the image with an alpha channel, but you cannot also put a magenta background on it. So you should have a tranparent background (checker pattern in photoshop). You also have to make sure to tell AGS to use the alpha channel when importing.

Quote from: SSH on Sat 18/11/2006 12:42:26
Of course, you could cache the scaled sprites in order to improve performance...

That's a good thought for rooms that have a fixed scaling factor, but for a continous scaling walkable area you would need something like 100 cached images for each sprite. I don't think it would be much of a problem in terms of memory, but it might take a while at startup to render all those sizes...

Edited by mod: Don't double post in such a short period.
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

Larrin

Instead of creating a new thread I figured I'd bump this old one. Is there any way to do anti-aliased scaled sprites with alpha channels? Or was this added to AGS already?

GarageGothic

It now works in the new Direct3D-mode, in DirectX-mode you still have to choose between either or.

Larrin

Thanks, it is quite incredible the level of steady improvements made to the AGS engine.

Larrin

Quote from: GarageGothic on Tue 08/07/2008 17:49:28
It now works in the new Direct3D-mode, in DirectX-mode you still have to choose between either or.
By the way, where/when was this announced? I can't find it anywhere.

Gilbert

Read here. The Direct3D enabled engine was actually introduced in a beta version of V2.80 (Refer to the last post of the linked thread. Note that there isn't an officially released V2.80, as the version number was later changed to V3.0 due to the huge updates).

The Direct3D mode bit is left out from change.txt (or, i.e. the official V3.0 release thread). As V3.0 contained major updates, CJ either forgot to add this to the change log or decided to leave out some of the changes so the change list won't be bloated.

Larrin

Quote from: Gilbot V7000a on Fri 11/07/2008 09:04:52
Read here. The Direct3D enabled engine was actually introduced in a beta version of V2.80 (Refer to the last post of the linked thread. Note that there isn't an officially released V2.80, as the version number was later changed to V3.0 due to the huge updates).

The Direct3D mode bit is left out from change.txt (or, i.e. the official V3.0 release thread). As V3.0 contained major updates, CJ either forgot to add this to the change log or decided to leave out some of the changes so the change list won't be bloated.
That's interesting, I guess the addition of anti-aliased sprites with alpha channels wasn't cool enough to make the official changes list.

SMF spam blocked by CleanTalk