Multiplicative blend mode?

Started by
1 comment, last by luser 20 years, 7 months ago
Is there any way to have a bland mode where the resultant colour is the dst colour * source? I''m trying to make a lighting engine in a 2d game where instead of drawing shadows the textures start out dark and are brightened by light sources. The way I want it to work is to have the clear colour be the ambient light colour, then the lights are drawn with additive blending before anything is actually drawn. (so that if theres a red light and a green light it will turn yellow etc.) The game geometry should then be drawn on top of the lighting using a multiplicative blend so that the lights affect the colour and the brightness of stuff drawn on top of them.
Advertisement
The blend equation is C = Cs*Fs + Cd*Fd, where C is color, F is factor, subscript s is source and subscript d is destination. Colors are taken from the incomming fragment or from the frame buffer, and factors are what you pass to glBlendFunc.

So you want to multiply the source and destination color, meaning you can set Fs to be the destination color and Fd to zero. So assuming Fs=Cd and Fd=0, the resulting color is C = Cs*Cd + Cd*0. You get this setup by calling glBlendFunc(GL_DST_COLOR, GL_ZERO).

Learning how the blend equation works will allow you to solve blending problems in the future, but learning how to setup multiplicative blending will solve that problem only. So take some time to learn the blending equation in general.
Well, now that you post it that way I feel stoopid .

Thanks for the info, for some reason I thought that you couldn''t put SRC_COLOR into the dfactor and vice versa, now I know.

This topic is closed to new replies.

Advertisement