Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 03:12:32 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)perhaps an opengl bug with color array vs blend enabled state
Pages: [1]
Print
Author Topic: perhaps an opengl bug with color array vs blend enabled state  (Read 469 times)
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« on: 13. September 2010, 11:09:39 pm »

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.

Code:
/**
 * 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();
    }
}

Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 14. September 2010, 08:17:50 am »

I don't know that bug. An as I see, you've used the BleedingBlendingTest to create your test. The BBT demonstrates, that sorting works properly in Xith3D. So I would expect, it also works for your case. Looks like your suspicion is correct. Though this is pretty unexpectional.

Btw. you don't need your startTime and curTime. This is, what gameTime is for. Simply use the provided to convert the gameTime parameter to seconds. You possibly need to start the RenderLoop with mode NANOSECONDS. Anyway, let the engine do this work for you, if it can Wink.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #2 on: 14. September 2010, 02:13:35 pm »

I've scanned the xith engine, and can only find one place that blending is disabled, in the coloring/transparency state unit.  Therefore I do not think the xith engine is doing anything wrong.  The sorting algorithm puts the two ceiling objects first, and then the floor objects, and the ceiling object has a color array.  So it's as if when the "color array" state is disabled after drawing the ceiling object and prior to drawing the floor object, blending gets disabled--it's at this point blending needs to be reset, perhaps?

If the camera is moved to be closer to the ceiling than the floor, then the floor objects are sorted first, and then the ceiling, and everything is transparent.
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #3 on: 17. September 2010, 07:52:54 pm »

I have a fix I'll commit soon.
Logged
Agrv
Administrator
Enjoying the stay
*****
Offline Offline

Posts: 64


View Profile
« Reply #4 on: 03. October 2010, 05:35:49 pm »

Rwb1977, what about the patch that you mentioned? Is is ready?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic