Hi, I've been trying and experimenting on GetPixel/SetPixels to read color data of a 64 x 64 pixels psd file and paste the retrieved data into a Texture2D. The stencil (PSD file) comes with a single layer without background. The Texture2d that is created inside the code is formatted as ARGB32 and the PSD is also imported as ARGB32. In the test link you can see that each star overlaps and removes the previously painted one.
How is it possible to solve this problem so that stars overlap but don't remove eachother?
WebPlayer test: http://jovialart.com/WebPlayer/WebPlayer.html
here is script:
You should do what a graphics card does when you ask it to perform alpha blending (alpha blending is what you're trying to do here):
final rgb colour = sourceColour*sourceAlpha + destinationColour*oneMinusSourceAlpha
or in your case:
final rgb colour = (rgb colour of the texture you're applying * alpha colour of the texture you're applying) + (rgb colour of the texture into which you are rendering * (1 - alpha colour of the texture you're applying))
That way you won't just overwrite the alpha values of your 64x64, you'll blend them properly :)
answered Mar 01 '11 at 09:20 AM
There is logic mistake in the script. I spend much time before I realize that I need to swap this couple of lines in CreateStencil function:
This two lines need to swap, to get script working correct. Oterwise iterator writes into array Y-row at first. Than changes X. And again writes Y-row. This is the reason why I was getting wrong drawing result.