Package com.jme3.post

Class Filter

java.lang.Object
com.jme3.post.Filter
All Implemented Interfaces:
Savable
Direct Known Subclasses:
AbstractShadowFilter, AbstractShadowFilterVR, BloomFilter, CartoonEdgeFilter, CartoonSSAO, ColorOverlayFilter, ComposeFilter, ContrastAdjustmentFilter, CrossHatchFilter, DepthOfFieldFilter, FadeFilter, FogFilter, FXAAFilter, GammaCorrectionFilter, LightScatteringFilter, PosterizationFilter, PssmShadowFilter, RadialBlurFilter, SoftBloomFilter, SSAOFilter, ToneMapFilter, TranslucentBucketFilter, WaterFilter

public abstract class Filter extends Object implements Savable
Filters are 2D effects applied to the rendered scene.
The filter is fed with the rendered scene image rendered in an offscreen frame buffer.
This texture is applied on a full-screen quad with a special material.
This material uses a shader that applies the desired effect to the scene texture.

This class is abstract, any Filter must extend it.
Any filter holds a frameBuffer and a texture
The getMaterial must return a Material that use a GLSL shader implementing the desired effect
  • Field Details

  • Constructor Details

    • Filter

      public Filter(String name)
    • Filter

      protected Filter()
      construct a Filter
  • Method Details

    • getDefaultPassTextureFormat

      protected Image.Format getDefaultPassTextureFormat()
      Returns:
      the default pass texture format
    • getDefaultPassDepthFormat

      protected Image.Format getDefaultPassDepthFormat()
      returns the default pass depth format
      Returns:
      the enum value
    • init

      protected final void init(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h)
      initialize this filter use InitFilter for overriding filter initialization
      Parameters:
      manager - the assetManager
      renderManager - the renderManager
      vp - the viewport
      w - the width
      h - the height
    • cleanup

      protected final void cleanup(Renderer r)
      cleanup this filter
      Parameters:
      r - the Renderer
    • initFilter

      protected abstract void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h)
      Initialization of filter subclasses. This method is called once when the filter is added to the FilterPostProcessor It should contain Material initializations and extra passes initialization
      Parameters:
      manager - the assetManager
      renderManager - the renderManager
      vp - the viewPort where this filter is rendered
      w - the width of the filter
      h - the height of the filter
    • cleanUpFilter

      protected void cleanUpFilter(Renderer r)
      override this method if you have some cleanup to do
      Parameters:
      r - the renderer
    • getMaterial

      protected abstract Material getMaterial()
      Must return the material used for this filter. this method is called every frame.
      Returns:
      the material used for this filter.
    • setDepthTexture

      protected void setDepthTexture(Texture depthTexture)
      Override if you want to do something special with the depth texture;
      Parameters:
      depthTexture - the desired Texture
    • postQueue

      protected void postQueue(RenderQueue queue)
      Override this method if you want to make a pre pass, before the actual rendering of the frame
      Parameters:
      queue - the RenderQueue
    • preFrame

      protected void preFrame(float tpf)
      Override this method if you want to modify parameters according to tpf before the rendering of the frame. This is useful for animated filters Also it can be the place to render pre passes
      Parameters:
      tpf - the time used to render the previous frame
    • postFrame

      protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer)
      Override this method if you want to make a pass just after the frame has been rendered and just before the filter rendering
      Parameters:
      renderManager - for rendering
      viewPort - for rendering
      prevFilterBuffer - the FrameBuffer of the previous filter
      sceneBuffer - the FrameBuffer of the scene
    • write

      public void write(JmeExporter ex) throws IOException
      Override this method if you want to save extra properties when the filter is saved else only basic properties of the filter will be saved This method should always begin by super.write(ex);
      Specified by:
      write in interface Savable
      Parameters:
      ex - the exporter (not null)
      Throws:
      IOException - from the exporter
    • read

      public void read(JmeImporter im) throws IOException
      Override this method if you want to load extra properties when the filter is loaded else only basic properties of the filter will be loaded This method should always begin by super.read(im);
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • getName

      public String getName()
      returns the name of the filter
      Returns:
      the Filter's name
    • setName

      public void setName(String name)
      Sets the name of the filter
      Parameters:
      name - the desired name (alias created)
    • getRenderFrameBuffer

      protected FrameBuffer getRenderFrameBuffer()
      returns the default pass frame buffer
      Returns:
      the pre-existing buffer
    • setRenderFrameBuffer

      protected void setRenderFrameBuffer(FrameBuffer renderFrameBuffer)
      sets the default pass frame buffer
      Parameters:
      renderFrameBuffer - the buffer to use (alias created)
    • getRenderedTexture

      protected Texture2D getRenderedTexture()
      returns the rendered texture of this filter
      Returns:
      the pre-existing texture
    • setRenderedTexture

      protected void setRenderedTexture(Texture2D renderedTexture)
      sets the rendered texture of this filter
      Parameters:
      renderedTexture - the desired Texture (alias created)
    • isRequiresDepthTexture

      protected boolean isRequiresDepthTexture()
      Override this method and return true if your Filter needs the depth texture
      Returns:
      true if your Filter need the depth texture
    • isRequiresSceneTexture

      protected boolean isRequiresSceneTexture()
      Override this method and return false if your Filter does not need the scene texture
      Returns:
      false if your Filter does not need the scene texture
    • isRequiresBilinear

      protected boolean isRequiresBilinear()
      Override this method and return true if you want the scene (input) texture to use bilinear filtering or false to use nearest filtering. Typically, filters that perform samples in between pixels should enable bilinear filtering.
      Returns:
      true to use linear filtering, false to use nearest filtering.
    • getPostRenderPasses

      protected List<Filter.Pass> getPostRenderPasses()
      returns the list of the postRender passes
      Returns:
      the pre-existing List
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable this filter
      Parameters:
      enabled - true to enable
    • isEnabled

      public boolean isEnabled()
      returns true if the filter is enabled
      Returns:
      enabled
    • setProcessor

      protected void setProcessor(FilterPostProcessor proc)
      sets a reference to the FilterPostProcessor to which this filter is attached
      Parameters:
      proc - the desired FPP (alias created)
    • postFilter

      protected void postFilter(Renderer r, FrameBuffer buffer)
      This method is called right after the filter has been rendered to the framebuffer. Note that buffer will be null if the filter is the last one in the stack and has been rendered to screen
      Parameters:
      r - the renderer
      buffer - the framebuffer on which the filter has been rendered.