|
37 | 37 | import com.jme3.export.JmeImporter; |
38 | 38 | import com.jme3.export.OutputCapsule; |
39 | 39 | import com.jme3.light.DirectionalLight; |
| 40 | +import com.jme3.light.SpotLight; |
40 | 41 | import com.jme3.material.Material; |
41 | 42 | import com.jme3.math.ColorRGBA; |
42 | 43 | import com.jme3.math.Vector2f; |
|
51 | 52 | import java.io.IOException; |
52 | 53 |
|
53 | 54 | /** |
54 | | - * DirectionalLightShadowRenderer renderer use Parallel Split Shadow Mapping |
55 | | - * technique (pssm)<br> It splits the view frustum in several parts and compute |
56 | | - * a shadow map for each one.<br> splits are distributed so that the closer they |
57 | | - * are from the camera, the smaller they are to maximize the resolution used of |
58 | | - * the shadow map.<br> This results in a better quality shadow than standard |
59 | | - * shadow mapping.<br> for more information on this read <a |
60 | | - * href="https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch10.html">https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch10.html</a><br> |
| 55 | + * Implements a shadow renderer specifically for {@link DirectionalLight DirectionalLight} |
| 56 | + * using the **Parallel Split Shadow Mapping (PSSM)** technique. |
61 | 57 | * |
| 58 | + * <p>PSSM divides the camera's view frustum into multiple sections, |
| 59 | + * generating a separate shadow map for each. These splits are |
| 60 | + * intelligently distributed, with smaller, higher-resolution maps for areas |
| 61 | + * closer to the camera and larger, lower-resolution maps for distant areas. |
| 62 | + * This approach optimizes shadow map usage, leading to superior shadow quality |
| 63 | + * compared to standard shadow mapping techniques. |
| 64 | + * |
| 65 | + * <p>For a detailed explanation of PSSM, refer to: |
| 66 | + * <a href="https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch10.html">GPU Gems 3, Chapter 10: Parallel-Split Shadow Maps on Programmable GPUs</a> |
| 67 | + * |
62 | 68 | * @author Nehon |
63 | 69 | */ |
64 | 70 | public class DirectionalLightShadowRenderer extends AbstractShadowRenderer { |
@@ -89,21 +95,24 @@ protected DirectionalLightShadowRenderer() { |
89 | 95 | * Creates a DirectionalLight shadow renderer. This renderer implements the |
90 | 96 | * Parallel Split Shadow Mapping (PSSM) technique. |
91 | 97 | * |
92 | | - * @param assetManager The application's asset manager. |
| 98 | + * @param assetManager The application's asset manager. |
93 | 99 | * @param shadowMapSize The size of the rendered shadow maps (e.g., 512, 1024, 2048). |
94 | | - * @param nbSplits The number of shadow maps to render (1 to 4). More maps |
95 | | - * improve quality but can reduce performance. |
| 100 | + * Higher values produce better quality shadows but may impact performance. |
| 101 | + * @param nbSplits The number of shadow maps to render (1 to 4). More maps |
| 102 | + * improve quality but can reduce performance. |
96 | 103 | */ |
97 | 104 | public DirectionalLightShadowRenderer(AssetManager assetManager, int shadowMapSize, int nbSplits) { |
98 | 105 | super(assetManager, shadowMapSize, nbSplits); |
99 | 106 | init(nbSplits, shadowMapSize); |
100 | 107 | } |
101 | 108 |
|
102 | 109 | private void init(int nbSplits, int shadowMapSize) { |
103 | | - nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1); |
104 | | - if (nbShadowMaps != nbSplits) { |
105 | | - throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits); |
| 110 | + // Ensure the number of shadow maps is within the valid range [1, 4] |
| 111 | + if (nbSplits < 1 || nbSplits > 4) { |
| 112 | + throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value: " + nbSplits); |
106 | 113 | } |
| 114 | + |
| 115 | + nbShadowMaps = nbSplits; |
107 | 116 | splits = new ColorRGBA(); |
108 | 117 | splitsArray = new float[nbSplits + 1]; |
109 | 118 | shadowCam = new Camera(shadowMapSize, shadowMapSize); |
|
0 commit comments