flat assembler
Message board for the users of flat assembler.
Index
> Windows > per pixel alpha blending 2 images artifact problem |
Author |
|
dev_89 02 May 2013, 12:23
i made a template using dib sections and made some simple animations.
i used the following formula to calculate each pixel by alpha value: dest = alpha * (source - dest) / 255 + dest and it works fine except when i alpha is below 100 or lower at some positions black artifacts appears specially when alpha is nearby zero. here is my code:(i know it looks like crap and i can optimize it but that's not what matters now) Code: movzx eax,byte [Color];this is the new pixel movzx ebx,byte [esi];current pixel(red) sub eax,ebx imul eax,[Alpha] shr eax,8;since divide by 255 requires div instruction and it's slow and 256 ;is nearby 255 so i sacrificed 1 and used shr instruction to speed up the ;calculation add eax,ebx mov byte [Color],al movzx eax,byte [Color+1] movzx ebx,byte [esi+1];current pixel(green) sub eax,ebx imul eax,[Alpha] shr eax,8 add eax,ebx mov byte [Color+1],al movzx eax,byte [Color+2] movzx ebx,byte [esi+2];current pixel(blue) sub eax,ebx imul eax,[Alpha] shr eax,8 add eax,ebx mov byte [Color+2],al mov eax,[Color] any ideas what causes the black artifact on lower alpha value? i know the there's something wrong with the calculation but dunno what is it. btw,here is the compiled template.just look at the blood drops when they slowly disappears and you'll notice the black artifacts on some positions which completely destroys the back image and turns it to black. edit:btw,the blood drop is 24 bit bitmap and fire is 32 bit bitmap.
|
|||||||||||
02 May 2013, 12:23 |
|
baldr 02 May 2013, 13:14
dev_89,
Artifacts appear in overlapping regions. Probably not only blending involved. |
|||
02 May 2013, 13:14 |
|
dev_89 02 May 2013, 14:37
@edfed:
i know that i'm doing the calculation wrong and i tried what you mentioned but more artifacts appeared. could it be that 1 which got sacrificed causing this?maybe i should use div instruction to get the exact results?damn i'm confused! |
|||
02 May 2013, 14:37 |
|
cod3b453 04 May 2013, 11:42
I haven't tried your code but you will end up with a skew towards zero unless you correct the alpha value for the shr 8 optimisation:
Code: mov ecx,dword [alpha] ; alpha : [0,255] inc ecx ; 1+alpha : [1,256] movzx eax,byte [Color] ; S : [0,255] movzx ebx,byte [esi] ; D : [0,255] sub eax,ebx ; S - D : [-255,255] mul eax,ecx ; (S - D) * (1 + alpha) : [-255 shl 8,255 shl 8] add ah,bl ;((S - D) * (1 + alpha)) + (256 * D) : [0 shl 8,255 shl 8] mov byte [Color],ah ; |
|||
04 May 2013, 11:42 |
|
revolution 04 May 2013, 17:43
Perhaps you could keep the two source bitmaps intact and render on demand to the screen buffer:
Code: movzx eax,byte [Source1];from source1 movzx ebx,byte [Source2];from source2 ;... mixing function here mov byte [ScreenBuffer],al Plus this has the advantage of not needing to read the screen buffer directly (you only write to the screen), so this might be a consideration if you need to improve rendering speed. |
|||
04 May 2013, 17:43 |
|
dev_89 08 May 2013, 08:04
@revolution:thanks for the tip.
@cod3b453:thanks for the help but still the artifacts appears. |
|||
08 May 2013, 08:04 |
|
asmdev 13 May 2013, 10:23
perfectly fine working alpha blending: http://www.masmforum.com/board/index.php?topic=8783.0
but it will not produce either 100% solid or transparent - don't remember |
|||
13 May 2013, 10:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.