ImageRender: filter

filter
  • set the image filter

FilterBGR24():

  • Switches the Red and Blue color channels.  Red becomes blue.  Blue becomes red.
FilterBlueScreen():
  • Creates a Bluescreen effect.  Blue pixels are rendered transparent.
FilterColor():
  • Applies a custom color filter to the image.
  • FilterColor().matrix
4×5 integer matrix that contains parameters for color calculation.
Matrix provides general color transformation filter.
Resulting color values are calculated using matrix 4×5.
Every matrix row contains parameters for one color channel calculation.
Order of rows: red, green, blue, alpha.
Parameters in row define coefficients for source color channels in same order.

FilterGray():
  • Converts image to grayscale.
FilterLevel():
  • Filter for levels calculations.
  • FilterLevel().levels
FilterNormal():
  • Converts the images to normal maps.
FilterRGB24():
  • Resets the color channels.  Red becomes Red.  Green becomes Green.  Blue becomes Blue.
FilterRGBA32():
  • Uses the Blender 3D color sliders to set the Filter's Red, Green, Blue and Alpha channels.
Sample Code

###################### set filter

# import bge module
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get a list of the cameras
camList = scene.cameras

# get camera being used for render to texture
# my camera is named Security_Cam

cam = camList["Security_Cam"]

# get list of objects in scene
objList = scene.objects

# get object to render to
# my object is named SecurityMonitor

obj = objList["SecurityMonitor"]

# get the SecurityMonitor material ID
# Name of my render material is Screen
matID = bge.texture.materialID(obj, "MAScreen")

# set the texture
renderToTexture = bge.texture.Texture(obj, matID)

# get the texture image
renderToTexture.source = bge.texture.ImageRender(scene,cam)

# set grayscale filter
renderToTexture.source.filter = bge.texture.FilterGray()

# save RenderToTexture as an object variable
obj["Render"] = renderToTexture

# update the texture
renderToTexture.refresh(True)