Explorar o código

Fix RenderState Parameters Leaking Between Renders (#2130)

* debugging shadows

* fixed directional and point shadows

* use mergedRenderState instance

* removed test class
codex hai 1 ano
pai
achega
8fb016cc3e

+ 3 - 2
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -892,11 +892,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
 
     private void updateRenderState(Geometry geometry, RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) {
         if (renderManager.getForcedRenderState() != null) {
-            mergedRenderState.set(renderManager.getForcedRenderState());
+            mergedRenderState.copyFrom(renderManager.getForcedRenderState());
         } else if (techniqueDef.getRenderState() != null) {
-            // copyMergedTo writes to mergedRenderState
+            mergedRenderState.copyFrom(RenderState.DEFAULT);
             techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState);
         } else {
+            mergedRenderState.copyFrom(RenderState.DEFAULT);
             RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState);
         }
         // test if the face cull mode should be flipped before render

+ 50 - 0
jme3-core/src/main/java/com/jme3/material/RenderState.java

@@ -1685,6 +1685,56 @@ public class RenderState implements Cloneable, Savable {
         sfactorAlpha = state.sfactorAlpha;
         dfactorAlpha = state.dfactorAlpha;
     }
+    
+    /**
+     * Copy all values from the given state to this state.
+     * <p>
+     * This method is more precise than {@link #set(com.jme3.material.RenderState)}.
+     * @param state state to copy from
+     */
+    public void copyFrom(RenderState state) {
+        this.applyBlendMode = state.applyBlendMode;
+        this.applyColorWrite = state.applyColorWrite;
+        this.applyCullMode = state.applyCullMode;
+        this.applyDepthFunc = state.applyDepthFunc;
+        this.applyDepthTest = state.applyDepthTest;
+        this.applyDepthWrite = state.applyDepthWrite;
+        this.applyLineWidth = state.applyLineWidth;
+        this.applyPolyOffset = state.applyPolyOffset;
+        this.applyStencilTest = state.applyStencilTest;
+        this.applyWireFrame = state.applyWireFrame;
+        this.backStencilDepthFailOperation = state.backStencilDepthFailOperation;
+        this.backStencilDepthPassOperation = state.backStencilDepthPassOperation;
+        this.backStencilFunction = state.backStencilFunction;
+        this.backStencilMask = state.backStencilMask;
+        this.backStencilReference = state.backStencilReference;
+        this.backStencilStencilFailOperation = state.backStencilStencilFailOperation;
+        this.blendEquation = state.blendEquation;
+        this.blendEquationAlpha = state.blendEquationAlpha;
+        this.blendMode = state.blendMode;
+        this.cachedHashCode = state.cachedHashCode;
+        this.colorWrite = state.colorWrite;
+        this.cullMode = state.cullMode;
+        this.depthFunc = state.depthFunc;
+        this.depthTest = state.depthTest;
+        this.depthWrite = state.depthWrite;
+        this.dfactorAlpha = state.dfactorAlpha;
+        this.dfactorRGB = state.dfactorRGB;
+        this.frontStencilDepthFailOperation = state.frontStencilDepthFailOperation;
+        this.frontStencilDepthPassOperation = state.frontStencilDepthPassOperation;
+        this.frontStencilFunction = state.frontStencilFunction;
+        this.frontStencilMask = state.frontStencilMask;
+        this.frontStencilReference = state.frontStencilReference;
+        this.frontStencilStencilFailOperation = state.frontStencilStencilFailOperation;
+        this.lineWidth = state.lineWidth;
+        this.offsetEnabled = state.offsetEnabled;
+        this.offsetFactor = state.offsetFactor;
+        this.offsetUnits = state.offsetUnits;
+        this.sfactorAlpha = state.sfactorAlpha;
+        this.sfactorRGB = state.sfactorRGB;
+        this.stencilTest = state.stencilTest;
+        this.wireframe = state.wireframe;
+    }
 
     @Override
     public String toString() {

+ 2 - 2
jme3-examples/src/main/java/jme3test/light/TestSpotLightShadows.java

@@ -99,7 +99,7 @@ public class TestSpotLightShadows extends SimpleApplication {
 
         final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
         slsr.setLight(spot);       
-        slsr.setShadowIntensity(0.5f);
+        slsr.setShadowIntensity(.7f);
         slsr.setShadowZExtend(100);
         slsr.setShadowZFadeLength(5);
         slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);   
@@ -107,7 +107,7 @@ public class TestSpotLightShadows extends SimpleApplication {
 
         SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
         slsf.setLight(spot);    
-        slsf.setShadowIntensity(0.5f);
+        slsf.setShadowIntensity(.7f);
         slsf.setShadowZExtend(100);
         slsf.setShadowZFadeLength(5);
         slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);