diff --git a/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md index 07e7f2986..80b45914b 100644 --- a/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md +++ b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md @@ -8,6 +8,7 @@ MaterialDef Point Sprite { //only used for soft particles Texture2D DepthTexture Float Softness + Int NumSamplesDepth // Texture of the glowing parts of the material Texture2D GlowMap @@ -84,6 +85,31 @@ MaterialDef Point Sprite { } } + Technique SoftParticles15{ + + VertexShader GLSL100 : Common/MatDefs/Misc/SoftParticle.vert + FragmentShader GLSL150 : Common/MatDefs/Misc/SoftParticle15.frag + + WorldParameters { + WorldViewProjectionMatrix + WorldViewMatrix + WorldMatrix + CameraPosition + } + + RenderState { + Blend AlphaAdditive + DepthWrite Off + PointSprite On + } + + Defines { + USE_TEXTURE : Texture + POINT_SPRITE : PointSprite + RESOLVE_DEPTH_MS : NumSamplesDepth + } + } + Technique { RenderState { Blend AlphaAdditive diff --git a/engine/src/core-data/Common/MatDefs/Misc/SoftParticle15.frag b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle15.frag new file mode 100644 index 000000000..3e2f0955e --- /dev/null +++ b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle15.frag @@ -0,0 +1,51 @@ +#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/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md b/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md index 74be11ee1..111bdfce0 100644 --- a/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md +++ b/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md @@ -2,6 +2,7 @@ MaterialDef Default GUI { MaterialParameters { Int NumSamples + Int NumSamplesDepth Texture2D Texture Color Color } diff --git a/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java b/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java index b5b76c579..31238cdca 100644 --- a/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java +++ b/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java @@ -165,8 +165,13 @@ public final class TranslucentBucketFilter extends Filter { if (enabled) { enabledSoftParticles = enabled; - emitter.getMaterial().selectTechnique("SoftParticles", renderManager); - emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture()); + 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); logger.log(Level.FINE, "Made particle Emitter {0} soft.", emitter.getName());