I've modified the AmbientLightingTest to exhibit the problem. Notice how the rotating cube "disappears" into the background, just because the other polygon's rendering attributes has the depth write enabled set to false.
/**
* Copyright (c) 2003-2009, Xith3D Project Group all rights reserved.
*
* Portions based on the Java3D interface, Copyright by Sun Microsystems.
* Many thanks to the developers of Java3D and Sun Microsystems for their
* innovation and design.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the 'Xith3D Project Group' nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) A
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE
*/
package org.xith3d.test.lighting;
import org.jagatoo.input.InputSystem;
import org.jagatoo.input.devices.components.Key;
import org.jagatoo.input.events.KeyReleasedEvent;
import org.openmali.vecmath2.Colorf;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loaders.texture.TextureLoader;
import org.xith3d.loop.CanvasFPSListener;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.Canvas3DFactory;
import org.xith3d.resources.ResourceLocator;
import org.xith3d.scenegraph.AmbientLight;
import org.xith3d.scenegraph.Appearance;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.ColoringAttributes;
import org.xith3d.scenegraph.Material;
import org.xith3d.scenegraph.PolygonAttributes;
import org.xith3d.scenegraph.StaticTransform;
import org.xith3d.scenegraph.Texture;
import org.xith3d.scenegraph.Transform3D;
import org.xith3d.scenegraph.TransformGroup;
import org.xith3d.scenegraph.TransparencyAttributes;
import org.xith3d.scenegraph.primitives.Cube;
import org.xith3d.scenegraph.primitives.Rectangle;
import org.xith3d.schedops.movement.RotatableGroup;
import org.xith3d.schedops.movement.TransformationDirectives;
import org.xith3d.test.Xith3DTest;
import org.xith3d.test.util.TestUtils;
import org.xith3d.utility.commandline.BasicApplicationArguments;
import org.xith3d.utility.events.WindowClosingRenderLoopEnder;
@Xith3DTest.Description
(
fulltext = {
"Simple Xith3D Coloring Attributes test"
},
authors = {
"YVG"
}
)
public class AmbientLightingTest2 extends Xith3DTest //InputAdapterRenderLoop
{
private Material mat;
@Override
public void onKeyReleased( KeyReleasedEvent e, Key key )
{
switch ( key.getKeyID() )
{
case SPACE:
mat.setLightingEnabled( !mat.isLightingEnabled() );
break;
case ESCAPE:
this.end();
break;
}
}
private void createSceneGraph( Xith3DEnvironment env ) throws Exception
{
BranchGroup objRoot = new BranchGroup();
RotatableGroup testRotateYGroup = new RotatableGroup( new TransformationDirectives( 0f, 0.1f, 0f ) );
objRoot.addChild( testRotateYGroup );
AmbientLight light = new AmbientLight( true, new Colorf(1,1,.95f));
objRoot.addChild( light );
// Make extra transfrom we may want to play with (scale etc.)
TransformGroup sceneRootTransform = new TransformGroup();
Transform3D t = new Transform3D();
t.setIdentity();
sceneRootTransform.setTransform(t);
testRotateYGroup.addChild( sceneRootTransform );
Texture texture = TextureLoader.getInstance().getTexture( "stone.jpg" );
Texture texture2 = TextureLoader.getInstance().getTexture( "jplogo.png" );
mat = new Material();
mat.setAmbientColor( Colorf.GRAY25 );
mat.setLightingEnabled( true );
Rectangle rect;
Appearance app;
rect = new Rectangle( 0.0f, 0.6f, 0.6f, Colorf.WHITE );
StaticTransform.translate( rect, -0.4f, -0.4f, 0.0f );
app = rect.getAppearance( true );
app.getColoringAttributes( true ).setShadeModel( ColoringAttributes.SHADE_FLAT );
app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
sceneRootTransform.addChild( rect );
rect = new Rectangle( 0.0f, 0.6f, 0.6f, Colorf.RED );
StaticTransform.translate( rect, 0.4f, -0.4f, 0.0f );
app = rect.getAppearance( true );
app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
app.getColoringAttributes( true ).setShadeModel( ColoringAttributes.SHADE_FLAT );
sceneRootTransform.addChild( rect );
rect = new Rectangle( 0.0f, 0.6f, 0.6f, Colorf.GREEN );
StaticTransform.translate( rect, -0.4f, 0.4f, 0.0f );
app = rect.getAppearance( true );
app.getColoringAttributes( true ).setShadeModel( ColoringAttributes.SHADE_FLAT );
app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
sceneRootTransform.addChild( rect );
rect = new Rectangle( 0.0f, 0.6f, 0.6f, Colorf.BLUE );
StaticTransform.translate( rect, 0.4f, 0.4f, 0.0f );
app = rect.getAppearance( true );
app.getColoringAttributes( true ).setShadeModel( ColoringAttributes.SHADE_FLAT );
app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
sceneRootTransform.addChild( rect );
Appearance a = new Appearance();
a.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
a.setTexture( texture );
a.setMaterial( mat );
Cube cube = new Cube( 0.8f, a );
StaticTransform.translate( cube, 0.0f, 0.0f, -0.6f );
sceneRootTransform.addChild( cube );
rect = new Rectangle( 1.0f, 1f, -0.6f, texture2);
StaticTransform.translate( rect, 1f, 1f, 0.0f );
app = rect.getAppearance( true );
app.getColoringAttributes( true ).setShadeModel( ColoringAttributes.SHADE_FLAT );
app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );
app.getRenderingAttributes(true).setDepthBufferWriteEnabled(false);
TransparencyAttributes tra = app.getTransparencyAttributes(true);
tra.setSortEnabled(true);
tra.setTransparency(.4f);
tra.setMode(TransparencyAttributes.BLENDED);
sceneRootTransform.addChild( rect );
env.addPerspectiveBranch( objRoot );
this.getAnimator().addAnimatableObject( testRotateYGroup );
}
public AmbientLightingTest2( BasicApplicationArguments arguments ) throws Throwable
{
super( arguments.getMaxFPS() );
Xith3DEnvironment env = new Xith3DEnvironment( 0f, 0f, 3f,
0f, 0f, 0f,
0f, 1f, 0f,
this
);
ResourceLocator resLoc = TestUtils.createResourceLocator();
resLoc.createAndAddTSL( "textures" );
createSceneGraph(env);
Canvas3D canvas = Canvas3DFactory.create( arguments.getCanvasConstructionInfo(), getClass().getSimpleName() );
canvas.setBackgroundColor(Colorf.RED);
env.addCanvas( canvas );
canvas.addWindowClosingListener( new WindowClosingRenderLoopEnder( this ) );
this.addFPSListener( new CanvasFPSListener( canvas ) );
InputSystem.getInstance().registerNewKeyboardAndMouse( canvas.getPeer() );
System.out.println("Hit SPACE to toggle lights enabled/disabled policy, or ESC to exit");
}
public static void main( String[] args ) throws Throwable
{
AmbientLightingTest2 test = new AmbientLightingTest2( parseCommandLine( args ) );
test.begin();
}
}