@ -1,33 +1,31 @@
/ *
/ *
* Copyright ( c ) 2009 - 2010 jMonkeyEngine
* Copyright ( c ) 2009 - 2010 jMonkeyEngine All rights reserved .
* All rights reserved .
* < p / >
*
* Redistribution and use in source and binary forms , with or without
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are
* modification , are permitted provided that the following conditions are met :
* met :
*
*
* * Redistributions of source code must retain the above copyright notice ,
* * Redistributions of source code must retain the above copyright
* this list of conditions and the following disclaimer .
* notice , this list of conditions and the following disclaimer .
* < p / >
*
* * Redistributions in binary form must reproduce the above copyright
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* documentation and / or other materials provided with the distribution .
*
* < p / >
* * Neither the name of ' jMonkeyEngine ' nor the names of its contributors
* * Neither the name of ' jMonkeyEngine ' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* may be used to endorse or promote products derived from this software
* without specific prior written permission .
* without specific prior written permission .
*
* < p / >
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL ,
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO ,
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* POSSIBILITY OF SUCH DAMAGE .
* /
* /
package com.jme3.shadow ;
package com.jme3.shadow ;
@ -58,11 +56,13 @@ import com.jme3.ui.Picture;
/ * *
/ * *
* PssmShadow renderer use Parrallel Split Shadow Mapping technique ( pssm ) < br >
* PssmShadow renderer use Parrallel Split Shadow Mapping technique ( pssm ) < br >
* It splits the view frustum in several parts and compute a shadow map for each one . < br >
* It splits the view frustum in several parts and compute a shadow map for each
* splits are distributed so that the closer they are from the camera , the smaller they are to maximize the resolution used of the shadow map . < br >
* one . < br > splits are distributed so that the closer they are from the camera ,
* This result in a better quality shadow than standard shadow mapping . < br >
* the smaller they are to maximize the resolution used of the shadow map . < br >
* for more informations on this read this http : //http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html<br>
* This result in a better quality shadow than standard shadow mapping . < br > for
*
* more informations on this read this
* http : //http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html<br>
* < p / >
* @author Rémy Bouquet aka Nehon
* @author Rémy Bouquet aka Nehon
* /
* /
public class PssmShadowRenderer implements SceneProcessor {
public class PssmShadowRenderer implements SceneProcessor {
@ -139,6 +139,7 @@ public class PssmShadowRenderer implements SceneProcessor {
private CompareMode compareMode ;
private CompareMode compareMode ;
private Picture [ ] dispPic ;
private Picture [ ] dispPic ;
private Vector3f [ ] points = new Vector3f [ 8 ] ;
private Vector3f [ ] points = new Vector3f [ 8 ] ;
private boolean flushQueues = true ;
/ * *
/ * *
* Create a PSSM Shadow Renderer
* Create a PSSM Shadow Renderer
@ -382,7 +383,9 @@ public class PssmShadowRenderer implements SceneProcessor {
// render shadow casters to shadow map
// render shadow casters to shadow map
viewPort . getQueue ( ) . renderShadowQueue ( splitOccluders , renderManager , shadowCam , true ) ;
viewPort . getQueue ( ) . renderShadowQueue ( splitOccluders , renderManager , shadowCam , true ) ;
}
}
occluders . clear ( ) ;
if ( flushQueues ) {
occluders . clear ( ) ;
}
//restore setting for future rendering
//restore setting for future rendering
r . setFrameBuffer ( viewPort . getOutputFrameBuffer ( ) ) ;
r . setFrameBuffer ( viewPort . getOutputFrameBuffer ( ) ) ;
renderManager . setForcedMaterial ( null ) ;
renderManager . setForcedMaterial ( null ) ;
@ -390,7 +393,7 @@ public class PssmShadowRenderer implements SceneProcessor {
renderManager . setCamera ( viewCam , false ) ;
renderManager . setCamera ( viewCam , false ) ;
}
}
//debug only : displays depth shadow maps
//debug only : displays depth shadow maps
private void displayShadowMap ( Renderer r ) {
private void displayShadowMap ( Renderer r ) {
Camera cam = viewPort . getCamera ( ) ;
Camera cam = viewPort . getCamera ( ) ;
@ -421,7 +424,9 @@ public class PssmShadowRenderer implements SceneProcessor {
postshadowMat . setMatrix4 ( "LightViewProjectionMatrix" + i , lightViewProjectionsMatrices [ i ] ) ;
postshadowMat . setMatrix4 ( "LightViewProjectionMatrix" + i , lightViewProjectionsMatrices [ i ] ) ;
}
}
renderManager . setForcedMaterial ( postshadowMat ) ;
renderManager . setForcedMaterial ( postshadowMat ) ;
viewPort . getQueue ( ) . renderShadowQueue ( ShadowMode . Receive , renderManager , cam , true ) ;
viewPort . getQueue ( ) . renderShadowQueue ( ShadowMode . Receive , renderManager , cam , flushQueues ) ;
renderManager . setForcedMaterial ( null ) ;
renderManager . setForcedMaterial ( null ) ;
renderManager . setCamera ( cam , false ) ;
renderManager . setCamera ( cam , false ) ;
@ -443,7 +448,7 @@ public class PssmShadowRenderer implements SceneProcessor {
/ * *
/ * *
* returns the labda parameter < br >
* returns the labda parameter < br >
* see { @link setLambda ( float lambda ) }
* see { @link setLambda ( float lambda ) }
* @return
* @return lambda
* /
* /
public float getLambda ( ) {
public float getLambda ( ) {
return lambda ;
return lambda ;
@ -464,7 +469,7 @@ public class PssmShadowRenderer implements SceneProcessor {
/ * *
/ * *
* How far the shadows are rendered in the view
* How far the shadows are rendered in the view
* see { @link setShadowZExtend ( float zFar ) }
* see { @link setShadowZExtend ( float zFar ) }
* @return
* @return shadowZExtend
* /
* /
public float getShadowZExtend ( ) {
public float getShadowZExtend ( ) {
return zFarOverride ;
return zFarOverride ;
@ -482,7 +487,7 @@ public class PssmShadowRenderer implements SceneProcessor {
/ * *
/ * *
* returns the shdaow intensity < br >
* returns the shdaow intensity < br >
* see { @link setShadowIntensity ( float shadowIntensity ) }
* see { @link setShadowIntensity ( float shadowIntensity ) }
* @return
* @return shadowIntensity
* /
* /
public float getShadowIntensity ( ) {
public float getShadowIntensity ( ) {
return shadowIntensity ;
return shadowIntensity ;
@ -503,14 +508,14 @@ public class PssmShadowRenderer implements SceneProcessor {
/ * *
/ * *
* returns the edges thickness < br >
* returns the edges thickness < br >
* see { @link setEdgesThickness ( int edgesThickness ) }
* see { @link setEdgesThickness ( int edgesThickness ) }
* @return
* @return edgesThickness
* /
* /
public int getEdgesThickness ( ) {
public int getEdgesThickness ( ) {
return ( int ) ( edgesThickness * 10 ) ;
return ( int ) ( edgesThickness * 10 ) ;
}
}
/ * *
/ * *
* St es the shadow edges thickness . default is 1 , setting it to lower values can help to reduce the jagged effect of the shadow edges
* Set s the shadow edges thickness . default is 1 , setting it to lower values can help to reduce the jagged effect of the shadow edges
* @param edgesThickness
* @param edgesThickness
* /
* /
public void setEdgesThickness ( int edgesThickness ) {
public void setEdgesThickness ( int edgesThickness ) {
@ -518,4 +523,21 @@ public class PssmShadowRenderer implements SceneProcessor {
this . edgesThickness * = 0 . 1f ;
this . edgesThickness * = 0 . 1f ;
postshadowMat . setFloat ( "PCFEdge" , edgesThickness ) ;
postshadowMat . setFloat ( "PCFEdge" , edgesThickness ) ;
}
}
/ * *
* returns true if the PssmRenderer flushed the shadow queues
* @return flushQueues
* /
public boolean isFlushQueues ( ) {
return flushQueues ;
}
/ * *
* Set this to false if you want to use several PssmRederers to have multiple shadows cast by multiple light sources .
* Make sure the last PssmRenderer in the stack DO flush the queues , but not the others
* @param flushQueues
* /
public void setFlushQueues ( boolean flushQueues ) {
this . flushQueues = flushQueues ;
}
}
}