/** * Creates a DirectionalLightShadowFilter Shadow Filter 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> * * @param assetManager the application asset manager * @param shadowMapSize the size of the rendered shadowmaps (512,1024,2048, * etc...) * @param nbSplits the number of shadow maps rendered (the more shadow maps * the more quality, the less fps). */ public DirectionalLightShadowFilter(AssetManager assetManager, int shadowMapSize, int nbSplits) { super(assetManager, shadowMapSize, new DirectionalLightShadowRenderer(assetManager, shadowMapSize, nbSplits)); }
/** * Adjust the repartition of the different shadow maps in the shadow extend * usually goes from 0.0 to 1.0 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 a high value give a more logarithmic * repartition resulting in a high quality for near shadows, but the quality * quickly decrease over the extend. the default value is set to 0.65f * (theoretic optimal value). * * @param lambda the lambda value. */ public void setLambda(float lambda) { shadowRenderer.setLambda(lambda); }
/** * Sets the light to use to cast shadows * * @param light a DirectionalLight */ public void setLight(DirectionalLight light) { shadowRenderer.setLight(light); }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("stabilize") && isPressed) { dlsRenderer.setEnabledStabilization(!dlsRenderer.isEnabledStabilization()) ; } } }, "stabilize");
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3); dlsr.setLight(l); dlsr.setLambda(0.55f); dlsr.setShadowIntensity(0.8f); dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest); dlsr.displayDebug(); viewPort.addProcessor(dlsr);
dlsr.setLambda(dlsr.getLambda() + 0.01f); dlsf.setLambda(dlsr.getLambda() + 0.01f); System.out.println("Lambda : " + dlsr.getLambda()); } else if (name.equals("lambdaDown") && keyPressed) { dlsr.setLambda(dlsr.getLambda() - 0.01f); dlsf.setLambda(dlsr.getLambda() - 0.01f); System.out.println("Lambda : " + dlsr.getLambda()); al.setColor(ColorRGBA.White.mult((1 - dlsr.getShadowIntensity()) * 0.2f)); dlsr.displayFrustum(); dlsr.setRenderBackFacesShadows(!dlsr.isRenderBackFacesShadows()); dlsf.setRenderBackFacesShadows(!dlsf.isRenderBackFacesShadows()); dlsr.setEnabledStabilization(!dlsr.isEnabledStabilization()); dlsf.setEnabledStabilization(!dlsf.isEnabledStabilization()); shadowStabilizationText.setText("(b:on/off) Shadow stabilization : " + dlsr.isEnabledStabilization()); if (dlsr.getShadowZExtend() > 0) { dlsr.setShadowZExtend(0); dlsr.setShadowZFadeLength(0); dlsf.setShadowZExtend(0); dlsf.setShadowZFadeLength(0); dlsr.setShadowZExtend(500); dlsr.setShadowZFadeLength(50); dlsf.setShadowZExtend(500); dlsf.setShadowZFadeLength(50);
= new DirectionalLightShadowRenderer(assetManager, 512, 1); dlsr.setLight(light); dlsr.setShadowIntensity(0.4f); viewPort.addProcessor(dlsr); viewPort.addProcessor(fpp);
directionalLight.setColor(ColorRGBA.Blue); directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f)); dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE*2, 4); dlsr.setLight(directionalLight); dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1); sun_renderer.setLight(sun); viewPort.addProcessor(sun_renderer);
/** * returns true if stabilization is enabled * @return */ public boolean isEnabledStabilization() { return shadowRenderer.isEnabledStabilization(); }
/** * returns the lambda parameter * * @see #setLambda(float lambda) * @return lambda */ public float getLambda() { return shadowRenderer.getLambda(); }
/** * Enables the stabilization of the shadow's edges. (default is true) * This prevents shadow edges from flickering when the camera moves. * However it can lead to some shadow quality loss in some particular scenes. * @param stabilize */ public void setEnabledStabilization(boolean stabilize) { shadowRenderer.setEnabledStabilization(stabilize); }
shadowStabilizationText.setText("(b:on/off) Shadow stabilization : " + dlsr.isEnabledStabilization()); shadowStabilizationText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 100, 0); guiNode.attachChild(shadowStabilizationText); shadowZfarText.setText("(n:on/off) Shadow extend to 500 and fade to 50 : " + (dlsr.getShadowZExtend() > 0)); shadowZfarText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 120, 0); guiNode.attachChild(shadowZfarText);
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); ShadowUtil.updateFrustumPoints2(shadowCam, points); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); }
= new DirectionalLightShadowRenderer(assetManager, 2048, 3); dlsr.setLambda(0.55f); dlsr.setShadowIntensity(0.6f); dlsr.setEdgeFilteringMode(EdgeFilteringMode.Bilinear); viewPort.addProcessor(dlsr); dlsr.setLight(dl); dl.setColor(new ColorRGBA(1.0f, 0.94f, 0.8f, 1f).multLocal(1.3f)); dl.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
/** * returns true if stabilization is enabled * @return */ public boolean isEnabledStabilization() { return shadowRenderer.isEnabledStabilization(); }
/** * returns the lambda parameter * * @see #setLambda(float lambda) * @return lambda */ public float getLambda() { return shadowRenderer.getLambda(); }
/** * Enables the stabilization of the shadow's edges. (default is true) * This prevents shadow edges from flickering when the camera moves. * However it can lead to some shadow quality loss in some particular scenes. * @param stabilize */ public void setEnabledStabilization(boolean stabilize) { shadowRenderer.setEnabledStabilization(stabilize); }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); ShadowUtil.updateFrustumPoints2(shadowCam, points); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); }
final DirectionalLightShadowRenderer pssmRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 4); viewPort.addProcessor(pssmRenderer); pssmRenderer.setLight(dl); pssmRenderer.setLambda(0.55f); pssmRenderer.setShadowIntensity(0.55f); pssmRenderer.setShadowCompareMode(com.jme3.shadow.CompareMode.Software); pssmRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);