Package com.jme3.post

Class FilterPostProcessor

java.lang.Object
com.jme3.post.FilterPostProcessor
All Implemented Interfaces:
Savable, SceneProcessor

public class FilterPostProcessor extends Object implements SceneProcessor, Savable
A `FilterPostProcessor` is a SceneProcessor that can apply several Filters to a rendered scene. It manages a list of filters that will be applied in the order in which they have been added. This processor handles rendering the main scene to an offscreen framebuffer, then applying each enabled filter sequentially, optionally with anti-aliasing (multisampling) and depth texture support.
  • Field Details

    • FPP

      public static final String FPP
      The simple name of this class, used for profiling.
  • Constructor Details

    • FilterPostProcessor

      public FilterPostProcessor(AssetManager assetManager)
      Creates a new `FilterPostProcessor`.
      Parameters:
      assetManager - The asset manager to be used by filters for loading assets.
    • FilterPostProcessor

      protected FilterPostProcessor()
      Serialization-only constructor. Do not use this constructor directly; use FilterPostProcessor(AssetManager).
  • Method Details

    • addFilter

      public void addFilter(Filter filter)
      Adds a filter to the list of filters to be applied. Filters are applied in the order they are added. If the processor is already initialized, the filter is immediately initialized as well.
      Parameters:
      filter - The filter to add (not null).
      Throws:
      IllegalArgumentException - If the provided filter is null.
    • removeFilter

      public void removeFilter(Filter filter)
      Removes a specific filter from the list. The filter's `cleanup` method is called upon removal.
      Parameters:
      filter - The filter to remove (not null).
      Throws:
      IllegalArgumentException - If the provided filter is null.
    • getFilterIterator

      public Iterator<Filter> getFilterIterator()
      Returns an iterator over the filters currently managed by this processor.
      Returns:
      An `Iterator` of Filter objects.
    • initialize

      public void initialize(RenderManager rm, ViewPort vp)
      Initializes the `FilterPostProcessor`. This method is called by the `RenderManager` when the processor is added to a viewport.
      Specified by:
      initialize in interface SceneProcessor
      Parameters:
      rm - The `RenderManager` instance.
      vp - The `ViewPort` this processor is attached to.
    • getDefaultPassTextureFormat

      public Image.Format getDefaultPassTextureFormat()
      Returns the default color buffer format used for the internal rendering passes of the filters. This format is determined during initialization based on the renderer's capabilities.
      Returns:
      The default `Format` for the filter pass textures.
    • isInitialized

      public boolean isInitialized()
      Checks if the `FilterPostProcessor` has been initialized.
      Specified by:
      isInitialized in interface SceneProcessor
      Returns:
      True if initialized, false otherwise.
    • postQueue

      public void postQueue(RenderQueue rq)
      Description copied from interface: SceneProcessor
      Called after the scene graph has been queued, but before it is flushed.
      Specified by:
      postQueue in interface SceneProcessor
      Parameters:
      rq - The render queue
    • postFrame

      public void postFrame(FrameBuffer out)
      Description copied from interface: SceneProcessor
      Called after a frame has been rendered and the queue flushed.
      Specified by:
      postFrame in interface SceneProcessor
      Parameters:
      out - The FB to which the scene was rendered.
    • preFrame

      public void preFrame(float tpf)
      Description copied from interface: SceneProcessor
      Called before a frame
      Specified by:
      preFrame in interface SceneProcessor
      Parameters:
      tpf - Time per frame
    • setFilterState

      protected void setFilterState(Filter filter, boolean enabled)
      Sets the enabled state of a specific filter. If the filter is part of this processor's list, its `enabled` flag is updated, and the `lastFilterIndex` is recomputed.
      Parameters:
      filter - The Filter to modify (not null).
      enabled - True to enable the filter, false to disable it.
    • cleanup

      public void cleanup()
      Description copied from interface: SceneProcessor
      Called when the SP is removed from the RM.
      Specified by:
      cleanup in interface SceneProcessor
    • setProfiler

      public void setProfiler(AppProfiler profiler)
      Sets the profiler instance for this processor.
      Specified by:
      setProfiler in interface SceneProcessor
      Parameters:
      profiler - The `AppProfiler` instance to use for performance monitoring.
    • reshape

      public void reshape(ViewPort vp, int w, int h)
      Reshapes the `FilterPostProcessor` when the viewport or canvas size changes. This method recalculates internal framebuffer dimensions, creates new framebuffers and textures if necessary (e.g., for anti-aliasing), and reinitializes all filters with the new dimensions. It also detects multi-view scenarios.
      Specified by:
      reshape in interface SceneProcessor
      Parameters:
      vp - The `ViewPort` being reshaped.
      w - The new width of the viewport's canvas.
      h - The new height of the viewport's canvas.
    • getNumSamples

      public int getNumSamples()
      Returns the number of samples used for anti-aliasing.
      Returns:
      The number of samples.
    • removeAllFilters

      public void removeAllFilters()
      Removes all filters currently added to this processor.
    • setNumSamples

      public void setNumSamples(int numSamples)
      Sets the number of samples for anti-aliasing. A value of 1 means no anti-aliasing. This method should generally be called before the processor is initialized to have an effect.
      Parameters:
      numSamples - The number of samples. Must be greater than 0.
      Throws:
      IllegalArgumentException - If `numSamples` is less than or equal to 0.
    • setAssetManager

      public void setAssetManager(AssetManager assetManager)
      Sets the asset manager for this processor
      Parameters:
      assetManager - to load assets
    • setFrameBufferFormat

      public void setFrameBufferFormat(Image.Format fbFormat)
      Sets the preferred `Image.Format` to be used for the internal frame buffer's color buffer.
      Parameters:
      fbFormat - The desired `Format` for the color buffer.
    • setFrameBufferDepthFormat

      public void setFrameBufferDepthFormat(Image.Format depthFormat)
      Sets the preferred `Image.Format` to be used for the internal frame buffer's depth buffer.
      Parameters:
      depthFormat - The desired `Format` for the depth buffer.
    • getFrameBufferDepthFormat

      public Image.Format getFrameBufferDepthFormat()
      Returns the `Image.Format` currently used for the internal frame buffer's depth buffer.
      Returns:
      The current depth `Format`.
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      Throws:
      IOException
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • getDepthTexture

      public Texture2D getDepthTexture()
      For internal use only. Returns the depth texture generated from the scene's depth buffer. This texture is available if any filter requires a depth texture.
      Returns:
      The `Texture2D` containing the scene's depth information, or null if not computed.
    • getFilterTexture

      public Texture2D getFilterTexture()
      For internal use only. Returns the color texture that contains the rendered scene or the output of the previous filter in the chain. This texture serves as input for subsequent filters.
      Returns:
      The `Texture2D` containing the scene's color information or the intermediate filter output.
    • getFilter

      public <T extends Filter> T getFilter(Class<T> filterType)
      Returns the first filter in the managed list that is assignable from the given filter type. Useful for retrieving specific filters to modify their properties.
      Type Parameters:
      T - The type of the filter to retrieve.
      Parameters:
      filterType - The `Class` object representing the filter type.
      Returns:
      A filter instance assignable from `filterType`, or null if no such filter is found.
    • getFilterList

      public List<Filter> getFilterList()
      Returns an unmodifiable version of the list of filters currently managed by this processor.
      Returns:
      An unmodifiable `List` of Filter objects.