diff --git a/jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md b/jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md index 1d2ed6fd3..504062ffa 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md @@ -59,10 +59,7 @@ MaterialDef Point Sprite { } Defines { - COLOR_MAP : ColorMap - DISCARD_ALPHA : AlphaDiscardThreshold - NUM_BONES : NumberOfBones - INSTANCING : UseInstancing + COLOR_MAP : Texture } ForcedRenderState { @@ -77,30 +74,8 @@ MaterialDef Point Sprite { Technique SoftParticles{ - VertexShader GLSL100 : Common/MatDefs/Misc/SoftParticle.vert - FragmentShader GLSL100 : Common/MatDefs/Misc/SoftParticle.frag - - WorldParameters { - WorldViewProjectionMatrix - WorldViewMatrix - WorldMatrix - CameraPosition - } - - RenderState { - Blend AlphaAdditive - DepthWrite Off - } - - Defines { - USE_TEXTURE : Texture - } - } - - Technique SoftParticles15{ - - VertexShader GLSL150 : Common/MatDefs/Misc/SoftParticle.vert - FragmentShader GLSL150 : Common/MatDefs/Misc/SoftParticle15.frag + VertexShader GLSL100 GLSL150 : Common/MatDefs/Misc/SoftParticle.vert + FragmentShader GLSL120 GLSL150 : Common/MatDefs/Misc/SoftParticle.frag WorldParameters { WorldViewProjectionMatrix @@ -122,14 +97,6 @@ MaterialDef Point Sprite { } } - Technique { - RenderState { - Blend AlphaAdditive - // DepthWrite Off - // AlphaTestFalloff 0.01 - } - } - Technique Glow { VertexShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert diff --git a/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle.frag b/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle.frag index d3108b54e..0277727f6 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle.frag @@ -1,4 +1,7 @@ -uniform sampler2D m_DepthTexture; +#import "Common/ShaderLib/GLSLCompat.glsllib" +#import "Common/ShaderLib/MultiSample.glsllib" + +uniform DEPTHTEXTURE m_DepthTexture; uniform float m_Softness; // Power used in the contrast function varying vec2 vPos; // Position of the pixel varying vec2 projPos;// z and w valus in projection space @@ -36,15 +39,15 @@ void main(){ #endif - float depthv = texture2D(m_DepthTexture, vPos).x*2.0-1.0; // Scene depth - depthv*=projPos.y; + float depthv = fetchTextureSample(m_DepthTexture, vPos, 0).x * 2.0 - 1.0; // Scene depth + depthv *= projPos.y; float particleDepth = projPos.x; - float zdiff =depthv-particleDepth; - if(zdiff<=0.0){ + float zdiff = depthv - particleDepth; + if(zdiff <= 0.0){ discard; } // Computes alpha based on the particles distance to the rest of the scene c.a = c.a * stdDiff(zdiff);// Contrast(zdiff); - gl_FragColor =c; + gl_FragColor = c; } \ No newline at end of file diff --git a/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle15.frag b/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle15.frag deleted file mode 100644 index 3e2f0955e..000000000 --- a/jme3-core/src/main/resources/Common/MatDefs/Misc/SoftParticle15.frag +++ /dev/null @@ -1,51 +0,0 @@ -#import "Common/ShaderLib/MultiSample.glsllib" - -uniform DEPTHTEXTURE m_DepthTexture; -uniform float m_Softness; // Power used in the contrast function -in vec2 vPos; // Position of the pixel -in vec2 projPos;// z and w valus in projection space - -#ifdef USE_TEXTURE -uniform sampler2D m_Texture; -in vec4 texCoord; -#endif - -in vec4 color; -out vec4 outColor; - -float Contrast(in float d){ - float val = clamp( 2.0*( (d > 0.5) ? 1.0-d : d ), 0.0, 1.0); - float a = 0.5 * pow(val, m_Softness); - return (d > 0.5) ? 1.0 - a : a; -} - -float stdDiff(in float d){ - return clamp((d)*m_Softness,0.0,1.0); -} - - -void main(){ - if (color.a <= 0.01) - discard; - - outColor = vec4(1.0,1.0,1.0,1.0);//color; - #ifdef USE_TEXTURE - #ifdef POINT_SPRITE - vec2 uv = mix(texCoord.xy, texCoord.zw, gl_PointCoord.xy); - #else - vec2 uv = texCoord.xy; - #endif - outColor = getColor(m_Texture, uv) * color; - #endif - - float depthv = getDepth(m_DepthTexture, vPos).x*2.0-1.0; // Scene depth - depthv*=projPos.y; - float particleDepth = projPos.x; - - float zdiff =depthv-particleDepth; - if(zdiff<=0.0){ - discard; - } - // Computes alpha based on the particles distance to the rest of the scene - outColor.a = outColor.a * stdDiff(zdiff);// Contrast(zdiff); -} \ No newline at end of file diff --git a/jme3-effects/src/main/java/com/jme3/post/filters/TranslucentBucketFilter.java b/jme3-effects/src/main/java/com/jme3/post/filters/TranslucentBucketFilter.java index 31238cdca..39c1205e6 100644 --- a/jme3-effects/src/main/java/com/jme3/post/filters/TranslucentBucketFilter.java +++ b/jme3-effects/src/main/java/com/jme3/post/filters/TranslucentBucketFilter.java @@ -165,11 +165,9 @@ public final class TranslucentBucketFilter extends Filter { if (enabled) { enabledSoftParticles = enabled; + emitter.getMaterial().selectTechnique("SoftParticles", renderManager); if( processor.getNumSamples()>1){ - emitter.getMaterial().selectTechnique("SoftParticles15", renderManager); emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples()); - }else{ - emitter.getMaterial().selectTechnique("SoftParticles", renderManager); } emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture()); emitter.setQueueBucket(RenderQueue.Bucket.Translucent); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java b/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java index 71504e51a..84189e1e9 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java @@ -95,6 +95,10 @@ public class TestSoftParticles extends SimpleApplication { fpp = new FilterPostProcessor(assetManager); tbf = new TranslucentBucketFilter(true); fpp.addFilter(tbf); + int samples = context.getSettings().getSamples(); + if (samples > 0) { + fpp.setNumSamples(samples); + } viewPort.addProcessor(fpp); particleNode = new Node("particleNode");