|
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 Thoughts appreciated. here is script:
(comments are locked)
|
|
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 :) Thanks taoa, i did what you mentioned, and also included the webplayer test. still having issues... In the "CreateStencil" function inside the loops there is a Color array called "stencilUV" where i implemented what you commented. is this what you meant?
Mar 02 '11 at 01:04 AM
Kourosh
Holy crap. Javasript. Ouch. Give me some time then :) BTW: instead of performing a raycast every frame and only using it if you click the mouse, do the other way around, only do your raycast if the mouse is clicked. A mouse click test is about thirty seven billions times quicker than a ray cast test. Roughly.
Mar 02 '11 at 10:52 AM
taoa
OK, I believe your code is generally correct, but your main issue here is that you use the alpha value of your source image (the one you apply) to multiply in both your source texture and your destination texture all colours components... including the alpha values! You should only multiply the rgb components, and for the alpha component of the final colour, choose the highest value between the source and the destination. Also, you're calling three (3! yes, 3!) times the function texture.GetPixel (xPix,yPix). Please, Call it once (1) and store it into a Color variable :p
Mar 02 '11 at 11:26 AM
taoa
HoOoray!! Success!! thanks taoa! you rock :)
Mar 02 '11 at 04:17 PM
Kourosh
Glad I helped! ^_^
Mar 02 '11 at 06:25 PM
taoa
(comments are locked)
|
|
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.
(comments are locked)
|
|
I'm trying to implement this scrip, but with no luck so far... Could you post the correct script? It would be an awesome help. Thanks in advance
(comments are locked)
|
|
Hi Kourosh, would you be so kind to share your corrected script, i'm having a hard time multiplying my rgb components with the alpha channels.. Thx!
(comments are locked)
|
|
Hi, did anyone manage to run this code on iPhone? I need exactly this but it is running too slow.. is there another workaround?
(comments are locked)
|
1 2 next page »
