- Added a translucent bucket that is rendered after the processors (usefull for shadows) - For filters, rendering this bucket is a bit particular, so you can use the TranslucentBucketFilter to render the translucent bucket in the middle of the fillter stack (doc is comming up in the wiki) - renamed Filter's preRender method to postQueue for consistancy with processors - added translucent objects in TestPostWater, added a fire (particles) in test transparent shadows git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7540 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
29a4e7e01c
commit
2d4896942d
@ -0,0 +1,76 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.post.filters; |
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager; |
||||||
|
import com.jme3.material.Material; |
||||||
|
import com.jme3.math.ColorRGBA; |
||||||
|
import com.jme3.post.Filter; |
||||||
|
import com.jme3.renderer.RenderManager; |
||||||
|
import com.jme3.renderer.Renderer; |
||||||
|
import com.jme3.renderer.ViewPort; |
||||||
|
import com.jme3.renderer.queue.RenderQueue; |
||||||
|
import com.jme3.texture.FrameBuffer; |
||||||
|
import com.jme3.texture.Texture2D; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author Nehon |
||||||
|
*/ |
||||||
|
public final class TranslucentBucketFilter extends Filter { |
||||||
|
|
||||||
|
private RenderManager renderManager; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) { |
||||||
|
this.renderManager = rm; |
||||||
|
material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md"); |
||||||
|
material.setColor("Color", ColorRGBA.White); |
||||||
|
Texture2D tex = processor.getFilterTexture(); |
||||||
|
material.setTexture("Texture", tex); |
||||||
|
if (tex.getImage().getMultiSamples() > 1) { |
||||||
|
material.setInt("NumSamples", tex.getImage().getMultiSamples()); |
||||||
|
} else { |
||||||
|
material.clearParam("NumSamples"); |
||||||
|
} |
||||||
|
renderManager.setHandleTranslucentBucket(false); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Override this method and return false if your Filter does not need the scene texture |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public boolean isRequiresSceneTexture() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) { |
||||||
|
renderManager.setCamera(viewPort.getCamera(), false); |
||||||
|
renderManager.getRenderer().copyFrameBuffer(prevFilterBuffer, sceneBuffer, false); |
||||||
|
renderManager.getRenderer().setFrameBuffer(sceneBuffer); |
||||||
|
viewPort.getQueue().renderQueue(RenderQueue.Bucket.Translucent, renderManager, viewPort.getCamera()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void cleanUpFilter(Renderer r) { |
||||||
|
if (renderManager != null) { |
||||||
|
renderManager.setHandleTranslucentBucket(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Material getMaterial() { |
||||||
|
return material; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setEnabled(boolean enabled) { |
||||||
|
super.setEnabled(enabled); |
||||||
|
if (renderManager != null) { |
||||||
|
renderManager.setHandleTranslucentBucket(!enabled); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue