Draw order changes strangely as camera moves?

霸气de小男生 提交于 2019-12-13 05:06:57

问题


I am currently developing a 3D gui system in libgdx, with the goal of making a library useful for anyone who wants true 3d interfaces in their application. (that is, an interface constructed from model-instances)

This means in a lot of cases there will be transparent objects overlapping.

For example, a label object in a container. The label has a distance field shader (working nicely) and the container a outlined rectangle shader (working nicely). Both shaders have a transparent, or semi-transparent background. The label is slightly in front of that container, and linked to its position/movements (also working nicely).

However, depending where the camera is positioned the labels background goes from correctly transparent, to masking out the background. I assume this is some draw order issue?

Please see the video below to see how it relates to the camera motion;

http://youtu.be/3aADY3_vjV4 (updated video - more clearly shows transparency's)

(apologies for posting a video not a image, but I think it shows better how the problem changes based on movement)

I first move the camera around and you can see the order changing based on position. Seems to be about half way across the screen in changes. I also turn the camera sideways a bit near the end so you can see the label (distance field shader) is above the containers (rectangle shader)

The materials both have a blend attribute set like this;

Material material = new Material(ICON_MATERIAL,
            new GlowingSquareShader.GlowingSquareAttribute(1f,DefaultColour,Color.WHITE),
            new BlendingAttribute(true,GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA,1.0f));

My modelbatch is just using the default sort;

modelBatch = new ModelBatch(myshaderprovider);

(the sort this constructor then uses is; https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/utils/DefaultRenderableSorter.java - this isn't editable by me, but I can override and implement my own sort/compare if needed)

And my shaders setup the following in their begin methods;

context.setBlending(true,GL20.GL_SRC_ALPHA ,GL20.GL_ONE_MINUS_SRC_ALPHA);
context.setDepthTest(GL20.GL_LESS); 

Is this all correct? What other areas could be going wrong?

Or is this an expected limitation of DefaultRenderableSorter.java? (that is, that transparent planes close together wont sort correctly)

来源:https://stackoverflow.com/questions/31973600/draw-order-changes-strangely-as-camera-moves

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!