PssmShadowRenderer.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
  3. * <p/>
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * <p/>
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * <p/>
  14. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. * <p/>
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. package com.jme3.shadow;
  31. import com.jme3.asset.AssetManager;
  32. import com.jme3.material.Material;
  33. import com.jme3.material.RenderState;
  34. import com.jme3.math.ColorRGBA;
  35. import com.jme3.math.Matrix4f;
  36. import com.jme3.math.Vector3f;
  37. import com.jme3.post.SceneProcessor;
  38. import com.jme3.renderer.Camera;
  39. import com.jme3.renderer.Caps;
  40. import com.jme3.renderer.RenderManager;
  41. import com.jme3.renderer.Renderer;
  42. import com.jme3.renderer.ViewPort;
  43. import com.jme3.renderer.queue.GeometryList;
  44. import com.jme3.renderer.queue.OpaqueComparator;
  45. import com.jme3.renderer.queue.RenderQueue;
  46. import com.jme3.renderer.queue.RenderQueue.ShadowMode;
  47. import com.jme3.scene.Geometry;
  48. import com.jme3.scene.Spatial;
  49. import com.jme3.scene.debug.WireFrustum;
  50. import com.jme3.texture.FrameBuffer;
  51. import com.jme3.texture.Image.Format;
  52. import com.jme3.texture.Texture.MagFilter;
  53. import com.jme3.texture.Texture.MinFilter;
  54. import com.jme3.texture.Texture.ShadowCompareMode;
  55. import com.jme3.texture.Texture2D;
  56. import com.jme3.ui.Picture;
  57. /**
  58. * PssmShadow renderer use Parrallel Split Shadow Mapping technique (pssm)<br>
  59. * It splits the view frustum in several parts and compute a shadow map for each
  60. * one.<br> splits are distributed so that the closer they are from the camera,
  61. * the smaller they are to maximize the resolution used of the shadow map.<br>
  62. * This result in a better quality shadow than standard shadow mapping.<br> for
  63. * more informations on this read this
  64. * <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html</a><br>
  65. * <p/>
  66. * @author Rémy Bouquet aka Nehon
  67. */
  68. public class PssmShadowRenderer implements SceneProcessor {
  69. /**
  70. * <code>FilterMode</code> specifies how shadows are filtered
  71. */
  72. public enum FilterMode {
  73. /**
  74. * Shadows are not filtered. Nearest sample is used, causing in blocky
  75. * shadows.
  76. */
  77. Nearest,
  78. /**
  79. * Bilinear filtering is used. Has the potential of being hardware
  80. * accelerated on some GPUs
  81. */
  82. Bilinear,
  83. /**
  84. * Dither-based sampling is used, very cheap but can look bad
  85. * at low resolutions.
  86. */
  87. Dither,
  88. /**
  89. * 4x4 percentage-closer filtering is used. Shadows will be smoother
  90. * at the cost of performance
  91. */
  92. PCF4,
  93. /**
  94. * 8x8 percentage-closer filtering is used. Shadows will be smoother
  95. * at the cost of performance
  96. */
  97. PCF8
  98. }
  99. /**
  100. * Specifies the shadow comparison mode
  101. */
  102. public enum CompareMode {
  103. /**
  104. * Shadow depth comparisons are done by using shader code
  105. */
  106. Software,
  107. /**
  108. * Shadow depth comparisons are done by using the GPU's dedicated
  109. * shadowing pipeline.
  110. */
  111. Hardware;
  112. }
  113. private int nbSplits = 3;
  114. private float lambda = 0.65f;
  115. private float shadowIntensity = 0.7f;
  116. private float zFarOverride = 0;
  117. private RenderManager renderManager;
  118. private ViewPort viewPort;
  119. private FrameBuffer[] shadowFB;
  120. private Texture2D[] shadowMaps;
  121. private Texture2D dummyTex;
  122. private Camera shadowCam;
  123. private Material preshadowMat;
  124. private Material postshadowMat;
  125. private GeometryList splitOccluders = new GeometryList(new OpaqueComparator());
  126. private Matrix4f[] lightViewProjectionsMatrices;
  127. private ColorRGBA splits;
  128. private float[] splitsArray;
  129. private boolean noOccluders = false;
  130. private Vector3f direction = new Vector3f();
  131. private AssetManager assetManager;
  132. private boolean debug = false;
  133. private float edgesThickness = 1.0f;
  134. private FilterMode filterMode;
  135. private CompareMode compareMode;
  136. private Picture[] dispPic;
  137. private Vector3f[] points = new Vector3f[8];
  138. private boolean flushQueues = true;
  139. //render state for post shadow pass
  140. private RenderState state = new RenderState();
  141. // define if the fallback material should be used.
  142. private boolean needsfallBackMaterial = false;
  143. //Name of the post material technique
  144. private String postTechniqueName = "PostShadow";
  145. /**
  146. * Create a PSSM Shadow Renderer
  147. * More info on the technique at <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html</a>
  148. * @param manager the application asset manager
  149. * @param size the size of the rendered shadowmaps (512,1024,2048, etc...)
  150. * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps).
  151. * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps).
  152. */
  153. public PssmShadowRenderer(AssetManager manager, int size, int nbSplits) {
  154. this(manager, size, nbSplits, new Material(manager, "Common/MatDefs/Shadow/PostShadowPSSM.j3md"));
  155. }
  156. /**
  157. * Create a PSSM Shadow Renderer
  158. * More info on the technique at <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html</a>
  159. * @param manager the application asset manager
  160. * @param size the size of the rendered shadowmaps (512,1024,2048, etc...)
  161. * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps).
  162. * @param postShadowMat the material used for post shadows if you need to override it *
  163. */
  164. //TODO remove the postShadowMat when we have shader injection....or remove this todo if we are in 2020.
  165. public PssmShadowRenderer(AssetManager manager, int size, int nbSplits, Material postShadowMat) {
  166. assetManager = manager;
  167. nbSplits = Math.max(Math.min(nbSplits, 4), 1);
  168. this.nbSplits = nbSplits;
  169. shadowFB = new FrameBuffer[nbSplits];
  170. shadowMaps = new Texture2D[nbSplits];
  171. dispPic = new Picture[nbSplits];
  172. lightViewProjectionsMatrices = new Matrix4f[nbSplits];
  173. splits = new ColorRGBA();
  174. splitsArray = new float[nbSplits + 1];
  175. //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
  176. dummyTex = new Texture2D(size, size, Format.RGBA8);
  177. preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md");
  178. this.postshadowMat = postShadowMat;
  179. for (int i = 0; i < nbSplits; i++) {
  180. lightViewProjectionsMatrices[i] = new Matrix4f();
  181. shadowFB[i] = new FrameBuffer(size, size, 1);
  182. shadowMaps[i] = new Texture2D(size, size, Format.Depth);
  183. shadowFB[i].setDepthTexture(shadowMaps[i]);
  184. //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
  185. shadowFB[i].setColorTexture(dummyTex);
  186. postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]);
  187. //quads for debuging purpose
  188. dispPic[i] = new Picture("Picture" + i);
  189. dispPic[i].setTexture(manager, shadowMaps[i], false);
  190. }
  191. setCompareMode(CompareMode.Hardware);
  192. setFilterMode(FilterMode.Bilinear);
  193. setShadowIntensity(0.7f);
  194. shadowCam = new Camera(size, size);
  195. shadowCam.setParallelProjection(true);
  196. for (int i = 0; i < points.length; i++) {
  197. points[i] = new Vector3f();
  198. }
  199. //initializing render state for post shadow pass (modulade blending and cullmode of for back faces )
  200. state.setBlendMode(RenderState.BlendMode.Modulate);
  201. state.setFaceCullMode(RenderState.FaceCullMode.Off);
  202. }
  203. /**
  204. * Sets the filtering mode for shadow edges see {@link FilterMode} for more info
  205. * @param filterMode
  206. */
  207. final public void setFilterMode(FilterMode filterMode) {
  208. if (filterMode == null) {
  209. throw new NullPointerException();
  210. }
  211. if (this.filterMode == filterMode) {
  212. return;
  213. }
  214. this.filterMode = filterMode;
  215. postshadowMat.setInt("FilterMode", filterMode.ordinal());
  216. postshadowMat.setFloat("PCFEdge", edgesThickness);
  217. if (compareMode == CompareMode.Hardware) {
  218. for (Texture2D shadowMap : shadowMaps) {
  219. if (filterMode == FilterMode.Bilinear) {
  220. shadowMap.setMagFilter(MagFilter.Bilinear);
  221. shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
  222. } else {
  223. shadowMap.setMagFilter(MagFilter.Nearest);
  224. shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  225. }
  226. }
  227. }
  228. }
  229. /**
  230. * sets the shadow compare mode see {@link CompareMode} for more info
  231. * @param compareMode
  232. */
  233. final public void setCompareMode(CompareMode compareMode) {
  234. if (compareMode == null) {
  235. throw new NullPointerException();
  236. }
  237. if (this.compareMode == compareMode) {
  238. return;
  239. }
  240. this.compareMode = compareMode;
  241. for (Texture2D shadowMap : shadowMaps) {
  242. if (compareMode == CompareMode.Hardware) {
  243. shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
  244. if (filterMode == FilterMode.Bilinear) {
  245. shadowMap.setMagFilter(MagFilter.Bilinear);
  246. shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
  247. } else {
  248. shadowMap.setMagFilter(MagFilter.Nearest);
  249. shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  250. }
  251. } else {
  252. shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
  253. shadowMap.setMagFilter(MagFilter.Nearest);
  254. shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
  255. }
  256. }
  257. postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
  258. }
  259. //debug function that create a displayable frustrum
  260. private Geometry createFrustum(Vector3f[] pts, int i) {
  261. WireFrustum frustum = new WireFrustum(pts);
  262. Geometry frustumMdl = new Geometry("f", frustum);
  263. frustumMdl.setCullHint(Spatial.CullHint.Never);
  264. frustumMdl.setShadowMode(ShadowMode.Off);
  265. Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  266. mat.getAdditionalRenderState().setWireframe(true);
  267. frustumMdl.setMaterial(mat);
  268. switch (i) {
  269. case 0:
  270. frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
  271. break;
  272. case 1:
  273. frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
  274. break;
  275. case 2:
  276. frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
  277. break;
  278. case 3:
  279. frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
  280. break;
  281. default:
  282. frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
  283. break;
  284. }
  285. frustumMdl.updateGeometricState();
  286. return frustumMdl;
  287. }
  288. public void initialize(RenderManager rm, ViewPort vp) {
  289. renderManager = rm;
  290. viewPort = vp;
  291. //checking for caps to chosse the appropriate post material technique
  292. if (renderManager.getRenderer().getCaps().contains(Caps.GLSL150)) {
  293. postTechniqueName = "PostShadow15";
  294. }else{
  295. postTechniqueName = "PostShadow";
  296. }
  297. }
  298. public boolean isInitialized() {
  299. return viewPort != null;
  300. }
  301. /**
  302. * returns the light direction used by the processor
  303. * @return
  304. */
  305. public Vector3f getDirection() {
  306. return direction;
  307. }
  308. /**
  309. * Sets the light direction to use to compute shadows
  310. * @param direction
  311. */
  312. public void setDirection(Vector3f direction) {
  313. this.direction.set(direction).normalizeLocal();
  314. }
  315. @SuppressWarnings("fallthrough")
  316. public void postQueue(RenderQueue rq) {
  317. GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
  318. if (occluders.size() == 0) {
  319. return;
  320. }
  321. GeometryList receivers = rq.getShadowQueueContent(ShadowMode.Receive);
  322. if (receivers.size() == 0) {
  323. return;
  324. }
  325. Camera viewCam = viewPort.getCamera();
  326. float zFar = zFarOverride;
  327. if (zFar == 0) {
  328. zFar = viewCam.getFrustumFar();
  329. }
  330. //We prevent computing the frustum points and splits with zeroed or negative near clip value
  331. float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
  332. ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
  333. //shadowCam.setDirection(direction);
  334. shadowCam.getRotation().lookAt(direction, shadowCam.getUp());
  335. shadowCam.update();
  336. shadowCam.updateViewProjection();
  337. PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda);
  338. switch (splitsArray.length) {
  339. case 5:
  340. splits.a = splitsArray[4];
  341. case 4:
  342. splits.b = splitsArray[3];
  343. case 3:
  344. splits.g = splitsArray[2];
  345. case 2:
  346. case 1:
  347. splits.r = splitsArray[1];
  348. break;
  349. }
  350. Renderer r = renderManager.getRenderer();
  351. renderManager.setForcedMaterial(preshadowMat);
  352. renderManager.setForcedTechnique("PreShadow");
  353. for (int i = 0; i < nbSplits; i++) {
  354. // update frustum points based on current camera and split
  355. ShadowUtil.updateFrustumPoints(viewCam, splitsArray[i], splitsArray[i + 1], 1.0f, points);
  356. //Updating shadow cam with curent split frustra
  357. ShadowUtil.updateShadowCamera(occluders, receivers, shadowCam, points, splitOccluders);
  358. //saving light view projection matrix for this split
  359. lightViewProjectionsMatrices[i] = shadowCam.getViewProjectionMatrix().clone();
  360. renderManager.setCamera(shadowCam, false);
  361. r.setFrameBuffer(shadowFB[i]);
  362. r.clearBuffers(false, true, false);
  363. // render shadow casters to shadow map
  364. viewPort.getQueue().renderShadowQueue(splitOccluders, renderManager, shadowCam, true);
  365. }
  366. if (flushQueues) {
  367. occluders.clear();
  368. }
  369. //restore setting for future rendering
  370. r.setFrameBuffer(viewPort.getOutputFrameBuffer());
  371. renderManager.setForcedMaterial(null);
  372. renderManager.setForcedTechnique(null);
  373. renderManager.setCamera(viewCam, false);
  374. }
  375. //debug only : displays depth shadow maps
  376. private void displayShadowMap(Renderer r) {
  377. Camera cam = viewPort.getCamera();
  378. renderManager.setCamera(cam, true);
  379. int h = cam.getHeight();
  380. for (int i = 0; i < dispPic.length; i++) {
  381. dispPic[i].setPosition(64 * (i + 1) + 128 * i, h / 20f);
  382. dispPic[i].setWidth(128);
  383. dispPic[i].setHeight(128);
  384. dispPic[i].updateGeometricState();
  385. renderManager.renderGeometry(dispPic[i]);
  386. }
  387. renderManager.setCamera(cam, false);
  388. }
  389. /**For dubuging purpose
  390. * Allow to "snapshot" the current frustrum to the scene
  391. */
  392. public void displayDebug() {
  393. debug = true;
  394. }
  395. public void postFrame(FrameBuffer out) {
  396. Camera cam = viewPort.getCamera();
  397. if (!noOccluders) {
  398. //setting params to recieving geometry list
  399. setMatParams();
  400. //some materials in the scene does not have a post shadow technique so we're using the fall back material
  401. if (needsfallBackMaterial) {
  402. renderManager.setForcedMaterial(postshadowMat);
  403. }
  404. //forcing the post shadow technique and render state
  405. renderManager.setForcedTechnique(postTechniqueName);
  406. renderManager.setForcedRenderState(state);
  407. //rendering the post shadow pass
  408. viewPort.getQueue().renderShadowQueue(ShadowMode.Receive, renderManager, cam, flushQueues);
  409. //resetting renderManager settings
  410. renderManager.setForcedTechnique(null);
  411. renderManager.setForcedMaterial(null);
  412. renderManager.setForcedRenderState(null);
  413. renderManager.setCamera(cam, false);
  414. }
  415. if (debug) {
  416. displayShadowMap(renderManager.getRenderer());
  417. }
  418. }
  419. private void setMatParams() {
  420. GeometryList l = viewPort.getQueue().getShadowQueueContent(ShadowMode.Receive);
  421. //iteratin throught all the geometries of the list to set the material params
  422. for (int i = 0; i < l.size(); i++) {
  423. Material mat = l.get(i).getMaterial();
  424. //checking if the material has the post technique and setting the params.
  425. if (mat.getMaterialDef().getTechniqueDef(postTechniqueName) != null) {
  426. mat.setColor("Splits", splits);
  427. postshadowMat.setColor("Splits", splits);
  428. for (int j = 0; j < nbSplits; j++) {
  429. mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
  430. mat.setTexture("ShadowMap" + j, shadowMaps[j]);
  431. }
  432. mat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
  433. mat.setInt("FilterMode", filterMode.ordinal());
  434. mat.setFloat("PCFEdge", edgesThickness);
  435. mat.setFloat("ShadowIntensity", shadowIntensity);
  436. } else {
  437. needsfallBackMaterial = true;
  438. }
  439. }
  440. //At least one material of the receiving geoms does not support the post shadow techniques
  441. //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
  442. if (needsfallBackMaterial) {
  443. postshadowMat.setColor("Splits", splits);
  444. for (int j = 0; j < nbSplits; j++) {
  445. postshadowMat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
  446. }
  447. }
  448. }
  449. public void preFrame(float tpf) {
  450. }
  451. public void cleanup() {
  452. }
  453. public void reshape(ViewPort vp, int w, int h) {
  454. }
  455. /**
  456. * returns the labda parameter<br>
  457. * see {@link setLambda(float lambda)}
  458. * @return lambda
  459. */
  460. public float getLambda() {
  461. return lambda;
  462. }
  463. /*
  464. * Adjust the repartition of the different shadow maps in the shadow extend
  465. * usualy goes from 0.0 to 1.0
  466. * a low value give a more linear repartition resulting in a constant quality in the shadow over the extends, but near shadows could look very jagged
  467. * a high value give a more logarithmic repartition resulting in a high quality for near shadows, but the quality quickly decrease over the extend.
  468. * the default value is set to 0.65f (theoric optimal value).
  469. * @param lambda the lambda value.
  470. */
  471. public void setLambda(float lambda) {
  472. this.lambda = lambda;
  473. }
  474. /**
  475. * How far the shadows are rendered in the view
  476. * see {@link setShadowZExtend(float zFar)}
  477. * @return shadowZExtend
  478. */
  479. public float getShadowZExtend() {
  480. return zFarOverride;
  481. }
  482. /**
  483. * Set the distance from the eye where the shadows will be rendered
  484. * default value is dynamicaly computed to the shadow casters/receivers union bound zFar, capped to view frustum far value.
  485. * @param zFar the zFar values that override the computed one
  486. */
  487. public void setShadowZExtend(float zFar) {
  488. this.zFarOverride = zFar;
  489. }
  490. /**
  491. * returns the shdaow intensity<br>
  492. * see {@link setShadowIntensity(float shadowIntensity)}
  493. * @return shadowIntensity
  494. */
  495. public float getShadowIntensity() {
  496. return shadowIntensity;
  497. }
  498. /**
  499. * Set the shadowIntensity, the value should be between 0 and 1,
  500. * a 0 value gives a bright and invisilble shadow,
  501. * a 1 value gives a pitch black shadow,
  502. * default is 0.7
  503. * @param shadowIntensity the darkness of the shadow
  504. */
  505. final public void setShadowIntensity(float shadowIntensity) {
  506. this.shadowIntensity = shadowIntensity;
  507. postshadowMat.setFloat("ShadowIntensity", shadowIntensity);
  508. }
  509. /**
  510. * returns the edges thickness <br>
  511. * see {@link setEdgesThickness(int edgesThickness)}
  512. * @return edgesThickness
  513. */
  514. public int getEdgesThickness() {
  515. return (int) (edgesThickness * 10);
  516. }
  517. /**
  518. * Sets the shadow edges thickness. default is 1, setting it to lower values can help to reduce the jagged effect of the shadow edges
  519. * @param edgesThickness
  520. */
  521. public void setEdgesThickness(int edgesThickness) {
  522. this.edgesThickness = Math.max(1, Math.min(edgesThickness, 10));
  523. this.edgesThickness *= 0.1f;
  524. postshadowMat.setFloat("PCFEdge", edgesThickness);
  525. }
  526. /**
  527. * returns true if the PssmRenderer flushed the shadow queues
  528. * @return flushQueues
  529. */
  530. public boolean isFlushQueues() {
  531. return flushQueues;
  532. }
  533. /**
  534. * Set this to false if you want to use several PssmRederers to have multiple shadows cast by multiple light sources.
  535. * Make sure the last PssmRenderer in the stack DO flush the queues, but not the others
  536. * @param flushQueues
  537. */
  538. public void setFlushQueues(boolean flushQueues) {
  539. this.flushQueues = flushQueues;
  540. }
  541. }