Blender Materials: setBlending

setBlending(source, destination)
  • sets the blending source and destination values.

source: 

  • 0 = bge.logic.BL_ZERO
  • 1 = bge.logic.BL_ONE
  • 768 = bge.logic.BL_SRC_COLOR
  • 769 = bge.logic.BL_ONE_MINUS_SRC_COLOR
  • 774 = bge.logic.BL_DST_COLOR
  • 775 = bge.logic.BL_ONE_MINUS_DST_COLOR
  • 770 = bge.logic.BL_SRC_ALPHA
  • 771 = bge.logic.BL_ONE_MINUS_SRC_ALPHA
  • 772 = bge.logic.BL_DST_ALPHA
  • 773 = bge.logic.BL_ONE_MINUS_DST_ALPHA
  • 776 = bge.logic.BL_SRC_ALPHA_SATURATE
destination: 
  • 0 = bge.logic.BL_ZERO
  • 1 = bge.logic.BL_ONE
  • 768 = bge.logic.BL_SRC_COLOR
  • 769 = bge.logic.BL_ONE_MINUS_SRC_COLOR
  • 774 = bge.logic.BL_DST_COLOR
  • 775 = bge.logic.BL_ONE_MINUS_DST_COLOR
  • 770 = bge.logic.BL_SRC_ALPHA
  • 771 = bge.logic.BL_ONE_MINUS_SRC_ALPHA
  • 772 = bge.logic.BL_DST_ALPHA
  • 773 = bge.logic.BL_ONE_MINUS_DST_ALPHA
  • 776 = bge.logic.BL_SRC_ALPHA_SATURATE
Note:
  • Textures are drawn by blending the incoming (source) RGBA color values with the RGBA color values already in the frame buffer (destination)
     
  • Works with Multitexture.  Doesn't work with GLSL or Singletexture.
     
  • Properties menu >> Scene button >> Shading >> Multitexture
Sample Code

# The code below uses a texture's alpha channel. 
# The Alpha in the Game Setting tab doesn't have to be enabled.

# import bge
import bge

# get the current controller
controller = bge.logic.getCurrentController()

# get object that owns this controller
obj = controller.owner
 
# There's only one mesh on my model
mesh = obj.meshes[0]

# And only one material on the mesh
mat = mesh.materials[0]

# set blending of pixels to use texture's alpha channel
# using Multitexture Shading

mat.setBlending(bge.logic.BL_SRC_ALPHA , bge.logic.BL_ONE_MINUS_SRC_ALPHA )