- Home /
Texture2D setPixels Alpha merging
Hello everyone, I am trying to programmaticaly create a hexagon texture to be later projected onto a terrain. I am running into a problem when trying to tile the individual hex images (each hexagon is a loaded texture with GetPixels, and has alpha transparency) to create the grid. See the attached image for what I am talking about.
Is there an efficient way to solve the "overlap" problem without having to use SetPixel in a loop ? I really like the SetPixels because it's fast, and don't want to abandom my project because I can't figure out the alpha-overlay problem.
I have just learned that what I need is called "alphablending" and that I am looking for something like Lerp(text1,text2,X) ... anyone has any experience with this ? I don't want to lerp individual pixels - that would be slow I assume.
You have to Lerp() individual pixels. You can be a bit more efficient by using GetPixels32() and deal with Color32 structures. There are both a Color32.Lerp() and a Color.Lerp() depending on the pixel representation you want to use. The algorithm for doing the Lerp() to a color should be pretty straight forward to figure out, but doing the code in-line vs. making the Lerp() calls probably won't buy you much. Try the Lerp() calls first.
Thanks a lot Robertbu for your ideas. I noticed there is $$anonymous$$aterial.render.Lerp function. What if I converted my Texture2D into a material, then lerp it, then convert it back to Texture ? Or .. can I somehow use Shaders to generate Texture2D ? I think shader-based Alphablends would be faster ?
Your answer
