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
This commit is contained in:
parent
7e43015f3c
commit
01bf1ca843
@ -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,15 +1813,21 @@ public class JoglRenderer implements Renderer {
|
|||||||
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
|
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// R to Texture compare mode
|
if (tex.isNeedCompareModeUpdate()) {
|
||||||
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
|
// R to Texture compare mode
|
||||||
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
|
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
|
||||||
gl.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
|
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
|
||||||
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
|
gl.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
|
||||||
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
|
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 {
|
} 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());
|
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// R to Texture compare mode
|
if(tex.isNeedCompareModeUpdate()){
|
||||||
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
|
// R to Texture compare mode
|
||||||
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
|
||||||
glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||||
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
|
glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||||
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
|
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
|
||||||
} else {
|
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
|
||||||
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
} else {
|
||||||
|
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//restoring default value
|
||||||
|
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
}
|
}
|
||||||
|
tex.compareModeUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user