Hello,
I have a problem with textures! I am using a pass manager that has a RenderPass and a DepthOfFieldRenderPass.
There are 3 boxes each one with the JME picture as texture.
If I develop a test based on the TestDepthOfField example (which uses the create window method) i get the correct DOF effect. However, if i use the createCanvas method and and implementator I get the textures looking as the image in attachment. Besides as i move the camera the textures also move over the box surfaces.
Can anyone help on this issue?
Thanks.
EDIT: if I replace the DOFPAss by the bloom pass I get the result seen in the other picture(bloomproblem.jpg)
Here is my code for the implementator:
...
///////////////////////////////////////////////////////////////////////////////////
public ActionImplementor3(int width, int height) {
super(width, height);
this.displayWidth = width;
this.displayHeight = height;
}
///////////////////////////////////////////////////////////////////////////////////
public void simpleSetup() {
{
changing = new Node("changing TDOI");
rootNode.attachChild(changing);
stable = new Node("stable TDOI");
rootNode.attachChild(stable);
}
setupDisplay();
setupLights();
setupCamera();
setup1stPersonInput();
setupPassManager();
setupTest();
KeyBindingManager.getKeyBindingManager().set("1", KeyInput.KEY_1);
KeyBindingManager.getKeyBindingManager().set("2", KeyInput.KEY_2);
KeyBindingManager.getKeyBindingManager().set("3", KeyInput.KEY_3);
KeyBindingManager.getKeyBindingManager().set("4", KeyInput.KEY_4);
KeyBindingManager.getKeyBindingManager().set("5", KeyInput.KEY_5);
KeyBindingManager.getKeyBindingManager().set("5", KeyInput.KEY_6);
KeyBindingManager.getKeyBindingManager().set("6", KeyInput.KEY_7);
KeyBindingManager.getKeyBindingManager().set("-", KeyInput.KEY_SUBTRACT);
KeyBindingManager.getKeyBindingManager().set("+", KeyInput.KEY_ADD);
KeyBindingManager.getKeyBindingManager().set("twopass_transp", KeyInput.KEY_2);
KeyBindingManager.getKeyBindingManager().set("toggle_shadows",KeyInput.KEY_T);
KeyBindingManager.getKeyBindingManager().set("light_update",KeyInput.KEY_9);
KeyBindingManager.getKeyBindingManager().set("light_location_next", KeyInput.KEY_0);
KeyBindingManager.getKeyBindingManager().set("camera_settings_record", KeyInput.KEY_INSERT);
KeyBindingManager.getKeyBindingManager().set("camera_settings_next", KeyInput.KEY_PGUP);
KeyBindingManager.getKeyBindingManager().set("camera_delete", KeyInput.KEY_DELETE);
KeyBindingManager.getKeyBindingManager().set("camera_home", KeyInput.KEY_HOME);
KeyBindingManager.getKeyBindingManager().set("render_config", KeyInput.KEY_9);
}
///////////////////////////////////////////////////////////////////////////////////
private void setupPassManager() {
pManager = new BasicPassManager();
pManager.clearAll();
RenderPass rootPass = new RenderPass();
rootPass.add( rootNode );
pManager.add( rootPass );
//
// rootNode.updateGeometricState( 0, true );
blurPass = new DepthOfFieldRenderPass( cam, 1 );
blurPass.add( rootNode );
pManager.add( blurPass );
//
//// BloomRenderPass bloomPass = new BloomRenderPass (cam, 4);
//// bloomPass.add( stable );
//// bloomPass.setUseCurrentScene(true);
//// pManager.add( bloomPass );
//
// RenderPass rootPass2 = new RenderPass();
// rootPass2.add( rootNode );
// pManager.add( rootPass2 );
//
}
///////////////////////////////////////////////////////////////////////////////////
protected void cameraPerspective() {
cam.setFrustumPerspective( 45.0f, (float) width / height, 1, 1000 );
cam.setParallelProjection( false );
cam.update();
}
///////////////////////////////////////////////////////////////////////////////////
protected void cameraParallel() {
cam.setParallelProjection( true );
float aspect = (float) displayWidth / displayHeight;
cam.setFrustum( -100, 1000, -50 * aspect, 50 * aspect, -50, 50 );
cam.update();
}
///////////////////////////////////////////////////////////////////////////////////
private void setupDisplay() {
renderer.setBackgroundColor(ColorRGBA.black);
startTime = System.currentTimeMillis() + 5000;
}
///////////////////////////////////////////////////////////////////////////////////
private void setupCamera() {
/** Set up how our camera sees. */
cameraPerspective();
Vector3f loc = new Vector3f( 0.0f, 0.0f, 25.0f );
Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f );
Vector3f up = new Vector3f( 0.0f, 1.0f, 0.0f );
Vector3f dir = new Vector3f( 0.0f, 0f, -1.0f );
/** Move our camera to a correct place and orientation. */
cam.setFrame( loc, left, up, dir );
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Assign the camera to this renderer. */
renderer.setCamera(cam);
}
///////////////////////////////////////////////////////////////////////////////////
protected void setup1stPersonInput() {
if (firstPerson == null) {
firstPerson = new FirstPersonHandler(cam, 300f, (.1f * FastMath.PI));
}
input = firstPerson;
}
///////////////////////////////////////////////////////////////////////////////////
public void lookAtCenter(Renderer renderer) {
BoundingBox bbox = null;
rootNode.updateGeometricState(0f, true);
rootNode.updateModelBound();
BoundingVolume volume = rootNode.getWorldBound();
if (volume instanceof BoundingBox) {
bbox = (BoundingBox)volume;
Vector3f center = bbox.getCenter();
cam.lookAt(center, new Vector3f(0f, 1f, 0f));
cam.setLocation(new Vector3f(center.x + bbox.xExtent, center.y + bbox.yExtent, center.z + bbox.zExtent));
cam.update();
}
}
///////////////////////////////////////////////////////////////////////////////////
public void doUpdate() {
timer.update();
tpf = timer.getTimePerFrame();
if (input.isEnabled()) {
input.update(tpf);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("twopass_transp", false)) {
renderer.getQueue().setTwoPassTransparency(!renderer.getQueue().isTwoPassTransparency());
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("camera_settings_record", false)) {
cameras.addCamera(getCamera());
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("camera_settings_next", false)) {
cameras.nextCamera(renderer);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("camera_delete", false)) {
cameras.deleteCurrent(renderer);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("render_config", false)) {
setupPassManager();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("camera_home", false)) {
lookAtCenter(renderer);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("light_update", false) || (currentLocation == FOLLOWCAMERA)) {
setupLights();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("light_location_next", false)) {
currentLocation++;
if (currentLocation > MAXLOCATIONS) currentLocation = 0;
setupLights();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("1", false)) {
blurPass.setEnabled(!blurPass.isEnabled());
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("2", false)) {
blurPass.setBlurSize(blurPass.getBlurSize() - 0.001f);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("3", false)) {
blurPass.setBlurSize(blurPass.getBlurSize() + 0.001f);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("4", false)) {
zbuffer = ! zbuffer;
//blurPass.setDisplayBuffer(zbuffer);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("6", false)) {
this.cameraParallel();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("7", false)) {
this.cameraPerspective();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("-", false)) {
float throttle = blurPass.getThrottle() - 1 / 200f;
if (throttle < 0)
throttle = 0;
blurPass.setThrottle(throttle);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("+", false)) {
float throttle = blurPass.getThrottle() + 1 / 200f;
blurPass.setThrottle(throttle);
}
rootNode.updateGeometricState(tpf, true);
pManager.updatePasses(tpf);
}
///////////////////////////////////////////////////////////////////////////////////
public void setupLights() {
lightState = getRenderer().createLightState();
lightState.setEnabled(true);
DirectionalLight dl = new DirectionalLight();
dl.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
dl.setDiffuse(new ColorRGBA(0.2f, 0.2f, 0.2f, 1.0f));
dl.setDirection(new Vector3f(1, -0.5f, 1));
dl.setEnabled(true);
lightState.attach(dl);
PointLight pl = new PointLight();
pl.setDiffuse(new ColorRGBA(.3f,.3f,.3f, 6f));
pl.setAmbient(new ColorRGBA(.2f,.2f,.2f, 2f));
pl.setShadowCaster(true);
pl.setEnabled(true);
pl.setLocation(new Vector3f(100,200,100));
lightState.attach(pl);
PointLight pl2 = new PointLight();
pl2.setDiffuse(new ColorRGBA(.4f,.4f,.4f, 6f));
pl2.setShadowCaster(true);
pl2.setEnabled(true);
pl2.setLocation(new Vector3f(-100,0,200));
lightState.attach(pl2);
rootNode.setRenderState(lightState);
}
....
///////////////////////////////////////////////////////////////////////////////////
private Box getBox( final String name ) {
Box node = new Box( name, Vector3f.UNIT_XYZ.clone().mult( 10 ).negateLocal(), Vector3f.UNIT_XYZ.clone().mult( 10 ) );
TextureState ts = getRenderer().createTextureState();
ts.setEnabled( true );
ts.setTexture( TextureManager.loadTexture(
RenderBlurAndTransparent.class.getClassLoader().getResource( "jmetest/data/images/Monkey.jpg" ),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear ) );
node.setRenderState( ts );
MaterialState ms = getRenderer().createMaterialState();
ms.setDiffuse(new ColorRGBA(1f, 0f, 1f, 0.5f));
ms.setEnabled(true);
node.setRenderState( ms );
return node;
}
///////////////////////////////////////////////////////////////////////////////////
public void setupTest() {
{
box[0] = getBox( "box1" );
box[0].getLocalTranslation().set( -25, -15, -20 );
box[0].setUserData("blur", new BlurAmount(.2f));
}
{
box[1] = getBox( "box2" );
box[1].getLocalTranslation().set( -26, -16, -60 );
}
{
box[2] = getBox( "box3" );
box[2].getLocalTranslation().set( -27, -17, -100 );
box[2].setUserData("blur", new BlurAmount(.7f));
}
{
changing.attachChild( box[0]);
stable.attachChild( box[1]);
changing.attachChild( box[2]);
}
rootNode.updateGeometricState( 0, true );
}
///////////////////////////////////////////////////////////////////////////////////
public void doRender() {
// Clears the previously rendered information.
renderer.clearBuffers();
// Execute renderQueue item
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute();
pManager.renderPasses(renderer);
Debugger.drawBounds( rootNode, renderer, true );
Debugger.drawNormals( rootNode, renderer );
Debugger.drawTangents( rootNode, renderer );
renderer.displayBackBuffer();
}