Gamestudio Links
Zorro Links
Newest Posts
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
folder management functions
by 7th_zorro. 04/15/24 10:10
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
SGT_FW
by Aku_Aku. 04/10/24 16:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, Quad), 373 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Subtractive blending #448336
01/30/15 03:37
01/30/15 03:37
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
I've found it very simple (with some help, I recall) to activate standard additive blending in a shader:
Code:
pass base
	{
		SrcBlend = One;
		DestBlend = One;
		BlendOp = Add;
		
		VertexShader=compile vs_1_1 mainVS();
		PixelShader=compile ps_1_1 mainPS();
	}



But is there an easy way to handle "subtractive" blending? For instance, if I have a light gray blob texture, I want it not to show up as a bright light, but as a color-saturated dark patch (which is generally how it looks when you uniformly subtract from a color).

Changing BlendOp to Subtract definitely does not do the trick, as it makes my scene resemble a disco on drugs. The closest I've found is Min, which gives the color saturation I want but seems to make anything bright look washed-out (yet also dim, as planned).

Re: Subtractive blending [Re: MatAllum] #448337
01/30/15 06:00
01/30/15 06:00
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
A - B = A + (-B) ;P


POTATO-MAN saves the day! - Random
Re: Subtractive blending [Re: Kartoffel] #448341
01/30/15 12:22
01/30/15 12:22
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Makes perfect sense. Sadly, I tried it, and negative color values seem to be clamped to 0.

There also doesn't seem to be a valid BlendFunc that returns a negative number. Maybe I'm missing something?

Re: Subtractive blending [Re: MatAllum] #448344
01/30/15 12:47
01/30/15 12:47
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Well sorry, I thought it'd work.

I'll See if I can find a solution when I'm at home.


POTATO-MAN saves the day! - Random
Re: Subtractive blending [Re: Kartoffel] #448345
01/30/15 12:51
01/30/15 12:51
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Just a though: Use floating point render targets with HDR instead of 8 bit unsigned.
I experienced that 8 bit render targets will clamp before(!) blending, float points don't clamp.

maybe this could work


Visit my site: www.masterq32.de
Re: Subtractive blending [Re: MasterQ32] #448346
01/30/15 19:29
01/30/15 19:29
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
A shader question in another game development forum seems to imply that the ReverseSubtract blendop would do the job perfectly. Unfortunately, this produces a shader compiling error saying it doesn't know what ReverseSubtract is...

Re: Subtractive blending [Re: MatAllum] #448348
01/31/15 05:11
01/31/15 05:11
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
A horrible workaround: Make sure the entity gets rendered last (I assume they get rendered in the order they were created), then grab the pixel value at that position and do the subtract math yourself.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Subtractive blending [Re: Superku] #448364
02/01/15 17:42
02/01/15 17:42
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Seems like I've seen effects like this in game engines from the early 2000s. Nevertheless, considering this is for a vignette effect, perhaps I should just learn to create postprocessing shaders.


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1