Pipet and Alpha

Hi there,

I found a strange behaviour on Pipet if you use Alpha.
If Alpha is off (1.0f) than everything (RGB) is fine, but as soon as you use Alpha below 1.0, than output for Alpha is showing some strange values.
I mangaged to get right ones and it occurs to me that there is missing a root somewhere internally as it works proper with root.
Actually, its working then, but not with Alpha below 0.11. I guess its because of rounding issues.

Edit: 4V version 14

pipet_alpha.v4p (16.9 kB)

works a bit better when you set dx9texure format to a8r8g8b8
works much better with filetexture, dynamictexture but still not giving back the exact values

Thanks Victor, I tried your suggestion. Its a little better now.

But I found some other strange behaviour, which probably is well known for 4V-gurus.
I have seen that if you are working with alpha channel, it changes colour values as well if you re-use this image as a texture again. That is weird, because I always thought that alpha is a seperate channel and not intertweened with RGB. Apparently it does.

pipet_alpha-3.v4p (34.6 kB)

huh, seems not to be a problem of pipet (since it works with dynamic texture), but rather of dx9texture which somehow premultiplies alpha?!

ai frank,

we’ve been tinkering about this for quite a while now and have come to the conclusion, this is a really tricky situation.

on the way we discovered a little bug, that, now fixed, changes the results, but doesn’t make them more understandable: the renderers background-color-alpha is now also applied to the dx9textures background.

still, with all default settings pipet will report rgb-values as you see them on screen. premultiplied, with their alpha.

maybe you could elaborate on what you actually are trying to do, so we can find a solution. everything should be possible. there only doesn’t seem to be a general solution.

what we see is definitely not what you get here, as long as our eyes can’t see alpha.

another try to get the head around it:

in default blend mode particle colors and background colors (what already is in the renderer) are blended according to the alpha value of the particle.

C = Cparticle * Aparticle + Cbackground * (1-Aparticle)

so if alpha of the particle in that point is 70% = 0.7 then the color output is determined by 70% of the particle color and by 30% by the backgroundcolor.
that’s independent of the alpha stored in the background.

however i would say that’s what you want in most cases.

if you now want to have a transparent texture is more difficult.
do you want to have the alpha multiplied into the color like above? then all the colors are already mixed in the way you want. what exactly should happen with the alpha channel? should t be 1 for all parts where drawing has occurred and 0 for the holes in between the particles?

if you say “no, it should be more clever”!
then maybe you don’t want to mix/composite/blend the colors when drawing into the texture, but later when using the texture?

  • so when filling the texture just overdraw always and therefore write new colors and alpha values into the texture at the overdrawn areas. use a blend (advanced) with alpha blending = 0 for drawing the particle into the texture.
  • sampling the texture should now give you only the colors and alpha values you wrote into.

have a look at the at the patch here (disable alpha iobox) and at the page under default blend mode…
Transparency

Blend (EX9.RenderState Advanced) help.v4p (18.7 kB)

for german readers:
http://keepcoding.ke.funpic.de/tutorials/DXTutAlphaBlending.pdf

the general equation for drawing pixels is fixed.

for colors:
C = Cparticle * SrcBlendMode + Cbackground * DestBlendMode

but also for alpha:
A = Apartice * SrcBlendMode + Abackground * DestBlendMode

for default blend mode:
SrcBlendMode = Aparticle
DestBlendMode = (1-Aparticle)

so we have:

C = Cparticle * Aparticle + Cbackground * (1-Aparticle)

A = Apartice * Aparticle + Abackground * (1-Aparticle)

for Abackground = 0 this simplifies to
A = Apartice * Aparticle

(…)

i’ll digg into this further after node08.

pipet_alpha-4.v4p (44.3 kB)

Oh thanks gregsn for this broad and deep answer. I have to read and think over it now. Looks like not to swallow too easily.