Jump to content


Photo

Inverting colours using a mask.


  • Please log in to reply
5 replies to this topic

#1 bjshnog

bjshnog

    GMC Member

  • GMC Member
  • 33 posts
  • Version:GM8

Posted 21 June 2012 - 11:55 PM

Is there a way to invert colours behind an object or a mask?
I'm working on a long-term GM project right now, and I want to add some effects, including something that can invert colours behind it.
Is there a way to manipulate the blend mode to do this?

C1 = colour of the pixel behind object (original colour)
C2 = colour of the pixel in the same position of the object
A = alpha of the pixel in the same position of the object
C = final colour of pixel in the position

I want the pixels to follow this kind of blend:
C = A*(1-C1) + (1-A)*(C2)

Edited by bjshnog, 22 June 2012 - 12:30 AM.

  • 0

#2 eyeCube

eyeCube

    GMC Member

  • GMC Member
  • 206 posts

Posted 22 June 2012 - 05:52 AM

I'm not sure, but I think you could read up about surfaces in the help file. They may be just what you're looking for.
  • 0

#3 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2041 posts
  • Version:Mac

Posted 22 June 2012 - 05:58 AM

With blend modes... no idea.
In general you'd just want to get the colour of the pixel, generate the new colour, and draw the new pixel over it... do that for every pixel in the area... and then save it as a sprite. But that's not really doable in GameMaker since the getpixel funxtions (for the screen and for surfaces) are so slow...
  • 0

#4 eyeCube

eyeCube

    GMC Member

  • GMC Member
  • 206 posts

Posted 22 June 2012 - 06:10 AM

With blend modes... no idea.
In general you'd just want to get the colour of the pixel, generate the new colour, and draw the new pixel over it... do that for every pixel in the area... and then save it as a sprite. But that's not really doable in GameMaker since the getpixel funxtions (for the screen and for surfaces) are so slow...


I think it could be done, considering bjshnog's game doesn't require too much getpixeling, and the area to be getpixel'd isn't too large.
  • 0

#5 ramses12

ramses12

    6

  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 22 June 2012 - 09:05 AM

How about a white sprite and an extended blend mode of (bm_inv_dest_color,bm_inv_src_color)
  • 0

#6 bjshnog

bjshnog

    GMC Member

  • GMC Member
  • 33 posts
  • Version:GM8

Posted 25 June 2012 - 12:04 AM

How about a white sprite and an extended blend mode of (bm_inv_dest_color,bm_inv_src_color)

Would this allow a gradient of alpha, making the appearance of the sprite fade into the inverted colour as alpha decreases?
EDIT: Yes, it would, if alpha is just amount of white, not actually alpha. I just tested it.
I think I will have it draw another sprite above the inversion sprite.

Edited by bjshnog, 25 June 2012 - 02:03 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users