Package com.jme3.post
Class FilterPostProcessor
java.lang.Object
com.jme3.post.FilterPostProcessor
- All Implemented Interfaces:
Savable,SceneProcessor
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSerialization-only constructor.FilterPostProcessor(AssetManager assetManager) Creates a new `FilterPostProcessor`. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a filter to the list of filters to be applied.voidcleanup()Called when the SP is removed from the RM.Returns the default color buffer format used for the internal rendering passes of the filters.For internal use only.<T extends Filter>
TReturns the first filter in the managed list that is assignable from the given filter type.Returns an iterator over the filters currently managed by this processor.Returns an unmodifiable version of the list of filters currently managed by this processor.For internal use only.Returns the `Image.Format` currently used for the internal frame buffer's depth buffer.intReturns the number of samples used for anti-aliasing.voidinitialize(RenderManager rm, ViewPort vp) Initializes the `FilterPostProcessor`.booleanChecks if the `FilterPostProcessor` has been initialized.voidpostFrame(FrameBuffer out) Called after a frame has been rendered and the queue flushed.voidpostQueue(RenderQueue rq) Called after the scene graph has been queued, but before it is flushed.voidpreFrame(float tpf) Called before a framevoidread(JmeImporter im) voidRemoves all filters currently added to this processor.voidremoveFilter(Filter filter) Removes a specific filter from the list.voidReshapes the `FilterPostProcessor` when the viewport or canvas size changes.voidsetAssetManager(AssetManager assetManager) Sets the asset manager for this processorprotected voidsetFilterState(Filter filter, boolean enabled) Sets the enabled state of a specific filter.voidsetFrameBufferDepthFormat(Image.Format depthFormat) Sets the preferred `Image.Format` to be used for the internal frame buffer's depth buffer.voidsetFrameBufferFormat(Image.Format fbFormat) Sets the preferred `Image.Format` to be used for the internal frame buffer's color buffer.voidsetNumSamples(int numSamples) Sets the number of samples for anti-aliasing.voidsetProfiler(AppProfiler profiler) Sets the profiler instance for this processor.voidwrite(JmeExporter ex) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.jme3.post.SceneProcessor
rescale
-
Field Details
-
FPP
The simple name of this class, used for profiling.
-
-
Constructor Details
-
FilterPostProcessor
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; useFilterPostProcessor(AssetManager).
-
-
Method Details
-
addFilter
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
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
Returns an iterator over the filters currently managed by this processor.- Returns:
- An `Iterator` of
Filterobjects.
-
initialize
Initializes the `FilterPostProcessor`. This method is called by the `RenderManager` when the processor is added to a viewport.- Specified by:
initializein interfaceSceneProcessor- Parameters:
rm- The `RenderManager` instance.vp- The `ViewPort` this processor is attached to.
-
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:
isInitializedin interfaceSceneProcessor- Returns:
- True if initialized, false otherwise.
-
postQueue
Description copied from interface:SceneProcessorCalled after the scene graph has been queued, but before it is flushed.- Specified by:
postQueuein interfaceSceneProcessor- Parameters:
rq- The render queue
-
postFrame
Description copied from interface:SceneProcessorCalled after a frame has been rendered and the queue flushed.- Specified by:
postFramein interfaceSceneProcessor- Parameters:
out- The FB to which the scene was rendered.
-
preFrame
public void preFrame(float tpf) Description copied from interface:SceneProcessorCalled before a frame- Specified by:
preFramein interfaceSceneProcessor- Parameters:
tpf- Time per frame
-
setFilterState
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- TheFilterto modify (not null).enabled- True to enable the filter, false to disable it.
-
cleanup
public void cleanup()Description copied from interface:SceneProcessorCalled when the SP is removed from the RM.- Specified by:
cleanupin interfaceSceneProcessor
-
setProfiler
Sets the profiler instance for this processor.- Specified by:
setProfilerin interfaceSceneProcessor- Parameters:
profiler- The `AppProfiler` instance to use for performance monitoring.
-
reshape
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:
reshapein interfaceSceneProcessor- 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
Sets the asset manager for this processor- Parameters:
assetManager- to load assets
-
setFrameBufferFormat
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
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
Returns the `Image.Format` currently used for the internal frame buffer's depth buffer.- Returns:
- The current depth `Format`.
-
write
- Specified by:
writein interfaceSavable- Throws:
IOException
-
read
- Specified by:
readin interfaceSavable- Throws:
IOException
-
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
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
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
Returns an unmodifiable version of the list of filters currently managed by this processor.- Returns:
- An unmodifiable `List` of
Filterobjects.
-