Fixed 2 issues with shadows :

- Looks like Poly offset behave defferently between ATI and NVIDIA i added a bit of offset to avoid shadow acne for NVIDIA
- Added a flag needCompareModeUpdate in the Texture class to avoid setting it on every frame in the renderer. I changed Lwjgl and Jogl renderer accordingly.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10043 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent 7e43015f3c
commit 01bf1ca843
  1. 2
      engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
  2. 2
      engine/src/core-data/Common/MatDefs/Shadow/PreShadow.j3md
  3. 12
      engine/src/core/com/jme3/texture/Texture.java
  4. 6
      engine/src/jogl/com/jme3/renderer/jogl/JoglRenderer.java
  5. 6
      engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java

@ -192,7 +192,7 @@ MaterialDef Phong Lighting {
FaceCull Off FaceCull Off
DepthTest On DepthTest On
DepthWrite On DepthWrite On
PolyOffset 5 0 PolyOffset 5 3
ColorWrite Off ColorWrite Off
} }

@ -12,7 +12,7 @@ MaterialDef Pre Shadow {
FaceCull Off FaceCull Off
DepthTest On DepthTest On
DepthWrite On DepthWrite On
PolyOffset 5 0 PolyOffset 5 3
ColorWrite Off ColorWrite Off
} }
} }

@ -298,6 +298,7 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable
private MinFilter minificationFilter = MinFilter.BilinearNoMipMaps; private MinFilter minificationFilter = MinFilter.BilinearNoMipMaps;
private MagFilter magnificationFilter = MagFilter.Bilinear; private MagFilter magnificationFilter = MagFilter.Bilinear;
private ShadowCompareMode shadowCompareMode = ShadowCompareMode.Off; private ShadowCompareMode shadowCompareMode = ShadowCompareMode.Off;
private boolean needCompareModeUpdate = false;
private int anisotropicFilter; private int anisotropicFilter;
/** /**
@ -385,6 +386,7 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable
"compareMode can not be null."); "compareMode can not be null.");
} }
this.shadowCompareMode = compareMode; this.shadowCompareMode = compareMode;
needCompareModeUpdate = true;
} }
/** /**
@ -619,4 +621,14 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable
magnificationFilter = capsule.readEnum("magnificationFilter", magnificationFilter = capsule.readEnum("magnificationFilter",
MagFilter.class, MagFilter.Bilinear); MagFilter.class, MagFilter.Bilinear);
} }
public boolean isNeedCompareModeUpdate() {
return needCompareModeUpdate;
}
public void compareModeUpdated() {
this.needCompareModeUpdate = false;
}
} }

@ -1813,6 +1813,7 @@ public class JoglRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
} }
if (tex.isNeedCompareModeUpdate()) {
// R to Texture compare mode // R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
@ -1822,6 +1823,11 @@ public class JoglRenderer implements Renderer {
} else { } else {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
} }
} else {
//restoring default value
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_NONE);
}
tex.compareModeUpdated();
} }
} }

@ -1764,6 +1764,7 @@ public class LwjglRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
} }
if(tex.isNeedCompareModeUpdate()){
// R to Texture compare mode // R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
@ -1773,6 +1774,11 @@ public class LwjglRenderer implements Renderer {
} else { } else {
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
} }
}else{
//restoring default value
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
}
tex.compareModeUpdated();
} }
} }

Loading…
Cancel
Save