Skip to main content

Posts

Showing posts from September, 2016

How to merge 2 Texture in unity

Hi guys,


Finally i got a chance to play with pixels, i was trying make an image effect. In the process i faced some challenges, so this post is about one of the challenges i faced.


I was trying to make a 'Vignettes' Image effect, to do that i needed to merge my overlay with the background image, this was little bit tricky at first. There was very less information available on the internet, though 'wikipedia' came to the rescue. I found this article which have a simple formula that merges 2 texture.


So the formula was,


Looks complex right ? lets read that formula as a sentence,
outputRed = (foregroundRed * foregroundAlpha) + (backgroundRed * (1.0 - foregroundAlpha));

Now it makes more sense, so basically you need to use that formula to get red, green and blue values of each pixel and create a new texture with that.

foreground is the overlay i created, which is a transparent texture, and my background is opaque.


background


foreground (overlay image for Vignettes effect)



I m…