So, here's a bizarre scenario that has been tying me up.
In this test case you will notice that as the camera moves from left to right, that the floor suddenly becomes transparent about 1/2 of the way on its path. The expected behavior is that the two floor objects should always be transparent.
Furthermore, if you comment out the part in the test case that adds color values per vertex to the ceiling object, everything works as expected, all objects are transparent.
It's like the color array is messing with disabling the blend function. The objects drawn *after* the object with the colors are being drawn opaque. (I have sorting enabled).
Has anyone heard of color arrays conflicting with GL_BLEND? The color values even have alpha values.
/**
* Copyright (c) 2003-2010, 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.render;
import org.jagatoo.input.InputSystem;
import org.jagatoo.input.devices.components.Key;
import org.jagatoo.input.events.KeyReleasedEvent;
import org.jagatoo.opengl.enums.DrawMode;
import org.jagatoo.opengl.enums.FaceCullMode;
import org.openmali.vecmath2.Colorf;
import org.openmali.vecmath2.Point3f;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loop.CanvasFPSListener;
import org.xith3d.loop.opscheduler.Animator;
import org.xith3d.loop.opscheduler.Interval;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.Renderer;
import org.xith3d.resources.ResourceLocator;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.Geometry;
import org.xith3d.scenegraph.PolygonAttributes;
import org.xith3d.scenegraph.TransparencyAttributes;
import org.xith3d.scenegraph.View;
import org.xith3d.scenegraph.primitives.Box;
import org.xith3d.scenegraph.primitives.SkySphere;
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 = {
"This test case demonstrates, how a semi-transparent",
"sphere can be rendered in Xith3D.."
},
authors = { "Marvin Froehlich (aka Qudus)" }
)
public class BlendingColorArrayTest extends Xith3DTest //InputAdapterRenderLoop
{
private PolygonAttributes polyAttrs;
@Override
public void onKeyReleased( KeyReleasedEvent e, Key key )
{
switch ( key.getKeyID() )
{
case SPACE:
polyAttrs.setFaceCullMode( FaceCullMode.values()[ (polyAttrs.getFaceCullMode().ordinal() + 1) % FaceCullMode.values().length ] );
break;
case ESCAPE:
this.end();
break;
}
}
private BranchGroup createScene( Animator animator ) throws Exception
{
BranchGroup scene = new BranchGroup();
// Cube background = new Cube( 10.0f, "stone.jpg" );
// scene.addChild( background );
float tval = 0.7f;
TransparencyAttributes ta3 = new TransparencyAttributes( TransparencyAttributes.BLENDED, tval );
Box b3 = new Box(new Point3f(395, 150f, -150), 800, 1f, 800, "jplogo.jpg");
b3.getAppearance( true ).setTransparencyAttributes( ta3 );
b3.getAppearance( true ).setPolygonAttributes( new PolygonAttributes( DrawMode.FILL, FaceCullMode.BACK ));
scene.addChild( b3 );
Box b4 = new Box(new Point3f(395, 140f, -150), 800, 1f, 800, "usa.jpg");
b4.getAppearance( true ).setTransparencyAttributes( ta3 );
b4.getAppearance( true ).setPolygonAttributes( new PolygonAttributes( DrawMode.FILL, FaceCullMode.BACK ));
Box b2 = new Box(new Point3f(395, -4f, -150), 800, 1f, 800, "stone.jpg");
b2.getAppearance( true ).setTransparencyAttributes( ta3 );
b2.getAppearance( true ).setPolygonAttributes( new PolygonAttributes( DrawMode.FILL, FaceCullMode.BACK ));
scene.addChild( b2 );
Box b1 = new Box(new Point3f(395, -20f, -150), 800, 1f, 800, "wood.jpg");
b1.getAppearance( true ).setTransparencyAttributes( ta3 );
b1.getAppearance( true ).setPolygonAttributes( new PolygonAttributes( DrawMode.FILL, FaceCullMode.BACK ));
scene.addChild( b1 );
//* adding colors messes up blending.
Geometry geom = b4.getGeometry();
int numVerts = geom.getVertexCount();
Colorf[]colors = new Colorf[numVerts];
for (int i = 0; i < colors.length; i++)
{
colors[i] = new Colorf(.9f, 1, .9f, 1-tval);
}
geom.setColors(0, colors);
//*/
scene.addChild( b4 );
getOperationScheduler().addInterval( new Interval( 100L )
{
@Override
protected void onIntervalHit( long gameTime, long frameTime, TimingMode timingMode )
{
View view = env.getView();
Point3f pos = view.getPosition();
long curTime = System.nanoTime();
float elapsedSecs = (curTime - startTime)*1e-9f;
float period = 24;
float percent = (float)(1-(.5f*Math.cos(Math.PI*2*(elapsedSecs % period)/period)+.5f));
pos.setX( percent*(900) - 75);
view.setPosition(pos);
}
} );
return ( scene );
}
long startTime = System.nanoTime();
Xith3DEnvironment env;
public BlendingColorArrayTest( BasicApplicationArguments arguments ) throws Throwable
{
super( arguments.getMaxFPS() );
env = new Xith3DEnvironment( this );
ResourceLocator resLoc = TestUtils.createResourceLocator();
env.getRenderer().setTransparentSortingPolicy(Renderer.TransparentSortingPolicy.SORT_BOUNDING_SPHERE_AND_EYE_RAY_INTERSECTION);
resLoc.createAndAddTSL( "textures" );
SkySphere skySphere = new SkySphere("reflectbg.jpg");
env.addRenderPass( skySphere );
env.addPerspectiveBranch( createScene( this.getAnimator() ) );
Canvas3D canvas = createCanvas( arguments.getCanvasConstructionInfo(), getClass().getSimpleName() );
canvas.getRenderOptions().setLightingEnabled(false);
env.addCanvas( canvas );
canvas.addWindowClosingListener( new WindowClosingRenderLoopEnder( this ) );
this.addFPSListener( new CanvasFPSListener( canvas ) );
InputSystem.getInstance().registerNewKeyboardAndMouse( canvas.getPeer() );
}
public static void main( String[] args ) throws Throwable
{
BlendingColorArrayTest test = new BlendingColorArrayTest( parseCommandLine( args ) );
test.begin();
}
}