From 662a0151e208ddb632e9aef2cb69cfa135f006d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81my=20Bouquet?= Date: Fri, 12 Aug 2016 20:51:56 +0200 Subject: [PATCH] fixed glsl 1.0 version of the postShadowFilter shader --- .../MatDefs/Shadow/PostShadowFilter.frag | 50 +++++++++---------- .../MatDefs/Shadow/PostShadowFilter.j3md | 2 - 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.frag b/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.frag index b144dca60..3e7cc8eae 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.frag @@ -40,26 +40,22 @@ vec3 getPosition(in float depth, in vec2 uv){ pos = m_ViewProjectionMatrixInverse * pos; return pos.xyz / pos.w; } +#ifndef BACKFACE_SHADOWS + vec3 approximateNormal(in vec4 worldPos,in vec2 texCoord){ + float step = g_ResolutionInverse.x ; + float stepy = g_ResolutionInverse.y ; + float depth2 = texture2D(m_DepthTexture,texCoord + vec2(step,-stepy)).r; + float depth3 = texture2D(m_DepthTexture,texCoord + vec2(-step,-stepy)).r; + vec4 worldPos2 = vec4(getPosition(depth2,texCoord + vec2(step,-stepy)),1.0); + vec4 worldPos3 = vec4(getPosition(depth3,texCoord + vec2(-step,-stepy)),1.0); + + vec3 v1 = (worldPos - worldPos2).xyz; + vec3 v2 = (worldPos3 - worldPos2).xyz; + return normalize(cross(v1, v2)); + } +#endif -vec3 approximateNormal(in vec4 worldPos,in vec2 texCoord){ - float step = g_ResolutionInverse.x ; - float stepy = g_ResolutionInverse.y ; - float depth2 = texture2D(m_DepthTexture,texCoord + vec2(step,-stepy)).r; - float depth3 = texture2D(m_DepthTexture,texCoord + vec2(-step,-stepy)).r; - vec4 worldPos2 = vec4(getPosition(depth2,texCoord + vec2(step,-stepy)),1.0); - vec4 worldPos3 = vec4(getPosition(depth3,texCoord + vec2(-step,-stepy)),1.0); - - vec3 v1 = (worldPos - worldPos2).xyz; - vec3 v2 = (worldPos3 - worldPos2).xyz; - return normalize(cross(v1, v2)); -} - -void main(){ - #if !defined( RENDER_SHADOWS ) - gl_FragColor = texture2D(m_Texture,texCoord); - return; - #endif - +void main(){ float depth = texture2D(m_DepthTexture,texCoord).r; vec4 color = texture2D(m_Texture,texCoord); @@ -72,7 +68,6 @@ void main(){ // get the vertex in world space vec4 worldPos = vec4(getPosition(depth,texCoord),1.0); - vec3 normal = approximateNormal(worldPos, texCoord); vec3 lightDir; #ifdef PSSM @@ -80,14 +75,17 @@ void main(){ #else lightDir = worldPos.xyz - m_LightPos; #endif - float ndotl = dot(normal, lightDir); - if(ndotl > -0.0){ - gl_FragColor = color; - return; - } + + #ifndef BACKFACE_SHADOWS + vec3 normal = approximateNormal(worldPos, texCoord); + float ndotl = dot(normal, lightDir); + if(ndotl > -0.0){ + gl_FragColor = color; + return; + } + #endif #if (!defined(POINTLIGHT) && !defined(PSSM)) - vec3 lightDir = worldPos.xyz - m_LightPos; if( dot(m_LightDir,lightDir) < 0.0){ gl_FragColor = color; return; diff --git a/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md b/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md index ced2f9fdb..c1000f8d3 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md @@ -59,8 +59,6 @@ MaterialDef Post Shadow { FADE : FadeInfo PSSM : Splits POINTLIGHT : LightViewProjectionMatrix5 - //if no shadow map don't render shadows - RENDER_SHADOWS : ShadowMap0 BACKFACE_SHADOWS : BackfaceShadows }