Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3507 Members - Latest Member: PienueDut

26. May 2012, 12:37:34 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)background bleeding through
Pages: [1]
Print
Author Topic: background bleeding through  (Read 943 times)
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« on: 15. October 2009, 07:02:26 pm »

In my scene, if I move the camera so that my main Shapes are in back of the camera, I can see my huge floor object.  However if I turn the camera around, so that I am facing the object in view, bad things happen to the view such that the background bleeds through most all the objects, as if they were transparent.  I'm trying to just use simple ambient lighting too, nothing fancy.  Any ideas what's wrong?  How do I disable culling to see if this is the problem?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 15. October 2009, 09:46:30 pm »

Code:
renderPass.setClipperEnabled( false );

But I don't think, frustum culling is the problem. Could it be, that your huge floor object has alpha blending enabled? This could be, if the texture has an alpa channel and/or the Appearance has TransparencyAttributes with enabled alpha blending. In that case sorting could fail, if your floor object is as huge as you say. In any case your floor shouldn't consist of one big shape, but of several smaller ones, so that they can be effectively culled.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #2 on: 15. October 2009, 11:20:33 pm »

Turning off frustrum culling and clipping did not work as you suspected.

canvas.getRenderer().getRenderPass(0).setClipperEnabled(false);
canvas.getRenderer().getRenderPass(0).setFrustumCullingEnabled(false);

If I just have the floor it the floor is fine by itself.  It's when I load the ASE from a file, and the ASE is in view, then there is a problem.  Even the ASE gets "blended" with the background, or disappears.  While I navigate, the floor and ASE flicker into view as if there is Z fighting going on, but when I stop, they disappear.

The floor does not have coloring attributes, rendering attributes, or transparency attributes, it does have a texture.  The ASE shapes have coloring attributes, no transparency attributes, and textures.

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

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 15. October 2009, 11:59:48 pm »

Could you possibly post the ASE file and testcase?

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #4 on: 16. October 2009, 05:01:03 pm »

I have discovered it's not a problem with the ASE itself, but rather, a quadarray that I add after the ASE is loaded.  The renderingattributes for this are the defaults except the depth buffer *write* is disabled (on purpose).  Could this be the problem?  Or a combination of this with something else, like the transparency?

RenderingAttributes rAttr = new RenderingAttributes();
rAttr.setDepthBufferWriteEnabled(false);

The texture also has alpha, and the appearance also has transparency. Is there something I'm doing wrong here?

Appearance app = new Appearance();
PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
app.setPolygonAttributes(pa);
app.setTexture(tex1);
   
TextureAttributes ta = new TextureAttributes();
ta.setTextureMode(TextureAttributes.MODULATE);

ColoringAttributes colAtt = new ColoringAttributes();
colAtt.setColor(color);

RenderingAttributes rAttr = new RenderingAttributes();
   
rAttr.setDepthBufferWriteEnabled(false);

tra = new TransparencyAttributes();
tra.setMode(TransparencyAttributes.BLENDED);
tra.setTransparency(transLevel);
tra.setSortEnabled(true);
            
app.setTransparencyAttributes(tra);
app.setRenderingAttributes(rAttr);
app.setTextureAttributes(ta);
app.setColoringAttributes(colAtt);
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 16. October 2009, 05:37:59 pm »

Yes, disabling the depth buffer writing could be the problem. You cannot do that without controlling sorting. Please check, if there could be a problem with sorting.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #6 on: 16. October 2009, 06:41:20 pm »

Well, I'm not doing anything special with sorting ... I've set the transparency sorting policy:

canvas.getRenderer().setTransparentSortingPolicy(Renderer.TransparentSortingPolicy.SORT_BOUNDING_SPHERE_AND_EYE_RAY_INTERSECTION);

Are you suggesting that I should not be sorting or that I should be?

By the way, If I enable depth test writing, then all the background "bleeding" issues go away...
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #7 on: 16. October 2009, 08:17:35 pm »

Well, you just need to make sure, that OpenGL is still able to depth test the rendered primitives. So if you disable depth buffer writing, you need to render this primitive last, if it potentially intersects with othe primitives rendered after it.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #8 on: 16. October 2009, 08:41:46 pm »

Hmm... i assumed if I disabled depth buffer writing for one primitive, that the setting only applied to that primitive and it would be set back to what it was after that, so things rendered after it would be rendered ok.  So it doesn't work this way?  Relatedly, does Xith not render all transparent polygons after solid ones?  This is the only transparent polygon, so isn't it rendered last?

If not, how would I ensure it is rendered last?  Another render pass?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #9 on: 16. October 2009, 08:48:47 pm »

Hmm... i assumed if I disabled depth buffer writing for one primitive, that the setting only applied to that primitive and it would be set back to what it was after that, so things rendered after it would be rendered ok.

Yes, you assumed right.

Relatedly, does Xith not render all transparent polygons after solid ones?  This is the only transparent polygon, so isn't it rendered last?

It is rendered last as you assumed. So depth buffer writing shouldn't hurt as long as the primitive doesn't intersect itself. Maybe you can fix it by enabling back side culling.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #10 on: 20. October 2009, 03:10:44 pm »

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.


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

Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #11 on: 22. October 2009, 02:11:20 pm »

Are you able to reproduce the problem/bug with this test?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #12 on: 22. October 2009, 05:31:10 pm »

I will try it out on the weekend.

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

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #13 on: 26. October 2009, 03:40:25 pm »

I found and fixed the bug. The problem was, that depthBufferWriteEnabled wasn't reseted after a frame. So the clear operation wasn't working as it should.

Marvin
Logged
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« Reply #14 on: 28. October 2009, 06:07:59 pm »

Excellent, thank you!  I've updated and it works as expected now.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic