From BlenderWiki

Jump to: navigation, search

Actuator: 2D Filters

2D Filters are image filtering actuators, that apply on final render of objects. Thanks Social et.al. for FPS_Template.

Motion Blur

Motion Blur is a 2D Filter that needs previous rendering information to produce motion effect on objects. Bellow you can see Motion Blur filter in Blender window, along with its logic bricks:

2D Filters: Motion Blur.
2D Filters: Game Logic.

To enable this filter:

  1. Add appropriate Sensor(s) and Controller(s).
  2. Add a 2D Filter Actuator.
  3. Select Motion Blur in the drop-down list.
  4. Set Motion Blur Value (Factor).

And for disabling this filter:

  1. Add appropriate Sensor(s) and Controller(s).
  2. Add a 2D Filter Actuator.
  3. Select Motion Blur.
  4. Click on D button to go to disabled mode.

You can enable Motion Blur filter using a Python controller:

import Rasterizer
Rasterizer.enableMotionBlur(0.85)

And disable it:

import Rasterizer
Rasterizer.disableMotionBlur()
Note
Your graphic hardware and OpenGL driver must support accumulation buffer (glAccum function).


Built-In 2D Filters

All 2D filters you can see in 2D Filter actuator have the same architecture, all built-in filters use fragment shader to produce final render view, so your hardware must support shaders.

2D Filters: Motion Blur.
2D Filters: Sepia.
2D Filters: Sobel.

Blur, Sharpen, Dilation, Erosion, Laplacian, Sobel, Prewitt, Gray Scale, Sepia and Invert are built-in filters. These filters can be set to be available in some passes.

To use a filter you should:

  1. Create appropriate sensor(s) and controller(s).
  2. Create a 2D Filter actuator.
  3. Select your filter, for example Blur.
  4. Set the pass number that the filter will be applied.

To remove a filter on a specific pass:

  1. Create appropriate sensor(s) and controller(s).
  2. Create a 2D Filter actuator.
  3. Select Remove Filter.
  4. Set the pass number you want to remove the filter from it.

To disable a filter on a specific pass:

  1. Create appropriate sensor(s) and controller(s).
  2. Create a 2D Filter actuator.
  3. Select Disable Filter.
  4. Set the pass number you want to disable the filter on it.

To enable a filter on a specific pass:

  1. Create appropriate sensor(s) and controller(s)
  2. Create a 2D Filter actuator.
  3. Select Enable Filter.
  4. Set the pass number you want to enable the filter on it.


Custom Filters

2D Filters: Custom Filter.

Custom filters give you the ability to define your own 2D filter using GLSL. Its usage is the same as built-in filters, but you must select Custom Filter in 2D Filter actuator, then write shader program into the Text Editor, and then place shader script name on actuator.

Blue Sepia Example:

uniform sampler2D bgl_RenderedTexture;
void main(void)
{
  vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
  float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114));
  gl_FragColor = vec4(gray * vec3(0.8, 1.0, 1.2), texcolor.a);
}