1

I have two pixel arrays, foreground and lighting. When I draw a white radial gradient (blurry circle) onto the lighting array, I want it to make the foreground visible - much like a torch in terraria/starbound. However, I also want to be able to mix different colors of lighting, rather than be stuck with black to white.

So how do I manipulate the pixel arrays so that they 'multiply' (I believe it's called)? Or is there an easier way using RGBA which I have not been able to get to work (flickering black on white or image getting ever more posterized)?

So far most responses regarding alpha channels / opacity have been using libraries from java which for this project I want to refrain from using.

Any help much appreciated!

Jiji
  • 13
  • 4
  • It sounds a lot like basic masking. You take the "blank" or "black" image as the base and using the lighting array as a bases, you make the decision about how much of the foreground pixel should be rendered onto the "blank"... – MadProgrammer Nov 01 '13 at 22:03

1 Answers1

0

If you want to know how the blending modes (such as "multiply") work in image editing programs on the pixel-value level, read this: How does photoshop blend two images together?.

Note that if you want to make the image lighter, you need a mode like "screen", because "multiply" makes it darker.

Community
  • 1
  • 1
lbalazscs
  • 17,474
  • 7
  • 42
  • 50
  • Ok, I am using additive methods for the lightsources to blend together; however, I'm getting irregular colours (like white and blue adding to make yellow?). – Jiji Nov 02 '13 at 15:28
  • What do you mean by additive methods? The "add" blending mode? Perhaps you have an overflow with values greater than 255. Note that is is not (A + B), but min(255, (A + B)) – lbalazscs Nov 02 '13 at 18:22
  • Oh yes, add blending method. Is it possible that when 0xffffff + 0x0000ff, it loops back to 0 and starts adding on from there, so although it is less than 255, its gone through 255^3? Is there a way we can discuss this with an easier medium than the comments? Thank :) – Jiji Nov 02 '13 at 19:34
  • You cannot simply add the 32-bit integers, you need to get the RGBA components (each has 8 bit information, therefore 255 is the max value they can represent), combine them separately and independently, make sure they don't exceed 255, then pack them back to integers. See for example this: http://stackoverflow.com/questions/4801366/convert-rgb-values-into-integer-pixel – lbalazscs Nov 03 '13 at 21:50