Question

I have been trying to get a particle rendering library to work with my shaders. It works perfect with fixed function and I know the result I am aiming for. I am just unsure how to do the final blending bit.

It packs the particle life like this into the DWORD and sets the dword as one of the vertex attributes. A quad has 4 vertices like that. 3 float pos, 3 float normal, 4 byte diffuse, 2 float uv. What should I do with the 4byte attribute, do I use it as a vec4 or float attribute in my glsl shader? Also since this library uses premultiplied alpha, what kind of blending equation should I use? The library is pyro particle library.

int ir = (int) (r * 255.0f + 0.5f);
int ig = (int) (g * 255.0f + 0.5f);
int ib = (int) (b * 255.0f + 0.5f);
int ia = (int) (a * Particle.Visibility * 255.0f + 0.5f);
DWORD diffuse;

#ifdef __BIG_ENDIAN__
if (GetLibrary()->GetGraphicsDevice()->IsRGBA())
diffuse = (ir << 24) | (ig << 16) | (ib << 8) | ia;
else diffuse = (ib << 24) | (ig << 16) | (ir << 8) | ia;
#else
if (GetLibrary()->GetGraphicsDevice()->IsRGBA())
diffuse = ir | (ig << 8) | (ib << 16) | (ia << 24);
else diffuse = ib | (ig << 8) | (ir << 16) | (ia << 24);
#endif /* __BIG_ENDIAN__ */
Was it helpful?

Solution

Your 4x unsigned bytes will be converted to vec4 (floating point type). glVertexAttribPointer always converts any input type to float in the shader.

Their value will range from 0-255 if you select normalize == GL_FALSE, otherwise they will range from 0-1 (byte/255.f) if you select normalize == GL_TRUE .

As to your question about premultiplied alpha, if you don't want to multiply the source data by alpha in the blending operation, then just use:

glBlendFunc(GL_ONE,                 //multiply source value by 1
            GL_ONE_MINUS_SRC_ALPHA  //multiply destination value by (1-src_alpha)
            )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top