Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.43 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4.  
  5. import com.jme3.asset.AssetManager;
  6. import com.jme3.export.InputCapsule;
  7. import com.jme3.export.JmeExporter;
  8. import com.jme3.export.JmeImporter;
  9. import com.jme3.export.OutputCapsule;
  10. import com.jme3.export.Savable;
  11. import com.jme3.material.Material;
  12. import com.jme3.material.Technique;
  13. import com.jme3.math.ColorRGBA;
  14. import com.jme3.math.Matrix4f;
  15. import com.jme3.math.Vector3f;
  16. import com.jme3.post.SceneProcessor;
  17. import com.jme3.renderer.Camera;
  18. import com.jme3.renderer.Caps;
  19. import com.jme3.renderer.RenderManager;
  20. import com.jme3.renderer.Renderer;
  21. import com.jme3.renderer.ViewPort;
  22. import com.jme3.renderer.queue.GeometryList;
  23. import com.jme3.renderer.queue.OpaqueComparator;
  24. import com.jme3.renderer.queue.RenderQueue;
  25. import com.jme3.renderer.queue.RenderQueue.ShadowMode;
  26. import com.jme3.scene.Geometry;
  27. import com.jme3.scene.Spatial;
  28. import com.jme3.scene.debug.WireFrustum;
  29. import com.jme3.shader.Shader;
  30. import com.jme3.shadow.CompareMode;
  31. import com.jme3.shadow.EdgeFilteringMode;
  32. import com.jme3.texture.FrameBuffer;
  33. import com.jme3.texture.Image.Format;
  34. import com.jme3.texture.Texture.MagFilter;
  35. import com.jme3.texture.Texture.MinFilter;
  36. import com.jme3.texture.Texture.ShadowCompareMode;
  37. import com.jme3.texture.Texture2D;
  38. import com.jme3.ui.Picture;
  39.  
  40. /**
  41.  * abstract shadow renderer that holds commons feature to have for a shadow
  42.  * renderer
  43.  *
  44.  * @author RĂ©my Bouquet aka Nehon
  45.  */
  46. public abstract class MyAbstractShadowRenderer implements SceneProcessor, Savable {
  47.  
  48.     protected int nbShadowMaps = 1;
  49.     protected float shadowMapSize;
  50.     protected float shadowIntensity = 0.7f;
  51.     protected RenderManager renderManager;
  52.     protected ViewPort viewPort;
  53.     protected FrameBuffer[] shadowFB;
  54.     protected Texture2D[] shadowMaps;
  55.     protected Texture2D dummyTex;
  56.     protected Material preshadowMat;
  57.     protected Material postshadowMat;
  58.     protected Matrix4f[] lightViewProjectionsMatrices;
  59.     protected AssetManager assetManager;
  60.     protected boolean debug = false;
  61.     protected float edgesThickness = 1.0f;
  62.     protected EdgeFilteringMode edgeFilteringMode = EdgeFilteringMode.Bilinear;
  63.     protected CompareMode shadowCompareMode = CompareMode.Hardware;
  64.     protected Picture[] dispPic;
  65.     protected boolean flushQueues = true;
  66.     // define if the fallback material should be used.
  67.     protected boolean needsfallBackMaterial = false;
  68.     //Name of the post material technique
  69.     protected String postTechniqueName = "PostShadow";
  70.     //flags to know when to change params in the materials
  71.     //a list of material of the post shadow queue geometries.
  72.     protected List<Material> matCache = new ArrayList<Material>();
  73.     protected GeometryList sceneReceivers;
  74.     protected GeometryList lightReceivers = new GeometryList(new OpaqueComparator());
  75.     protected GeometryList shadowMapOccluders = new GeometryList(new OpaqueComparator());
  76.     private String[] shadowMapStringCache;
  77.     private String[] lightViewStringCache;
  78.  
  79.    
  80.     /**
  81.      * used for serialization
  82.      */
  83.     protected MyAbstractShadowRenderer(){        
  84.     }    
  85.    
  86.     /**
  87.      * Create an abstract shadow renderer, this is to be called in extending
  88.      * classes
  89.      *
  90.      * @param assetManager the application asset manager
  91.      * @param shadowMapSize the size of the rendered shadowmaps (512,1024,2048,
  92.      * etc...)
  93.      * @param nbShadowMaps the number of shadow maps rendered (the more shadow
  94.      * maps the more quality, the less fps).
  95.      */
  96.     protected MyAbstractShadowRenderer(AssetManager assetManager, int shadowMapSize, int nbShadowMaps) {
  97.  
  98.         this.assetManager = assetManager;
  99.         this.nbShadowMaps = nbShadowMaps;
  100.         this.shadowMapSize = shadowMapSize;
  101.         init(assetManager, nbShadowMaps, shadowMapSize);
  102.  
  103.     }
  104.  
  105.     private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize)
  106.     {
  107.         //this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
  108.         this.postshadowMat = new Material(assetManager, "MatDefs/Shadow/PostShadowMS.j3md");
  109.         shadowFB = new FrameBuffer[nbShadowMaps];
  110.         shadowMaps = new Texture2D[nbShadowMaps];
  111.         dispPic = new Picture[nbShadowMaps];
  112.         lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
  113.         shadowMapStringCache = new String[nbShadowMaps];
  114.         lightViewStringCache = new String[nbShadowMaps];
  115.  
  116.         //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
  117.         dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
  118.  
  119.         preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
  120.         postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
  121.  
  122.         for (int i = 0; i < nbShadowMaps; i++)
  123.         {
  124.             lightViewProjectionsMatrices[i] = new Matrix4f();
  125.             shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
  126.             shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
  127.  
  128.             shadowFB[i].setDepthTexture(shadowMaps[i]);
  129.  
  130.             //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
  131.             shadowFB[i].setColorTexture(dummyTex);
  132.             shadowMapStringCache[i] = "ShadowMap" + i;
  133.             lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
  134.  
  135.             postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
  136.  
  137.             //quads for debuging purpose
  138.             dispPic[i] = new Picture("Picture" + i);
  139.             dispPic[i].setTexture(assetManager, shadowMaps[i], false);
  140.         }
  141.  
  142.         setShadowCompareMode(shadowCompareMode);
  143.         setEdgeFilteringMode(edgeFilteringMode);
  144.         setShadowIntensity(shadowIntensity);
  145.     }
  146.  
  147.     /**
  148.      * set the post shadow material for this renderer
  149.      *
  150.      * @param postShadowMat
  151.      */
  152.     protected final void setPostShadowMaterial(Material postShadowMat)
  153.     {
  154.         this.postshadowMat = postShadowMat;
  155.         postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
  156.         for (int i = 0; i < nbShadowMaps; i++)
  157.         {
  158.             postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
  159.         }
  160.         setShadowCompareMode(shadowCompareMode);
  161.         setEdgeFilteringMode(edgeFilteringMode);
  162.         setShadowIntensity(shadowIntensity);
  163.     }
  164.  
  165.     /**
  166.      * Sets the filtering mode for shadow edges see {@link EdgeFilteringMode}
  167.      * for more info
  168.      *
  169.      * @param EdgeFilteringMode
  170.      */
  171.     final public void setEdgeFilteringMode(EdgeFilteringMode filterMode)
  172.     {
  173.         if (filterMode == null)
  174.         {
  175.             throw new NullPointerException();
  176.         }
  177.  
  178.         this.edgeFilteringMode = filterMode;
  179.         postshadowMat.setInt("FilterMode", filterMode.getMaterialParamValue());
  180.         postshadowMat.setFloat("PCFEdge", edgesThickness);
  181.         if (shadowCompareMode == CompareMode.Hardware) {
  182.             for (Texture2D shadowMap : shadowMaps) {
  183.                 if (filterMode == EdgeFilteringMode.Bilinear) {
  184.                     shadowMap.setMagFilter(MagFilter.Bilinear);
  185.                     shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
  186.                 } else {
  187.                     shadowMap.setMagFilter(MagFilter.Nearest);
  188.                     shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  189.                 }
  190.             }
  191.         }
  192.     }
  193.  
  194.     /**
  195.      * returns the the edge filtering mode
  196.      *
  197.      * @see EdgeFilteringMode
  198.      * @return
  199.      */
  200.     public EdgeFilteringMode getEdgeFilteringMode() {
  201.         return edgeFilteringMode;
  202.     }
  203.  
  204.     /**
  205.      * sets the shadow compare mode see {@link CompareMode} for more info
  206.      *
  207.      * @param compareMode
  208.      */
  209.     final public void setShadowCompareMode(CompareMode compareMode) {
  210.         if (compareMode == null) {
  211.             throw new IllegalArgumentException("Shadow compare mode cannot be null");
  212.         }
  213.  
  214.         this.shadowCompareMode = compareMode;
  215.         for (Texture2D shadowMap : shadowMaps) {
  216.             if (compareMode == CompareMode.Hardware) {
  217.                 shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
  218.                 if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
  219.                     shadowMap.setMagFilter(MagFilter.Bilinear);
  220.                     shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
  221.                 } else {
  222.                     shadowMap.setMagFilter(MagFilter.Nearest);
  223.                     shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  224.                 }
  225.             } else {
  226.                 shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
  227.                 shadowMap.setMagFilter(MagFilter.Nearest);
  228.                 shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  229.             }
  230.         }
  231.         postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
  232.     }
  233.  
  234.     /**
  235.      * returns the shadow compare mode
  236.      *
  237.      * @see CompareMode
  238.      * @return the shadowCompareMode
  239.      */
  240.     public CompareMode getShadowCompareMode() {
  241.         return shadowCompareMode;
  242.     }
  243.  
  244.     //debug function that create a displayable frustrum
  245.     protected Geometry createFrustum(Vector3f[] pts, int i) {
  246.         WireFrustum frustum = new WireFrustum(pts);
  247.         Geometry frustumMdl = new Geometry("f", frustum);
  248.         frustumMdl.setCullHint(Spatial.CullHint.Never);
  249.         frustumMdl.setShadowMode(ShadowMode.Off);
  250.         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  251.         mat.getAdditionalRenderState().setWireframe(true);
  252.         frustumMdl.setMaterial(mat);
  253.         switch (i) {
  254.             case 0:
  255.                 frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
  256.                 break;
  257.             case 1:
  258.                 frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
  259.                 break;
  260.             case 2:
  261.                 frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
  262.                 break;
  263.             case 3:
  264.                 frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
  265.                 break;
  266.             default:
  267.                 frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
  268.                 break;
  269.         }
  270.  
  271.         frustumMdl.updateGeometricState();
  272.         return frustumMdl;
  273.     }
  274.  
  275.     public void initialize(RenderManager rm, ViewPort vp) {
  276.         renderManager = rm;
  277.         viewPort = vp;
  278.         //checking for caps to chosse the appropriate post material technique
  279.         if (renderManager.getRenderer().getCaps().contains(Caps.GLSL150)) {
  280.             postTechniqueName = "PostShadow15";
  281.         } else {
  282.             postTechniqueName = "PostShadow";
  283.         }
  284.     }
  285.  
  286.     public boolean isInitialized() {
  287.         return viewPort != null;
  288.     }
  289.  
  290.     /**
  291.      * This mehtod is called once per frame. it is responsible for updating the
  292.      * shadow cams according to the light view.
  293.      *
  294.      * @param viewCam the scene cam
  295.      */
  296.     protected abstract void updateShadowCams(Camera viewCam);
  297.  
  298.     /**
  299.      * this method must return the geomtryList that contains the oclluders to be
  300.      * rendered in the shadow map
  301.      *
  302.      * @param shadowMapIndex the index of the shadow map being rendered
  303.      * @param sceneOccluders the occluders of the whole scene
  304.      * @param sceneReceivers the recievers of the whole scene
  305.      * @return
  306.      */
  307.     protected abstract GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sceneOccluders, GeometryList sceneReceivers, GeometryList shadowMapOccluders);
  308.  
  309.     /**
  310.      * return the shadow camera to use for rendering the shadow map according
  311.      * the given index
  312.      *
  313.      * @param shadowMapIndex the index of the shadow map being rendered
  314.      * @return the shadowCam
  315.      */
  316.     protected abstract Camera getShadowCam(int shadowMapIndex);
  317.  
  318.     /**
  319.      * responsible for displaying the frustum of the shadow cam for debug
  320.      * purpose
  321.      *
  322.      * @param shadowMapIndex
  323.      */
  324.     protected void doDisplayFrustumDebug(int shadowMapIndex) {
  325.     }
  326.  
  327.     @SuppressWarnings("fallthrough")
  328.     public void postQueue(RenderQueue rq)
  329.     {
  330.         GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
  331.         sceneReceivers = rq.getShadowQueueContent(ShadowMode.Receive);
  332.         if (sceneReceivers.size() == 0 || occluders.size() == 0) {
  333.             return;
  334.         }
  335.  
  336.         updateShadowCams(viewPort.getCamera());
  337.  
  338.         Renderer r = renderManager.getRenderer();
  339.         renderManager.setForcedMaterial(preshadowMat);
  340.         renderManager.setForcedTechnique("PreShadow");
  341.  
  342.         for (int shadowMapIndex = 0; shadowMapIndex < nbShadowMaps; shadowMapIndex++) {
  343.  
  344.             if (debugfrustums) {
  345.                 doDisplayFrustumDebug(shadowMapIndex);
  346.             }
  347.             renderShadowMap(shadowMapIndex, occluders, sceneReceivers);
  348.  
  349.         }
  350.  
  351.         debugfrustums = false;
  352.         if (flushQueues) {
  353.             occluders.clear();
  354.         }
  355.         //restore setting for future rendering
  356.         r.setFrameBuffer(viewPort.getOutputFrameBuffer());
  357.         renderManager.setForcedMaterial(null);
  358.         renderManager.setForcedTechnique(null);
  359.         renderManager.setCamera(viewPort.getCamera(), false);
  360.  
  361.     }
  362.  
  363.     protected void renderShadowMap(int shadowMapIndex, GeometryList occluders, GeometryList receivers) {
  364.         shadowMapOccluders = getOccludersToRender(shadowMapIndex, occluders, receivers, shadowMapOccluders);
  365.         Camera shadowCam = getShadowCam(shadowMapIndex);
  366.  
  367.         //saving light view projection matrix for this split            
  368.         lightViewProjectionsMatrices[shadowMapIndex].set(shadowCam.getViewProjectionMatrix());
  369.         renderManager.setCamera(shadowCam, false);
  370.  
  371.         renderManager.getRenderer().setFrameBuffer(shadowFB[shadowMapIndex]);
  372.         renderManager.getRenderer().clearBuffers(false, true, false);
  373.  
  374.         // render shadow casters to shadow map
  375.         viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
  376.     }
  377.     boolean debugfrustums = false;
  378.  
  379.     public void displayFrustum() {
  380.         debugfrustums = true;
  381.     }
  382.  
  383.     //debug only : displays depth shadow maps
  384.     protected void displayShadowMap(Renderer r)
  385.     {
  386.         Camera cam = viewPort.getCamera();
  387.         renderManager.setCamera(cam, true);
  388.         int h = cam.getHeight();
  389.         for (int i = 0; i < dispPic.length; i++)
  390.         {
  391.             dispPic[i].setPosition((128 * i) + (150 + 34 * (i + 1)), h / 20f);
  392.             dispPic[i].setWidth(128);
  393.             dispPic[i].setHeight(128);
  394.             dispPic[i].updateGeometricState();
  395.             renderManager.renderGeometry(dispPic[i]);
  396.         }
  397.         renderManager.setCamera(cam, false);
  398.     }
  399.  
  400.     /**
  401.      * For dubuging purpose Allow to "snapshot" the current frustrum to the
  402.      * scene
  403.      */
  404.     public void displayDebug() {
  405.         debug = true;
  406.     }
  407.  
  408.     abstract GeometryList getReceivers(GeometryList sceneReceivers, GeometryList lightReceivers);
  409.  
  410.     public void postFrame(FrameBuffer out) {
  411.  
  412.         if (debug) {
  413.             displayShadowMap(renderManager.getRenderer());
  414.         }
  415.  
  416.         lightReceivers = getReceivers(sceneReceivers, lightReceivers);
  417.  
  418.         updatePostShadowMatParams(postshadowMat);
  419.        
  420.         if (lightReceivers.size() != 0)
  421.         {
  422.             //setting params to recieving geometry list
  423.             setMatParams();
  424.            
  425.             Camera cam = viewPort.getCamera();
  426.             //some materials in the scene does not have a post shadow technique so we're using the fall back material
  427.             if (needsfallBackMaterial)
  428.             {
  429.                 renderManager.setForcedMaterial(postshadowMat);
  430.             }
  431.  
  432.             //forcing the post shadow technique and render state
  433.             renderManager.setForcedTechnique(postTechniqueName);
  434.  
  435.             //rendering the post shadow pass
  436.             viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
  437.             if (flushQueues) {
  438.                 sceneReceivers.clear();
  439.             }
  440.  
  441.             //resetting renderManager settings
  442.             renderManager.setForcedTechnique(null);
  443.             renderManager.setForcedMaterial(null);
  444.             renderManager.setCamera(cam, false);
  445.            
  446.         }
  447.  
  448.     }
  449.  
  450.     /**
  451.      * This method is called once per frame and is responsible of setting the
  452.      * material parameters than sub class may need to set on the post material
  453.      *
  454.      * @param material the materail to use for the post shadow pass
  455.      */
  456.     protected abstract void setMaterialParameters(Material material);
  457.    
  458.     protected abstract void updatePostShadowMatParams(Material material);
  459.  
  460.     private void setMatParams() {
  461.  
  462.         GeometryList l = viewPort.getQueue().getShadowQueueContent(ShadowMode.Receive);
  463.  
  464.         //iteration throught all the geometries of the list to gather the materials
  465.  
  466.         matCache.clear();
  467.         for (int i = 0; i < l.size(); i++) {
  468.             Material mat = l.get(i).getMaterial();
  469.             //checking if the material has the post technique and adding it to the material cache
  470.             if (mat.getMaterialDef().getTechniqueDef(postTechniqueName) != null) {
  471.                 if (!matCache.contains(mat)) {
  472.                     matCache.add(mat);
  473.                 }
  474.             } else {
  475.                 needsfallBackMaterial = true;
  476.             }
  477.         }
  478.  
  479.         //iterating through the mat cache and setting the parameters
  480.         for (Material mat : matCache) {
  481.  
  482.             mat.setFloat("ShadowMapSize", shadowMapSize);
  483.  
  484.             for (int j = 0; j < nbShadowMaps; j++) {
  485.                 mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
  486.             }
  487.             for (int j = 0; j < nbShadowMaps; j++) {
  488.                 mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
  489.             }
  490.             mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
  491.             mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
  492.             mat.setFloat("PCFEdge", edgesThickness);
  493.             mat.setFloat("ShadowIntensity", shadowIntensity);
  494.  
  495.             setMaterialParameters(mat);
  496.         }
  497.  
  498.         //At least one material of the receiving geoms does not support the post shadow techniques
  499.         //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
  500.         if (needsfallBackMaterial)
  501.         {
  502.             setPostShadowParams();
  503.         }
  504.  
  505.     }
  506.  
  507.     /**
  508.      * for internal use only
  509.      */
  510.     protected void setPostShadowParams() {
  511.         setMaterialParameters(postshadowMat);
  512.         for (int j = 0; j < nbShadowMaps; j++) {
  513.             postshadowMat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
  514.             postshadowMat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
  515.         }
  516.     }
  517.  
  518.     public void preFrame(float tpf) {
  519.     }
  520.  
  521.     public void cleanup() {
  522.     }
  523.  
  524.     public void reshape(ViewPort vp, int w, int h) {
  525.     }
  526.  
  527.     /**
  528.      * returns the shdaow intensity
  529.      *
  530.      * @see #setShadowIntensity(float shadowIntensity)
  531.      * @return shadowIntensity
  532.      */
  533.     public float getShadowIntensity() {
  534.         return shadowIntensity;
  535.     }
  536.  
  537.     /**
  538.      * Set the shadowIntensity, the value should be between 0 and 1, a 0 value
  539.      * gives a bright and invisilble shadow, a 1 value gives a pitch black
  540.      * shadow, default is 0.7
  541.      *
  542.      * @param shadowIntensity the darkness of the shadow
  543.      */
  544.     final public void setShadowIntensity(float shadowIntensity)
  545.     {
  546.         this.shadowIntensity = shadowIntensity;
  547.         postshadowMat.setFloat("ShadowIntensity", shadowIntensity);
  548.     }
  549.  
  550.     /**
  551.      * returns the edges thickness
  552.      *
  553.      * @see #setEdgesThickness(int edgesThickness)
  554.      * @return edgesThickness
  555.      */
  556.     public int getEdgesThickness() {
  557.         return (int) (edgesThickness * 10);
  558.     }
  559.  
  560.     /**
  561.      * Sets the shadow edges thickness. default is 1, setting it to lower values
  562.      * can help to reduce the jagged effect of the shadow edges
  563.      *
  564.      * @param edgesThickness
  565.      */
  566.     public void setEdgesThickness(int edgesThickness) {
  567.         this.edgesThickness = Math.max(1, Math.min(edgesThickness, 10));
  568.         this.edgesThickness *= 0.1f;
  569.         postshadowMat.setFloat("PCFEdge", edgesThickness);
  570.     }
  571.  
  572.     /**
  573.      * returns true if the PssmRenderer flushed the shadow queues
  574.      *
  575.      * @return flushQueues
  576.      */
  577.     public boolean isFlushQueues() {
  578.         return flushQueues;
  579.     }
  580.  
  581.     /**
  582.      * Set this to false if you want to use several PssmRederers to have
  583.      * multiple shadows cast by multiple light sources. Make sure the last
  584.      * PssmRenderer in the stack DO flush the queues, but not the others
  585.      *
  586.      * @param flushQueues
  587.      */
  588.     public void setFlushQueues(boolean flushQueues) {
  589.         this.flushQueues = flushQueues;
  590.     }
  591.  
  592.     public void read(JmeImporter im) throws IOException {
  593.         InputCapsule ic = (InputCapsule) im.getCapsule(this);
  594.         assetManager = im.getAssetManager();
  595.         nbShadowMaps = ic.readInt("nbShadowMaps", 1);
  596.         shadowMapSize = ic.readInt("shadowMapSize", 0);
  597.         shadowIntensity = ic.readFloat("shadowIntensity", 0.7f);
  598.         edgeFilteringMode = ic.readEnum("edgeFilteringMode", EdgeFilteringMode.class, EdgeFilteringMode.Bilinear);
  599.         shadowCompareMode = ic.readEnum("shadowCompareMode", CompareMode.class, CompareMode.Hardware);
  600.         flushQueues = ic.readBoolean("flushQueues", false);
  601.         init(assetManager, nbShadowMaps, (int) shadowMapSize);
  602.         edgesThickness = ic.readFloat("edgesThickness", 1.0f);
  603.         postshadowMat.setFloat("PCFEdge", edgesThickness);
  604.  
  605.     }
  606.  
  607.     public void write(JmeExporter ex) throws IOException {
  608.         OutputCapsule oc = (OutputCapsule) ex.getCapsule(this);
  609.         oc.write(nbShadowMaps, "nbShadowMaps", 1);
  610.         oc.write(shadowMapSize, "shadowMapSize", 0);
  611.         oc.write(shadowIntensity, "shadowIntensity", 0.7f);
  612.         oc.write(edgeFilteringMode, "edgeFilteringMode", EdgeFilteringMode.Bilinear);
  613.         oc.write(shadowCompareMode, "shadowCompareMode", CompareMode.Hardware);
  614.         oc.write(flushQueues, "flushQueues", false);
  615.         oc.write(edgesThickness, "edgesThickness", 1.0f);
  616.     }
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement