How do I subtract with alpha blending?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Twada
DC Developer
DC Developer
Posts: 42
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 18 times
Been thanked: 53 times

How do I subtract with alpha blending?

Post by Twada »

Hello.
I want to subtract the pixel color by a constant value.
But, PVR alpha blending only has add and multiply.
Is there subtract techniques with PVR alpha blending?

Thanks!
User avatar
Protofall
DCEmu Freak
DCEmu Freak
Posts: 78
Joined: Sun Jan 14, 2018 8:03 pm
Location: Emu land
Has thanked: 21 times
Been thanked: 18 times
Contact:

Re: How do I subtract with alpha blending?

Post by Protofall »

Twada wrote: Fri Dec 11, 2020 9:21 pm Hello.
I want to subtract the pixel color by a constant value.
But, PVR alpha blending only has add and multiply.
Is there subtract techniques with PVR alpha blending?

Thanks!
I'm a bit rusty on my computer graphics terminology so I don't really know what "subtract" pixel colour means, but this post with a demo to download might be what you're looking for or point you in the right direction https://dcemulation.org/phpBB/viewtopic ... p#p1055918
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>

Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
Twada
DC Developer
DC Developer
Posts: 42
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 18 times
Been thanked: 53 times

Re: How do I subtract with alpha blending?

Post by Twada »

This is not what I want. But very interesting.
I wanted to know how to darken the pixel color.
I need to study PVR blend mode.
Thank you for your reply!
TapamN
DC Developer
DC Developer
Posts: 104
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 88 times

Re: How do I subtract with alpha blending?

Post by TapamN »

I think the closest you can get to subtractive blending is to send the source blend func to zero and the dest blend func to 1-src. (So in OpenGL, this would be glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR))

This gives you a blend equation of Source_color * 0.0 + Dest_color * (1 - Source_color), which simplifies to Dest_color - Dest_color * Source_color.

Not exactly Dest_color - Source_color, but it causes bright colors in the source texture to darken the pixels underneath. Pure white in the texture will draw pure black, and pure black will leave the pixel unchanged, just like true subtraction would. It might look close enough.
These users thanked the author TapamN for the post:
Protofall
Twada
DC Developer
DC Developer
Posts: 42
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 18 times
Been thanked: 53 times

Re: How do I subtract with alpha blending?

Post by Twada »

I got the answer with your tips and some sleep. Thank you!

pass 1 : dst = src_color
pass 2 : dst = 1 - dst_color
pass 3 : dst = dst_color + src_color * src_alpha
pass 4 : dst = 1 - dst_color

But, It's so heavy on PVR. PVR is not good on Translucent...
These users thanked the author Twada for the post (total 2):
ProtofallIan Robinson
Olivier
DCEmu Newbie
DCEmu Newbie
Posts: 7
Joined: Thu Jul 29, 2021 8:26 am
Location: Aix-en-Provence, France
Has thanked: 4 times
Been thanked: 0

Re: How do I subtract with alpha blending?

Post by Olivier »

Edit: I need to study more
Post Reply