Skip to main content
GameDev.net gamedev.net
🔒 Locked

Blending

Started by yurixd Oct 14, 2005 at 11:14 AM 1 replies 500+ views
Original Post
yurixd
yurixd
HI guys! I have made a program that render to the same position for diferent fragments. I will like that my render target contains at the end the addition of all the values that my program render to it! Anyone can told me how to do it ?? So, if on efragment contains position (x,y)=(0,0) and color = 0.1 and another fragment contains position (0,0) color 0.23 I will like thtat after When I read data back to the CPU from my render texture, have in position (0,0) the value 0.33! Anyone can give me a example code of how to do that ?? Many thanks!! Jesus
Muhammad Haggag
Muhammad Haggag
device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

DadleFish
DadleFish
Basically there are two ways to do that. Hard addition is done by -

Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);


which will simply add the two colors together and then clamp the result into the [0,1] values. This is not very good because your scene might get over-saturated. A better approach can be soft addition, which takes the destination as it is but adds "some" part of the source color, according to the intensity of the destination:

Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);


You can of course opt to make it the other way around - having the source taken as it is (D3DBLEND_ONE) and the destination taken in relation to the source (D3DBLEND_INVSRCCOLOR).

Try playing with it and see what you like best.
Dubito, Cogito ergo sum.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.