Multiply Blend Mode Proposal

Hey. I was wondering if it would be advantageous at all to add a Multiply blend mode to the material blending mode options (like how Add, Clip Alpha, Alpha, and Opaque are there). It’d be useful for sure, as I’m currently contemplating making a GLSL script just to have a texture draw as multiply (the lighting 2D texture in Valchion), which would hurt the FPS on older computers, I think, if it’s even possible for them.

I had it working before, but tried to speed things up via moving the drawing method to BGUI, which didn’t work out so well (drawing from an image source isn’t supported).

Anyway, a Multiply blend mode would be really appreciated. Maybe even exposing the destination and source blend modes entirely to the material editor? I might even be able to do something about that…

+1 . Would be quite useful ! Yep…

A subtract would be AWESOME. Like how add is light, but subtract would be darkness? I would love that.

Do you have tried with bge.texture.ImageMix.

While mathematically, subtracting a value is the opposite of adding a value, color-wise, multiply would be what you’re looking for (and how I do the lighting in Valchion). The color black is opaque, and the color white is transparent.

I haven’t really tried it that much, but last I recall, that process doesn’t actually give you full control over the mix of the images, since it has to add up to 1.0 alpha transparency per image. If you mix two images, they both will be partially transparent, rather than adding them both onto the same image and capping the output. For example, if image A has a white circle on a black background and image B has another white circle on a black background (but on a different position), mixing them will give you two gray circles, not two white circles. Anyway, that doesn’t really do much for my idea here.

I think custom blending modes would be a nice addition, especially considering there’s no surefire way to do it currently. In all modes (Single-Texture, Multi-Texture, and GLSL), you might (?) be able to use a GLSL shader to change the blending modes (however, this might not be the case, since I believe alpha-blending requires you to change the setting in the Blender Material).

For SingleTexture mode, you can’t change the blending modes apart from this (though you can tweak other stranger settings, making what’s known as a Python material (?) ). For Multi-Texture mode, you can alter the blending mode using Python (pretty cool, actually). For GLSL mode, there’s no such property. You might be able to do it with a fancy material setup (using calculated alpha as opposed to the built-in alpha for the alpha of the image, which makes it use white as opaque and black as transparent, but then inverting that alpha map).

Anyway, I think a simple method that works across these drawing modes would be nice. The Python-accessible properties would be nice to be added in for all of the draw modes, as would custom blending modes accessible via the material editor (i.e. where you specify the source and destination blending mode types manually). I might try a simple multiply blending mode and see how far I get with that to start, though.

More options are always nice, but I’m not sure where a multiply blend mode would come in handy. I assume you’re handling the lighting in Valchion using a textured plane set to the mix blend mode? What advantages would a multiply blend mode offer you over that?

@laser blaster - I actually am using a multiply blending mode to draw the lighting layer in Valchion; it’s just drawn over the screen with OpenGL (where I can customize the blend mode). I’m pretty sure the effect would be impossible without using multiply (or possibly another blending mode). Example with multiply mode on the left (correct), and simply drawing the lighting texture on the screen on the right:

The blending mode tells OpenGL to turn white to transparent, and darker values to opaque. That’s why the light areas, like the area under the ceiling light, are brighter than other areas.

EDIT: I actually almost have it implemented. It’s working in GLSL and MultiTexture mode, but SingleTexture’s holding me up. :1

Wait, so the spot light areas are actually *add ? Or are they really like cut-outs? I’m confused. . . O.o

*or multiply to lighten AND darken?

Basically, they’re like cut-outs. The gradient at the top-left is special (it’s an actual gradient of light), but the other lights are simply white (or blue, for the top console light) on a darker background. The dark areas turn opaque, and the light areas turn transparent.