diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md index 884ff8163..32b1f0ea5 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md @@ -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 } } diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag index fd989c60f..f8d8c2fc7 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag @@ -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)); } diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md index 8b7574838..7151674fb 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md @@ -36,7 +36,7 @@ MaterialDef Post Shadow { } RenderState { - Blend Modulate + Blend Alpha } } @@ -56,7 +56,7 @@ MaterialDef Post Shadow { } RenderState { - Blend Modulate + Blend Alpha } } diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert index c2c8823e3..61bc3aea3 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert @@ -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 diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag index 02ac3f68a..b41f86b77 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag @@ -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)); } diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag index 080666a4e..bb40fc3b5 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag +++ b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag @@ -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); } \ No newline at end of file diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag b/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag index 289c4c031..eda6e1987 100644 --- a/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag +++ b/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag @@ -11,11 +11,9 @@ void main(void) { #ifdef DIFFUSEMAP_ALPHA - if(texture2D(m_DiffuseMap,texCoord).a