Class AbstractShadowRenderer
- All Implemented Interfaces:
Savable,SceneProcessor,JmeCloneable,Cloneable
- Direct Known Subclasses:
DirectionalLightShadowRenderer,PointLightShadowRenderer,SpotLightShadowRenderer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AssetManagerprotected booleanprotected booleanprotected Picture[]protected Texture2Dprotected EdgeFilteringModeprotected floatprotected Vector2fprotected floatprotected RenderStateprotected Cameraprotected GeometryListprotected Matrix4f[]protected static final Loggerprotected intprotected booleanprotected Materialprotected Stringprotected Materialprotected AppProfilerprotected booleanprotected RenderManagerprotected CompareModeprotected FrameBuffer[]protected floatprotected GeometryListprotected Texture2D[]protected floatprotected booleanprotected ViewPortprotected float -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFor serialization only.protectedAbstractShadowRenderer(AssetManager assetManager, int shadowMapSize, int nbShadowMaps) Creates an AbstractShadowRenderer. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleancheckCulling(Camera viewCam) Abstract method to check if the light source's bounding box is within the view frustum of the given camera.voidcleanup()Called when the SP is removed from the RM.protected abstract voidclearMaterialParameters(Material material) This method is called once per frame and is responsible for clearing any material parameters that subclasses may have set on the post-shadow material.voidcloneFields(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.protected GeometrycreateFrustum(Vector3f[] pts, int i) Debug function to create a visible wireframe frustum.voidFor debugging purposes, "snapshots" the current state of the shadow maps and displays them on screen.voidEnables debugging of shadow frustums, making them visible in the scene.protected voidFor debugging purposes, displays the depth shadow maps on screen as Picture quads.protected voiddoDisplayFrustumDebug(int shadowMapIndex) Responsible for displaying the frustum of the shadow camera for debugging purposes.Returns the currently edge filtering mode for shadows.intReturns the configured shadow edges thickness.intReturns the number of shadow maps currently rendered by this processor.protected abstract GeometryListgetOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) Returns a subclass-specificGeometryListcontaining the occluders that should be rendered into the shadow map.Returns theRenderStatethat is forced during the pre-shadow pass.protected abstract voidgetReceivers(GeometryList lightReceivers) Populates the providedGeometryListwith geometries that are considered shadow receivers.protected abstract CameragetShadowCam(int shadowMapIndex) Returns the shadow camera to use for rendering the shadow map according to the given index.Returns the currently shadow comparison mode.floatReturns the current shadow intensity.intReturns the size (width and height) of each shadow map rendered by this processor.floatReturns the maximum distance from the eye where shadows are rendered.floatReturns the length over which the shadow will fade out when using a custom `shadowZextend`.protected voidprotected abstract voidDelegates the initialization of the frustum camera to child renderers.voidinitialize(RenderManager rm, ViewPort vp) Initialize this shadow renderer prior to its first update.booleanDeprecated.booleanTest whether this shadow renderer has been initialized.booleanChecks if this shadow processor is configured to render shadows from back faces.jmeClone()Performs a regular shallow clone of the object.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) De-serialize this instance, for example when loading from a J3O file.protected voidrenderShadowMap(int shadowMapIndex) voidCalled when the resolution of the viewport has been changed.final voidsetEdgeFilteringMode(EdgeFilteringMode filterMode) Sets the filtering mode for shadow edges.voidsetEdgesThickness(int edgesThickness) Sets the shadow edges thickness.protected abstract voidsetMaterialParameters(Material material) This method is called once per frame and is responsible for setting any material parameters that subclasses may need to set on the post material.protected final voidsetPostShadowMaterial(Material postShadowMat) Sets the post-shadow material for this renderer.protected voidFor internal use only.voidsetProfiler(AppProfiler profiler) Sets a profiler Instance for this processor.voidsetRenderBackFacesShadows(boolean renderBackFacesShadows) Sets whether back faces of geometries should cast shadows.final voidsetShadowCompareMode(CompareMode compareMode) Sets the shadow comparison mode.final voidsetShadowIntensity(float shadowIntensity) Sets the shadow intensity.voidsetShadowZExtend(float zFar) Sets the distance from the camera where shadows will be rendered.voidsetShadowZFadeLength(float length) Defines the length over which the shadow will fade out when using a custom `shadowZextend`.protected abstract voidupdateShadowCams(Camera viewCam) Invoked once per frame to update the shadow cameras according to the light view.voidwrite(JmeExporter ex) Serialize this instance, for example when saving to a J3O file.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
-
logger
-
nbShadowMaps
protected int nbShadowMaps -
shadowMapSize
protected float shadowMapSize -
shadowIntensity
protected float shadowIntensity -
renderManager
-
viewPort
-
shadowFB
-
shadowMaps
-
dummyTex
-
preshadowMat
-
postshadowMat
-
lightViewProjectionsMatrices
-
assetManager
-
debug
protected boolean debug -
edgesThickness
protected float edgesThickness -
edgeFilteringMode
-
shadowCompareMode
-
dispPic
-
forcedRenderState
-
renderBackFacesShadows
protected boolean renderBackFacesShadows -
prof
-
debugfrustums
protected boolean debugfrustums -
needsfallBackMaterial
protected boolean needsfallBackMaterial -
postTechniqueName
-
matCache
-
lightReceivers
-
shadowMapOccluders
-
zFarOverride
protected float zFarOverride -
fadeInfo
-
fadeLength
protected float fadeLength -
frustumCam
-
skipPostPass
protected boolean skipPostPass
-
-
Constructor Details
-
AbstractShadowRenderer
protected AbstractShadowRenderer()For serialization only. Do not use. -
AbstractShadowRenderer
Creates an AbstractShadowRenderer. Subclasses invoke this constructor.- Parameters:
assetManager- The application's asset manager.shadowMapSize- The size of the rendered shadow maps (e.g., 512, 1024, 2048).nbShadowMaps- The number of shadow maps to render (1 to 4). More maps improve quality but can reduce performance.
-
-
Method Details
-
initForcedRenderState
protected void initForcedRenderState() -
setPostShadowMaterial
Sets the post-shadow material for this renderer. This material is used to apply the shadows to the main scene.- Parameters:
postShadowMat- The desired Material instance to use (alias created).
-
setEdgeFilteringMode
Sets the filtering mode for shadow edges. This affects the smoothness of shadow boundaries.- Parameters:
filterMode- The desired filtering mode (cannot be null). SeeEdgeFilteringModefor available options.
-
getEdgeFilteringMode
Returns the currently edge filtering mode for shadows.- Returns:
- The current
EdgeFilteringModeenum value. - See Also:
-
setShadowCompareMode
Sets the shadow comparison mode. This determines how shadow map values are compared to generate shadows.- Parameters:
compareMode- The desired compare mode (cannot be null). SeeCompareModefor available options.
-
getShadowCompareMode
Returns the currently shadow comparison mode.- Returns:
- The current
CompareModeenum value. - See Also:
-
createFrustum
Debug function to create a visible wireframe frustum. This is useful for visualizing the shadow camera's view.- Parameters:
pts- Optional storage for vertex positions. If null, a new array will be created.i- The index, used to assign a color to the frustum for differentiation (e.g., for multiple shadow maps).- Returns:
- A new
Geometryrepresenting the wireframe frustum.
-
initialize
Initialize this shadow renderer prior to its first update.- Specified by:
initializein interfaceSceneProcessor- Parameters:
rm- the render managervp- the viewport
-
initFrustumCam
protected abstract void initFrustumCam()Delegates the initialization of the frustum camera to child renderers. This camera defines the view for calculating shadow frustums. -
isInitialized
public boolean isInitialized()Test whether this shadow renderer has been initialized.- Specified by:
isInitializedin interfaceSceneProcessor- Returns:
- true if initialized, otherwise false
-
updateShadowCams
Invoked once per frame to update the shadow cameras according to the light view. Subclasses must implement this method to define how shadow cameras are positioned and oriented.- Parameters:
viewCam- The main scene camera.
-
getOccludersToRender
protected abstract GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) Returns a subclass-specificGeometryListcontaining the occluders that should be rendered into the shadow map.- Parameters:
shadowMapIndex- The index of the shadow map being rendered.shadowMapOccluders- An existingGeometryListthat can be reused or populated.- Returns:
- A
GeometryListcontaining the geometries that cast shadows for the given map.
-
getShadowCam
Returns the shadow camera to use for rendering the shadow map according to the given index. Subclasses must implement this to provide the correct camera for each shadow map.- Parameters:
shadowMapIndex- The index of the shadow map being rendered.- Returns:
- The
Camerainstance representing the shadow's viewpoint.
-
doDisplayFrustumDebug
protected void doDisplayFrustumDebug(int shadowMapIndex) Responsible for displaying the frustum of the shadow camera for debugging purposes. Subclasses can override this method to provide specific debug visualizations.- Parameters:
shadowMapIndex- The index of the shadow map for which to display the frustum.
-
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
-
renderShadowMap
protected void renderShadowMap(int shadowMapIndex) -
displayFrustum
public void displayFrustum()Enables debugging of shadow frustums, making them visible in the scene. Call this beforepostQueue(RenderQueue)to see the frustums. -
displayShadowMap
For debugging purposes, displays the depth shadow maps on screen as Picture quads.- Parameters:
r- The currentRenderer(ignored).
-
displayDebug
public void displayDebug()For debugging purposes, "snapshots" the current state of the shadow maps and displays them on screen. -
getReceivers
Populates the providedGeometryListwith geometries that are considered shadow receivers. Subclasses must implement this method.- Parameters:
lightReceivers- TheGeometryListto populate with shadow-receiving geometries.
-
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.
-
clearMaterialParameters
This method is called once per frame and is responsible for clearing any material parameters that subclasses may have set on the post-shadow material. This ensures that parameters from previous frames or other renderers do not interfere.- Parameters:
material- The material that was used for the post-shadow pass.
-
setMaterialParameters
This method is called once per frame and is responsible for setting any material parameters that subclasses may need to set on the post material.- Parameters:
material- the material to use for the post shadow pass
-
setPostShadowParams
protected void setPostShadowParams()For internal use only. Sets the common shadow parameters on the internal post-shadow material. This is used when a fallback material is needed. -
getShadowZExtend
public float getShadowZExtend()Returns the maximum distance from the eye where shadows are rendered. A value of 0 indicates that the distance is dynamically computed based on scene bounds.- Returns:
- The shadow Z-extend distance in world units.
- See Also:
-
setShadowZExtend
public void setShadowZExtend(float zFar) Sets the distance from the camera where shadows will be rendered. By default (0), this value is dynamically computed based on the union bound of shadow casters and receivers, capped by the view frustum's far value. Setting a positive value overrides this dynamic computation.- Parameters:
zFar- The zFar value that overrides the computed one. Set to 0 to use dynamic computation.
-
setShadowZFadeLength
public void setShadowZFadeLength(float length) Defines the length over which the shadow will fade out when using a custom `shadowZextend`. This is useful for smoothly transitioning dynamic shadows into baked shadows or for preventing abrupt shadow cut-offs.- Parameters:
length- The fade length in world units. Set to 0 to disable fading.
-
getShadowZFadeLength
public float getShadowZFadeLength()Returns the length over which the shadow will fade out when using a custom `shadowZextend`.- Returns:
- The fade length in world units. Returns 0 if no fading is applied.
-
checkCulling
Abstract method to check if the light source's bounding box is within the view frustum of the given camera. This is used for culling to avoid unnecessary shadow computations.- Parameters:
viewCam- ACamerato define the view frustum against which to check.- Returns:
- True if the light source's bounding box is in the view frustum, otherwise false.
-
preFrame
public void preFrame(float tpf) Description copied from interface:SceneProcessorCalled before a frame- Specified by:
preFramein interfaceSceneProcessor- Parameters:
tpf- Time per frame
-
cleanup
public void cleanup()Description copied from interface:SceneProcessorCalled when the SP is removed from the RM.- Specified by:
cleanupin interfaceSceneProcessor
-
reshape
Description copied from interface:SceneProcessorCalled when the resolution of the viewport has been changed.- Specified by:
reshapein interfaceSceneProcessor- Parameters:
vp- the affected ViewPortw- the new width (in pixels)h- the new height (in pixels)
-
getShadowIntensity
public float getShadowIntensity()Returns the current shadow intensity.- Returns:
- The shadow intensity value, ranging from 0.0 to 1.0.
- See Also:
-
setShadowIntensity
public final void setShadowIntensity(float shadowIntensity) Sets the shadow intensity. This value controls the darkness of the shadows. A value of 0.0 results in bright, almost invisible shadows, while 1.0 creates pitch-black shadows. The default value is 0.7.- Parameters:
shadowIntensity- The desired darkness of the shadow, a float between 0.0 and 1.0.
-
getEdgesThickness
public int getEdgesThickness()Returns the configured shadow edges thickness. The value is returned as an integer representing tenths of a pixel (e.g., 10 for 1.0 pixel).- Returns:
- The edges thickness in tenths of a pixel.
- See Also:
-
getNumShadowMaps
public int getNumShadowMaps()Returns the number of shadow maps currently rendered by this processor.- Returns:
- The count of shadow maps.
-
getShadowMapSize
public int getShadowMapSize()Returns the size (width and height) of each shadow map rendered by this processor.- Returns:
- The resolution of a single shadow map in pixels.
-
setEdgesThickness
public void setEdgesThickness(int edgesThickness) Sets the shadow edges thickness. This parameter influences the smoothness of shadow edges, particularly with PCF (Percentage-Closer Filtering). Setting lower values can help reduce jagged artifacts.- Parameters:
edgesThickness- The desired thickness in tenths of a pixel (e.g., 10 for 1.0 pixel). The value is clamped between 1 and 10. Default is 10.
-
isFlushQueues
Deprecated.isFlushQueues does nothing now and is kept only for backward compatibility- Returns:
- false
-
getPreShadowForcedRenderState
Returns theRenderStatethat is forced during the pre-shadow pass. You can use this to adjust the rendering parameters for geometries that cast shadows. Note that this will be overridden if the "PreShadow" technique in the material definition has its own `ForcedRenderState`.- Returns:
- The
RenderStateapplied to the pre-shadow pass.
-
setRenderBackFacesShadows
public void setRenderBackFacesShadows(boolean renderBackFacesShadows) Sets whether back faces of geometries should cast shadows. When enabled, shadows cast by the back side of an object can appear. Be aware that back face shadows can sometimes lead to overly dark lighting when blended with existing dark areas.Setting this parameter will globally override this setting for ALL materials in the scene for the shadow pass. Alternatively, you can control this on individual materials using
Material.setBoolean(String, boolean)with the "BackfaceShadows" parameter.This method also automatically adjusts the
RenderState.FaceCullModeandRenderState.setPolyOffset(float, float)of the pre-shadow pass to accommodate back face rendering. You can further modify these usinggetPreShadowForcedRenderState().- Parameters:
renderBackFacesShadows- True to enable back face shadows, false to disable.
-
isRenderBackFacesShadows
public boolean isRenderBackFacesShadows()Checks if this shadow processor is configured to render shadows from back faces.- Returns:
- True if back face shadows are enabled, false otherwise.
-
jmeClone
Description copied from interface:JmeCloneablePerforms a regular shallow clone of the object. Some fields may also be cloned but generally only if they will never be shared with other objects. (For example, local Vector3fs and so on.)This method is separate from the regular clone() method so that objects might still maintain their own regular java clone() semantics (perhaps even using Cloner for those methods). However, because Java's clone() has specific features in the sense of Object's clone() implementation, it's usually best to have some path for subclasses to bypass the public clone() method that might be cloning fields and instead get at the superclass protected clone() methods. For example, through super.jmeClone() or another protected clone method that some base class eventually calls super.clone() in.
- Specified by:
jmeClonein interfaceJmeCloneable- Returns:
- a new instance
-
cloneFields
Description copied from interface:JmeCloneableImplemented to perform deep cloning for this object, resolving local cloned references using the specified cloner. The object can call cloner.clone(fieldValue) to deep clone any of its fields.Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied.
- Specified by:
cloneFieldsin interfaceJmeCloneable- Parameters:
cloner- The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.original- The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
-
setProfiler
Description copied from interface:SceneProcessorSets a profiler Instance for this processor.- Specified by:
setProfilerin interfaceSceneProcessor- Parameters:
profiler- the profiler instance.
-
read
De-serialize this instance, for example when loading from a J3O file.- Specified by:
readin interfaceSavable- Parameters:
im- importer (not null)- Throws:
IOException- from the importer
-
write
Serialize this instance, for example when saving to a J3O file.- Specified by:
writein interfaceSavable- Parameters:
ex- exporter (not null)- Throws:
IOException- from the exporter
-