Package com.jme3.shadow
Class AbstractShadowRenderer
java.lang.Object
com.jme3.shadow.AbstractShadowRenderer
- All Implemented Interfaces:
Savable
,SceneProcessor
,JmeCloneable
,Cloneable
- Direct Known Subclasses:
DirectionalLightShadowRenderer
,PointLightShadowRenderer
,SpotLightShadowRenderer
public abstract class AbstractShadowRenderer
extends Object
implements SceneProcessor, Savable, JmeCloneable, Cloneable
abstract shadow renderer that holds commons feature to have for a shadow
renderer
-
Field Summary
Modifier and TypeFieldDescriptionprotected AssetManager
protected boolean
protected Picture[]
protected Texture2D
protected EdgeFilteringMode
protected float
protected Vector2f
protected float
protected RenderState
protected Camera
protected GeometryList
protected Matrix4f[]
protected static final Logger
list of materials for post shadow queue geometriesprotected int
protected boolean
true if the fallback material should be used, otherwise falseprotected Material
protected String
name of the post material techniqueprotected Material
protected AppProfiler
protected boolean
protected RenderManager
protected CompareMode
protected FrameBuffer[]
protected float
protected GeometryList
protected Texture2D[]
protected float
protected boolean
true to skip the post pass when there are no shadow castersprotected ViewPort
protected float
fade shadows at distance -
Constructor Summary
ModifierConstructorDescriptionprotected
used for serializationprotected
AbstractShadowRenderer
(AssetManager assetManager, int shadowMapSize, int nbShadowMaps) Create an abstract shadow renderer. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
checkCulling
(Camera viewCam) void
cleanup()
Called when the SP is removed from the RM.protected abstract void
clearMaterialParameters
(Material material) This method is called once per frame and is responsible for clearing any material parameters that subclasses may need to clear on the post material.void
cloneFields
(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.protected Geometry
createFrustum
(Vector3f[] pts, int i) debug function to create a visible frustumvoid
For debugging purposes, "snapshot" the current frustum to the scene.void
protected void
For debugging purposes, display depth shadow maps.protected void
doDisplayFrustumDebug
(int shadowMapIndex) responsible for displaying the frustum of the shadow cam for debug purposereturns the edge filtering modeint
returns the edges thicknessint
Read the number of shadow maps rendered by this renderer.protected abstract GeometryList
getOccludersToRender
(int shadowMapIndex, GeometryList shadowMapOccluders) Returns a subclass-specific geometryList containing the occluders to be rendered in the shadow mapreturns the pre shadows pass render state.protected abstract void
getReceivers
(GeometryList lightReceivers) protected abstract Camera
getShadowCam
(int shadowMapIndex) return the shadow camera to use for rendering the shadow map according the given indexreturns the shadow compare modefloat
Returns the shadow intensity.int
Read the size of each shadow map rendered by this renderer.float
How far the shadows are rendered in the viewfloat
get the length over which the shadow will fade out when using a shadowZextendprotected void
protected abstract void
delegates the initialization of the frustum cam to child renderersvoid
initialize
(RenderManager rm, ViewPort vp) Initialize this shadow renderer prior to its first update.boolean
Deprecated.boolean
Test whether this shadow renderer has been initialized.boolean
if this processor renders back faces shadowsjmeClone()
Performs a regular shallow clone of the object.void
postFrame
(FrameBuffer out) Called after a frame has been rendered and the queue flushed.void
postQueue
(RenderQueue rq) Called after the scene graph has been queued, but before it is flushed.void
preFrame
(float tpf) Called before a framevoid
read
(JmeImporter im) De-serialize this instance, for example when loading from a J3O file.protected void
renderShadowMap
(int shadowMapIndex) void
Called when the resolution of the viewport has been changed.final void
setEdgeFilteringMode
(EdgeFilteringMode filterMode) Sets the filtering mode for shadow edges.void
setEdgesThickness
(int edgesThickness) Sets the shadow edges thickness.protected abstract void
setMaterialParameters
(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 void
setPostShadowMaterial
(Material postShadowMat) set the post shadow material for this rendererprotected void
for internal use onlyvoid
setProfiler
(AppProfiler profiler) Sets a profiler Instance for this processor.void
setRenderBackFacesShadows
(boolean renderBackFacesShadows) Set to true if you want back faces shadows on geometries.final void
setShadowCompareMode
(CompareMode compareMode) Sets the shadow compare mode.final void
setShadowIntensity
(float shadowIntensity) Set the shadowIntensity.void
setShadowZExtend
(float zFar) Set the distance from the eye where the shadows will be rendered default value is dynamically computed to the shadow casters/receivers union bound zFar, capped to view frustum far value.void
setShadowZFadeLength
(float length) Define the length over which the shadow will fade out when using a shadowZextend This is useful to make dynamic shadows fade into baked shadows in the distance.protected abstract void
updateShadowCams
(Camera viewCam) Invoked once per frame to update the shadow cams according to the light view.void
write
(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, wait
Methods 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
-
needsfallBackMaterial
protected boolean needsfallBackMaterialtrue if the fallback material should be used, otherwise false -
postTechniqueName
name of the post material technique -
matCache
list of materials for post shadow queue geometries -
lightReceivers
-
shadowMapOccluders
-
zFarOverride
protected float zFarOverridefade shadows at distance -
fadeInfo
-
fadeLength
protected float fadeLength -
frustumCam
-
skipPostPass
protected boolean skipPostPasstrue to skip the post pass when there are no shadow casters
-
-
Constructor Details
-
AbstractShadowRenderer
protected AbstractShadowRenderer()used for serialization -
AbstractShadowRenderer
Create an abstract shadow renderer. Subclasses invoke this constructor.- Parameters:
assetManager
- the application asset managershadowMapSize
- the size of the rendered shadow maps (512,1024,2048, etc...)nbShadowMaps
- the number of shadow maps rendered (the more shadow maps the more quality, the fewer fps).
-
-
Method Details
-
initForcedRenderState
protected void initForcedRenderState() -
setPostShadowMaterial
set the post shadow material for this renderer- Parameters:
postShadowMat
- the desired Material (alias created)
-
setEdgeFilteringMode
Sets the filtering mode for shadow edges. SeeEdgeFilteringMode
for more info.- Parameters:
filterMode
- the desired filtering mode (not null)
-
getEdgeFilteringMode
returns the edge filtering mode- Returns:
- the enum value
- See Also:
-
setShadowCompareMode
Sets the shadow compare mode. SeeCompareMode
for more info.- Parameters:
compareMode
- the desired compare mode (not null)
-
getShadowCompareMode
returns the shadow compare mode- Returns:
- the shadowCompareMode
- See Also:
-
createFrustum
debug function to create a visible frustum- Parameters:
pts
- optional storage for vertex positions (may be null)i
- the index of the desired wire color (default=White)- Returns:
- a new Geometry
-
initialize
Initialize this shadow renderer prior to its first update.- Specified by:
initialize
in interfaceSceneProcessor
- Parameters:
rm
- the render managervp
- the viewport
-
initFrustumCam
protected abstract void initFrustumCam()delegates the initialization of the frustum cam to child renderers -
isInitialized
public boolean isInitialized()Test whether this shadow renderer has been initialized.- Specified by:
isInitialized
in interfaceSceneProcessor
- Returns:
- true if initialized, otherwise false
-
updateShadowCams
Invoked once per frame to update the shadow cams according to the light view.- Parameters:
viewCam
- the scene cam
-
getOccludersToRender
protected abstract GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) Returns a subclass-specific geometryList containing the occluders to be rendered in the shadow map- Parameters:
shadowMapIndex
- the index of the shadow map being renderedshadowMapOccluders
- the list of occluders- Returns:
- the geometryList
-
getShadowCam
return the shadow camera to use for rendering the shadow map according the given index- Parameters:
shadowMapIndex
- the index of the shadow map being rendered- Returns:
- the shadowCam
-
doDisplayFrustumDebug
protected void doDisplayFrustumDebug(int shadowMapIndex) responsible for displaying the frustum of the shadow cam for debug purpose- Parameters:
shadowMapIndex
- the index of the shadow map
-
postQueue
Description copied from interface:SceneProcessor
Called after the scene graph has been queued, but before it is flushed.- Specified by:
postQueue
in interfaceSceneProcessor
- Parameters:
rq
- The render queue
-
renderShadowMap
protected void renderShadowMap(int shadowMapIndex) -
displayFrustum
public void displayFrustum() -
displayShadowMap
For debugging purposes, display depth shadow maps.- Parameters:
r
- ignored
-
displayDebug
public void displayDebug()For debugging purposes, "snapshot" the current frustum to the scene. -
getReceivers
-
postFrame
Description copied from interface:SceneProcessor
Called after a frame has been rendered and the queue flushed.- Specified by:
postFrame
in 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 need to clear on the post material.- 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 -
getShadowZExtend
public float getShadowZExtend()How far the shadows are rendered in the view- Returns:
- shadowZExtend
- See Also:
-
setShadowZExtend
public void setShadowZExtend(float zFar) Set the distance from the eye where the shadows will be rendered default value is dynamically computed to the shadow casters/receivers union bound zFar, capped to view frustum far value.- Parameters:
zFar
- the zFar values that override the computed one
-
setShadowZFadeLength
public void setShadowZFadeLength(float length) Define the length over which the shadow will fade out when using a shadowZextend This is useful to make dynamic shadows fade into baked shadows in the distance.- Parameters:
length
- the fade length in world units
-
getShadowZFadeLength
public float getShadowZFadeLength()get the length over which the shadow will fade out when using a shadowZextend- Returns:
- the fade length in world units
-
checkCulling
- Parameters:
viewCam
- a Camera to define the view frustum- Returns:
- true if the light source bounding box is in the view frustum
-
preFrame
public void preFrame(float tpf) Description copied from interface:SceneProcessor
Called before a frame- Specified by:
preFrame
in interfaceSceneProcessor
- Parameters:
tpf
- Time per frame
-
cleanup
public void cleanup()Description copied from interface:SceneProcessor
Called when the SP is removed from the RM.- Specified by:
cleanup
in interfaceSceneProcessor
-
reshape
Description copied from interface:SceneProcessor
Called when the resolution of the viewport has been changed.- Specified by:
reshape
in interfaceSceneProcessor
- Parameters:
vp
- the affected ViewPortw
- the new width (in pixels)h
- the new height (in pixels)
-
getShadowIntensity
public float getShadowIntensity()Returns the shadow intensity.- Returns:
- shadowIntensity
- See Also:
-
setShadowIntensity
public final void setShadowIntensity(float shadowIntensity) Set the shadowIntensity. The value should be between 0 and 1. A 0 value gives a bright and invisible shadow, a 1 value gives a pitch black shadow. The default is 0.7- Parameters:
shadowIntensity
- the darkness of the shadow
-
getEdgesThickness
public int getEdgesThickness()returns the edges thickness- Returns:
- edgesThickness
- See Also:
-
getNumShadowMaps
public int getNumShadowMaps()Read the number of shadow maps rendered by this renderer.- Returns:
- count
-
getShadowMapSize
public int getShadowMapSize()Read the size of each shadow map rendered by this renderer.- Returns:
- a map's height (which is also its width, in pixels)
-
setEdgesThickness
public void setEdgesThickness(int edgesThickness) Sets the shadow edges thickness. Default is 10. Setting it to lower values can help reduce the jagged effect of shadow edges.- Parameters:
edgesThickness
- the desired thickness (in tenths of a pixel, default=10)
-
isFlushQueues
Deprecated.isFlushQueues does nothing now and is kept only for backward compatibility- Returns:
- false
-
getPreShadowForcedRenderState
returns the pre shadows pass render state. use it to adjust the RenderState parameters of the pre shadow pass. Note that this will be overridden if the preShadow technique in the material has a ForcedRenderState- Returns:
- the pre shadow render state.
-
setRenderBackFacesShadows
public void setRenderBackFacesShadows(boolean renderBackFacesShadows) Set to true if you want back faces shadows on geometries. Note that back faces shadows will be blended over dark lighten areas and may produce overly dark lighting. Also note that setting this parameter will override this parameter for ALL materials in the scene. You can alternatively change this parameter on a single material usingMaterial.setBoolean(String, boolean)
This also will automatically adjust the faceCullMode and the PolyOffset of the pre shadow pass. You can modify them by usinggetPreShadowForcedRenderState()
- Parameters:
renderBackFacesShadows
- true or false.
-
isRenderBackFacesShadows
public boolean isRenderBackFacesShadows()if this processor renders back faces shadows- Returns:
- true if this processor renders back faces shadows
-
jmeClone
Description copied from interface:JmeCloneable
Performs 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:
jmeClone
in interfaceJmeCloneable
- Returns:
- a new instance
-
cloneFields
Description copied from interface:JmeCloneable
Implemented 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:
cloneFields
in 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:SceneProcessor
Sets a profiler Instance for this processor.- Specified by:
setProfiler
in interfaceSceneProcessor
- Parameters:
profiler
- the profiler instance.
-
read
De-serialize this instance, for example when loading from a J3O file.- Specified by:
read
in 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:
write
in interfaceSavable
- Parameters:
ex
- exporter (not null)- Throws:
IOException
- from the exporter
-