This is a fix for @survivor 's Projective Texture Renderer. You can find the original information about his work in this thread:
LINK
You can get the needed files, example usage and such there. Just replace TextureProjectorRenderer.java with this, and the projected texture will be rendered in the proper order depth-wise.
TextureProjectorRenderer.java
[java]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package cGameClient.Renderers;
import com.jme3.material.Material;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.asset.AssetManager;
import com.jme3.bounding.BoundingSphere;
import com.jme3.collision.CollisionResults;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.SceneProcessor;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.OpaqueComparator;
import com.jme3.scene.Geometry;
import com.jme3.texture.FrameBuffer;
import java.util.ArrayList;
import java.util.List;
/**
- A SceneProcessor that renders TextureProjectors, which means it projects
- textures on scene geometry.
*
-
@author survivor
*/
public class TextureProjectorRenderer implements SceneProcessor
{
private RenderManager renderManager;
private ViewPort viewPort;
private Material textureMat, newMat;
private ArrayList<TextureProjector> textureProjectors;
public TextureProjectorRenderer(AssetManager assetManager)
{
newMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
newMat.setColor("Color", new ColorRGBA(0,0,0,1));
textureMat = new Material(assetManager, "MatDefs/Misc/ProjectiveTextureMapping.j3md");
textureProjectors = new ArrayList<TextureProjector>();
renderManager = null;
viewPort = null;
}
/**
-
@return A list of TextureProjectors rendered by this instance.
*/
public List<TextureProjector> getTextureProjectors()
{
return textureProjectors;
}
/**
- Initializes this instance.
-
@see SceneProcessor
*/
@Override
public void initialize(RenderManager rm, ViewPort vp)
{
renderManager = rm;
viewPort = vp;
}
/**
-
@return true, if this instance is initialized, false otherwise.
-
@see SceneProcessor
*/
@Override
public boolean isInitialized()
{
return viewPort != null;
}
/**
- Called before the a frame is rendered.
-
@see SceneProcessor
*/
@Override
public void preFrame(float tpf) {
}
/**
- Called before the render queue is flushed.
-
@see SceneProcessor
*/
@Override
public void postQueue(RenderQueue rq)
{
}
/**
- Renders each TextureProjector with its corresponding material parameters.
- Called after a frame has been rendered.
-
@see SceneProcessor
*/
@Override
public void postFrame(FrameBuffer out)
{
renderManager.getRenderer().setFrameBuffer(out);
for (TextureProjector textureProjector : textureProjectors)
{
float fadeOutDistance = textureProjector.getFallOffDistance();
textureMat.setTexture("ProjectiveMap", textureProjector.getProjectiveTexture());
textureMat.setMatrix4("ProjectorViewProjectionMatrix", textureProjector.getProjectorViewProjectionMatrix());
if (textureProjector.isParallelProjection())
{
textureMat.clearParam("ProjectorLocation");
textureMat.setVector3("ProjectorDirection", textureProjector.getProjectorDirection());
}
else
{
textureMat.clearParam("ProjectorDirection");
textureMat.setVector3("ProjectorLocation", textureProjector.getProjectorLocation());
}
if (fadeOutDistance != Float.MAX_VALUE)
{
textureMat.setFloat("FallOffDistance", textureProjector.getFallOffDistance());
textureMat.setFloat("FallOffPower", textureProjector.getFallOffPower());
}
else
{
textureMat.clearParam("FallOffDistance");
textureMat.clearParam("FallOffPower");
}
renderManager.setForcedMaterial(textureMat);
GeometryList targetGeometryList = textureProjector.getTargetGeometryList();
if (targetGeometryList != null)
{
renderManager.renderGeometryList(targetGeometryList);
}
else
{
renderManager.renderViewPortRaw(viewPort);
}
renderManager.setForcedMaterial(null);
GeometryList reverseTargetGeometryList = textureProjector.getReverseTargetGeometryList();
if (reverseTargetGeometryList!= null) {
renderManager.setForcedMaterial(newMat);
renderManager.renderGeometryList(reverseTargetGeometryList);
renderManager.setForcedMaterial(null);
}
}
}
/**
- Cleans up this instance.
-
@see SceneProcessor
*/
@Override
public void cleanup()
{
}
/**
- Called if the shape of the ViewPort changed.
-
@see SceneProcessor
*/
@Override
public void reshape(ViewPort vp, int w, int h)
{
}
}
[/java]