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. 20
      engine/src/jogl/com/jme3/renderer/jogl/JoglRenderer.java
  5. 22
      engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java

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

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

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

@ -1813,15 +1813,21 @@ public class JoglRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
}
// R to Texture compare mode
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_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
if (tex.isNeedCompareModeUpdate()) {
// R to Texture compare mode
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_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
} else {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
}
} else {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
//restoring default value
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_NONE);
}
tex.compareModeUpdated();
}
}

@ -1764,15 +1764,21 @@ public class LwjglRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
}
// R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
} else {
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
if(tex.isNeedCompareModeUpdate()){
// R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
} else {
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