Tuesday, November 20, 2012

Herpin' and Derpin'

So, I am working on my Finger Fireworks revamp.  I have some textured triangles I'm rendering particles on.  It's still very early in the process, but I've already ran into an annoying issue: even though glBlendFuncSeparate() is in the GLES 2 specification, it is not actually implemented in my test device.  Holy [expletive deleted] batman that made me kind of mad.

I need to set the blend function so that the texture pixels with transparency are rendered transparent or semi-transparent, as the case requires.  I also wish to keep only the most recent alpha value for comparison, assuming (hopefully) that the blending takes place from farthest to nearest (I'm not sure this is the case actually).  But I do want to blend the actual RGB values in proportion to the source Alpha value.  This seems to be a reasonable thing, as this is exactly the kind of thing that glBlendFuncSeparate() was made for, but I guess someone didn't feel like writing that code.  I was going to use something like glBlendFuncSeparate(SRC_ALPHA,ONE_MINUS_SRC_ALPHA,ONE,ZERO).  Please excuse my not referencing the actual names of the GLES 2 constants; the meaning is there though.

I don't think I'm trying to do anything too extraordinary here, so I've been working on other ways to do it.  I've tried glBlend(SRC_ALPHA,ONE_MINUS_SRC_ALPHA), which almost does the job, but has some weird artifacts here and there; they look like the boxed outlines of the texture file which should not be present as they are entirely transparent by the time you get to the edges.  I think that somehow the order of evaluation might be the problem here.  The blend parameters I have here, if actually evaluated from back to front should only consider the source alpha each time, not carrying forward any amount of the destination alpha, as even though the pixel will be assigned a mixed alpha, the next blend execution will not actually factor it into the weighting of the RGB values.  It still bewilders me though that I am seeing areas of the textures that look like picture frames where there should be complete transparency, but only on a small number of the rendered triangles.

I will be orienting these particles to face the eye/camera tomorrow.  Hopefully these weird artifacts are a condition that does not occur under those circumstances, but we shall have to see.  There are two ways I could do it though, so I may have some options: simply no y- or x-rotation of the model coordinates or, in a more complicated way calculate the vector to the eye then make the plane of each particle perpendicular to that vector.  I have a few sources to consult on this one, so it should be good.

No comments:

Post a Comment