Alpha channel issue (AGS 3.2)

Started by Dave Gilbert, Sat 21/08/2010 22:24:33

Previous topic - Next topic

Dave Gilbert

Hello!  I am having a problem importing an image with an alpha channel.  I could swear that I was able to once do this, but for some reason it's beyond me now.

Here is how the background looks in Photoshop:



The light coming from the window is on a separate layer.  I exported the light source as a PNG (which is here for reference) which I imported into AGS with an alpha channel included.  The result?



Holy blindness, Batman! The alpha channel/transparency is definitely there, as my character is able to stand behind the light.  But obviously the light itself is waaay too bright.  Is this a problem with the current version of AGS?  I used to be able to import light sources this way without any problems.  I'm a bit confuzzled!  Any tips are appreciated!

Thanks,

-Dave

Dave Gilbert

Right, duh. Nevermind.  Apparently the artist created that highlight layer as an "overlay", which wouldn't export the same the way it appears within Photoshop. So... go ahead and lock this.

subspark

Actually, before you do lock this thread, I just want to say that it would be nice if AGS could make use of blend modes like this.
It has been mentioned several times in the wish list and you've provided a good visual example of what to expect.

Cheers,
Sparky.

Calin Leafshade

providing I have the blending formula, the agsblend plugin has the framework all worked out.

If you have any specific requests, let me know.

(a link to the blending algorithm would be nice if you could find it)

subspark

#4
Sure I'll have a look Calin. Thanks.

Edit: Gotcha! http://www.nathanm.com/photoshop-blending-math/

GarageGothic

There's a good list of blend modes that I've been using myself on Wikipedia. This  other page has more algorithms, including overlay.

Edit: Sparky posted while I was looking through my bookmarks, but maybe this is still useful.

subspark

Some good examples there too, Garage. :)
Sparky.

Calin Leafshade

Quote from: subspark on Mon 23/08/2010 16:19:21
Edit: Gotcha! http://www.nathanm.com/photoshop-blending-math/

oooooOOOOoooo, I can stick those macros pretty much straight into the code as written

subspark


Dave Gilbert

That's pretty awesome, Cailin.  Can you update this thread when you update the other one?

Calin Leafshade

http://www.thethoughtradar.com/AGS/agsblend0.5.zip

Try this.

Usage:

DrawSprite(dest.Graphic, src.Graphic, x, y, mode);

the function is a little cleverer now and shouldnt crash if you pass it a sprite that is too big or your x,y coordinates dont make sense.
It will still crash or behave oddly if both sprites arent 32-bit.

It's also now independent of allegro so the allegro dll is no longer needed.

mode is an int between 0 and 23. Heres an enum to make life easier.

Code: ags

enum eBlendModes{
  eBlendNormal = 0, 
  eBlendDarken = 1,   
  eBlendLighten = 2, 
  eBlendMultiply = 3, 
  eBlendAdd = 4, 
  eBlendSubtract = 5, 
  eBlendDifference = 6, 
  eBlendNegation = 7, 
  eBlendScreen = 8, 
  eBlendExclusion = 9, 
  eBlendOverlay = 10,
  eBlendSoftlight = 11, 
  eBlendHardlight = 12, 
  eBlendColorDodge = 13, 
  eBlendColorBurn = 14, 
  eBlendLinearDodge = 15, 
  eBlendLinearBurn = 16, 
  eBlendLinearLight = 17, 
  eBlendVividLight = 18, 
  eBlendPinLight = 19, 
  eBlendHardMix = 20, 
  eBlendReflect = 21, 
  eBlendGlow = 22, 
  eBlendPhoenix = 23
};


lemme know how you get on.

Knox

A "ResizeFilter" (with bilinear) for alpha channel would be great with AGSBlend  ;D  ;D
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

Ah shit, that upload wont work, I forgot to update the header prototype.

Will fix tomorrow when i get home from work.

As for a bilinear resize, I'm not sure if the API gives you any method of resizing a sprites surface and i'm not sure how to return a new sprite from a function.

Knox

I dont know if this sounds stupid (I really dont know how it all works, really!) but is it somehow possible to "extract" the alpha channel from the png and convert it onto a dynamic sprite that is only a b/w (black+white) opaque image...apply Khris's resizeFilter to that opaque image, and  then reconvert/reapply that newly resized+ filtered b/w image to the png's alpha channel (?)

Again, I really dont know how it all works :-X

I can help test out the blendmodes + post various results if you wish
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

yea the way you describe is essentially the only way to do it. The GetAlpha() and PutAlpha() functions can do for the alpha what khris' module does for the RGB.

Wyz

Wow, photoshop blending modes would be very nifty! I was dying to use that for a game a while back, will this would definitely be a welcome addition. :D
Life is like an adventure without the pixel hunts.

Calin Leafshade

It does work, promise  ::)

I just changed the function before compile and forgot to update the prototype and now im at work so i cant fix it.. i'll fix it in the morning.

Knox

Quoteyea the way you describe is essentially the only way to do it. The GetAlpha() and PutAlpha() functions can do for the alpha what khris' module does for the RGB

holy crap so you're telling me I can use those funtions in conjunction with khris' module and it will work (well once you update it tomorrow)?

if so, ahhhhhhhhh YEAH!
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

Yea, although I looked through khris' module and I'm not 100% sure how it works... I are not as clever as Khris.

But!

As a very poor work around you could make a copy of the sprite using the GetAlpha and then run khris resize on that and then once it has been resized, plug the values back into the sprite.. so something like this.

Make a copy of your sprite at full size
iterate through each pixel of the original using GetAlpha to get its value.
Draw on the copy a grey value representing the alpha.
like:
Code: ags

alpha = GetAlpha(orig.Graphic, x, y);
ds.DrawingColor = Game.GetColorFromRGB(alpha,alpha,alpha); //this is grey
ds.DrawPixel(x,y); 


then resize both your original and copy(which contains the alphas)

then iterate through the pixels again putting the alpha back into the original in accordance with the grey values stored in the copy.

This method might not be as inefficient as it seems since I dont think you can keep the drawingsurface open whilst running GetAlpha or PutAlpha so this way you only have to get/release the drawing surfaces a handful of times.

Calin Leafshade


SMF spam blocked by CleanTalk