Ver código fonte

Made soft particles work with MS anti aliasing

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10508 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om 12 anos atrás
pai
commit
85b3e7e8c5

+ 26 - 0
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

+ 51 - 0
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);  
+}

+ 1 - 0
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        
     }

+ 7 - 2
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());