Jump to content

  • Log In with Google      Sign In   
  • Create Account


Premultiplied alpha + packing question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 wildboar   Members   -  Reputation: 281

Like
0Likes
Like

Posted 12 August 2012 - 05:56 PM

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? I have been trying many possible ways with no correct result. The library is pyro particle library.
Can someone please help me out? this is so frustrating.


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__ */



Sponsor:

#2 Ignifex   Members   -  Reputation: 507

Like
0Likes
Like

Posted 15 August 2012 - 03:04 PM

Do you really need a separate diffuse color? Why not use a nice texture and read from it using the UV.
Otherwise, simply convert to float again before sending to the shader.

As for the pre-muliplied alpha blending question. Normal alpha blending is like this:
Srgb * Sa + Trgb * (1 - Sa), with S and T being Source (your texture) and Target (the previous color)
Pre-muliplied alpha already has computed Srgb * Sa. Then all you need is a simple
Srgb' * 1 + Trgb * (1 - Sa)
In OpenGL, this is GL_ONE / GL_ONE_MINUS_SRC_ALPHA for source / target.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS