Shadows/SSAO and transparency : Removed the AlphaDiscardThreshold attribute from the lighting material. Transparency discarding is now handled by the AlphaFallOff render state (as it should be).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9330 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 8de8bf2d3e
commit 22edb7beb0
  1. 20
      engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
  2. 39
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag
  3. 4
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md
  4. 4
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert
  5. 35
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag
  6. 35
      engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag
  7. 6
      engine/src/core-effects/Common/MatDefs/SSAO/normal.frag
  8. 3
      engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag
  9. 16
      engine/src/core/com/jme3/shadow/PssmShadowRenderer.java
  10. 3
      engine/test-data/Models/Tree/Leaves.j3m

@ -15,9 +15,6 @@ MaterialDef Phong Lighting {
// Output alpha from the diffuse map
Boolean UseAlpha
// Apha threshold for fragment discarding
Float AlphaDiscardThreshold
// Normal map is in BC5/ATI2n/LATC/3Dc compression format
Boolean LATC
@ -160,7 +157,7 @@ MaterialDef Phong Lighting {
SEPARATE_TEXCOORD : SeparateTexCoord
USE_REFLECTION : EnvMap
SPHERE_MAP : SphereMap
SPHERE_MAP : EnvMapAsSphereMap
}
}
@ -174,9 +171,8 @@ MaterialDef Phong Lighting {
WorldViewMatrix
}
Defines {
COLOR_MAP : ColorMap
DISCARD_ALPHA : AlphaDiscardThreshold
Defines {
DIFFUSEMAP : DiffuseMap
}
RenderState {
@ -203,12 +199,11 @@ MaterialDef Phong Lighting {
HARDWARE_SHADOWS : HardwareShadows
FILTER_MODE : FilterMode
PCFEDGE : PCFEdge
DISCARD_ALPHA : AlphaDiscardThreshold
COLOR_MAP : ColorMap
DIFFUSEMAP : DiffuseMap
}
RenderState {
Blend Modulate
Blend Alpha
}
}
@ -225,12 +220,11 @@ MaterialDef Phong Lighting {
HARDWARE_SHADOWS : HardwareShadows
FILTER_MODE : FilterMode
PCFEDGE : PCFEdge
DISCARD_ALPHA : AlphaDiscardThreshold
COLOR_MAP : ColorMap
DIFFUSEMAP : DiffuseMap
}
RenderState {
Blend Modulate
Blend Alpha
}
}

@ -114,31 +114,27 @@ float Shadow_DoPCF(in SHADOWMAP tex, in vec4 projCoord){
return shadow;
}
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
#else
uniform sampler2D m_DiffuseMap;
#endif
uniform float m_AlphaDiscardThreshold;
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
varying vec2 texCoord;
#endif
#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
varying vec2 texCoord;
#endif
void main(){
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
float alpha = texture2D(m_ColorMap,texCoord).a;
#else
float alpha = texture2D(m_DiffuseMap,texCoord).a;
#endif
if(alpha<=m_AlphaDiscardThreshold){
discard;
}
float alpha =1.0;
#ifdef COLOR_MAP
alpha = texture2D(m_ColorMap,texCoord).a;
#endif
#ifdef DIFFUSEMAP
alpha = texture2D(m_DiffuseMap,texCoord).a;
#endif
vec4 shadowPerSplit = vec4(0.0);
shadowPerSplit.x = GETSHADOW(m_ShadowMap0, projCoord0);
shadowPerSplit.y = GETSHADOW(m_ShadowMap1, projCoord1);
@ -151,9 +147,6 @@ void main(){
float shadow = dot(shadowPerSplit, less * more );
shadow = shadow * m_ShadowIntensity + (1.0 - m_ShadowIntensity);
gl_FragColor = vec4(shadow, shadow, shadow, 1.0);
//gl_FragColor = vec4(alpha, alpha, alpha, 1.0);
gl_FragColor = vec4(0.0, 0.0, 0.0, min(1.0 - shadow,alpha));
}

@ -36,7 +36,7 @@ MaterialDef Post Shadow {
}
RenderState {
Blend Modulate
Blend Alpha
}
}
@ -56,7 +56,7 @@ MaterialDef Post Shadow {
}
RenderState {
Blend Modulate
Blend Alpha
}
}

@ -16,7 +16,7 @@ varying float shadowPosition;
varying vec2 texCoord;
attribute vec3 inPosition;
#ifdef DISCARD_ALPHA
#ifdef DIFFUSEMAP) || defined(COLOR_MAP)
attribute vec2 inTexCoord;
#endif
@ -33,7 +33,7 @@ void main(){
// get the vertex in world space
vec4 worldPos = g_WorldMatrix * vec4(inPosition, 1.0);
#ifdef DISCARD_ALPHA
#if defined(DIFFUSEMAP) || defined(COLOR_MAP)
texCoord = inTexCoord;
#endif
// populate the light view matrices array and convert vertex to light viewProj space

@ -120,31 +120,28 @@ float Shadow_DoPCF(in SHADOWMAP tex, in vec4 projCoord){
return shadow;
}
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
#else
uniform sampler2D m_DiffuseMap;
#endif
uniform float m_AlphaDiscardThreshold;
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
varying vec2 texCoord;
#endif
#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
varying vec2 texCoord;
#endif
void main(){
float shadow = 0.0;
float alpha = 1.0;
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
float alpha = texture2D(m_ColorMap,texCoord).a;
#else
float alpha = texture2D(m_DiffuseMap,texCoord).a;
#endif
if(alpha < m_AlphaDiscardThreshold){
discard;
}
#ifdef COLOR_MAP
alpha = texture2D(m_ColorMap,texCoord).a;
#endif
#ifdef DIFFUSEMAP
alpha = texture2D(m_DiffuseMap,texCoord).a;
#endif
if(shadowPosition < m_Splits.x){
shadow = GETSHADOW(m_ShadowMap0, projCoord0);
}else if( shadowPosition < m_Splits.y){
@ -156,6 +153,6 @@ void main(){
}
shadow = shadow * m_ShadowIntensity + (1.0 - m_ShadowIntensity);
outFragColor = vec4(shadow, shadow, shadow, 1.0);
outFragColor = vec4(0.0, 0.0, 0.0, min(1.0 - shadow,alpha));
}

@ -1,27 +1,24 @@
varying vec2 texCoord;
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
#else
uniform sampler2D m_DiffuseMap;
#endif
uniform float m_AlphaDiscardThreshold;
#ifdef COLOR_MAP
uniform sampler2D m_ColorMap;
#endif
#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
#endif
void main(){
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
if (texture2D(m_ColorMap, texCoord).a <= m_AlphaDiscardThreshold){
discard;
}
#else
if (texture2D(m_DiffuseMap, texCoord).a <= m_AlphaDiscardThreshold){
discard;
}
#endif
#endif
float a = 1.0;
#ifdef COLOR_MAP
a = texture2D(m_ColorMap, texCoord).a;
#endif
#ifdef DIFFUSEMAP
a = texture2D(m_DiffuseMap, texCoord).a;
#endif
gl_FragColor = vec4(1.0);
gl_FragColor = vec4(a);
}

@ -11,11 +11,9 @@ void main(void)
{
#ifdef DIFFUSEMAP_ALPHA
if(texture2D(m_DiffuseMap,texCoord).a<m_AlphaDiscardThreshold){
discard;
}
float alpha=texture2D(m_DiffuseMap,texCoord).a;
#endif
gl_FragColor = vec4(normal.xy* 0.5 + 0.5,-normal.z* 0.5 + 0.5, 1.0);
gl_FragColor = vec4(normal.xy* 0.5 + 0.5,-normal.z* 0.5 + 0.5, alpha);
}

@ -57,12 +57,10 @@ vec2 reflection(in vec2 v1,in vec2 v2){
}
//const vec2 vec[4] = vec2[4](vec2(1.0,0.0), vec2(-1.0,0.0), vec2(0.0,1.0), vec2(0.0,-1.0));
void main(){
float result;
//vec2 vec[4] = { vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0) };
vec3 position = getPosition(texCoord);
//optimization, do not calculate AO if depth is 1
if(depthv==1.0){
@ -91,6 +89,5 @@ void main(){
result = 1.0-ao;
gl_FragColor=vec4(result,result,result, 1.0);
//gl_FragColor=vec4(depthv,depthv,depthv, 1.0);
}

@ -142,8 +142,6 @@ public class PssmShadowRenderer implements SceneProcessor {
private Picture[] dispPic;
private Vector3f[] points = new Vector3f[8];
private boolean flushQueues = true;
//render state for post shadow pass
private RenderState state = new RenderState();
// define if the fallback material should be used.
private boolean needsfallBackMaterial = false;
//Name of the post material technique
@ -216,13 +214,7 @@ public class PssmShadowRenderer implements SceneProcessor {
for (int i = 0; i < points.length; i++) {
points[i] = new Vector3f();
}
//initializing render state for post shadow pass (modulade blending and cullmode of for back faces )
state.setBlendMode(RenderState.BlendMode.Modulate);
state.setFaceCullMode(RenderState.FaceCullMode.Off);
state.setDepthWrite(false);
state.setPolyOffset(-0.1f, 0);
}
/**
@ -458,17 +450,15 @@ public class PssmShadowRenderer implements SceneProcessor {
renderManager.setForcedMaterial(postshadowMat);
}
//forcing the post shadow technique and render state
//forcing the post shadow technique
renderManager.setForcedTechnique(postTechniqueName);
renderManager.setForcedRenderState(state);
//rendering the post shadow pass
viewPort.getQueue().renderShadowQueue(ShadowMode.Receive, renderManager, cam, flushQueues);
//resetting renderManager settings
renderManager.setForcedTechnique(null);
renderManager.setForcedMaterial(null);
renderManager.setForcedRenderState(null);
renderManager.setForcedMaterial(null);
renderManager.setCamera(cam, false);
}

@ -4,8 +4,7 @@ Material Leaves : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Models/Tree/Leaves.png
UseAlpha : true
AlphaDiscardThreshold : 0.5
UseAlpha : true
UseMaterialColors : true
Ambient : .5 .5 .5 .5
Diffuse : 0.7 0.7 0.7 1

Loading…
Cancel
Save