Note that there are some explanatory texts on larger screens.

plurals
  1. POUneven edges and glitches where 3D objects meet
    text
    copied!<p>I'm diving right into my first 3D game by trying to convert a tile based game to a 3D one. I'm using libGDX's new 3D classes to accomplish this. </p> <p>Each block in a tile map will be converted to a 3D object in this case I'm rendering each tile as a box. It works reasonably well but I'm getting graphical errors where boxes share an edge or corner. </p> <p>This seems to work better on the desktop project (It seems to occur sometimes but less severe):</p> <p><img src="https://i.imgur.com/kA1d10D.png" alt="Desktop Rendering"></p> <p>But not on android devices: <img src="https://i.imgur.com/8nKfT6a.png" alt="Android Rendering"></p> <p>This glitching varies depending on where on the screen the block is drawn. This occurs on several different android devices but more noticeable on those with higher screen resolutions.</p> <p>Here is the code I'm using to render it in the main libGDX project:</p> <pre><code> @Override public void create() { modelBatch = new ModelBatch(); instances = new ArrayList&lt;ModelInstance&gt;(); //Setup camera cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 0, 150f); cam.lookAt(0, 0,0); cam.near = 0.1f; cam.far = 500f; cam.update(); //Setup Lighting environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); // Add boxes addBox(new Vector3(-50,0,0)); addBox(new Vector3(-50,16,0)); addBox(new Vector3(-50,32,0)); addBox(new Vector3(-50,48,0)); addBox(new Vector3(50,48,0)); addBox(new Vector3(66,48,0)); addBox(new Vector3(82,48,0)); addBox(new Vector3(98,48,0)); } private void addBox(Vector3 position){ ModelBuilder modelBuilder = new ModelBuilder(); Model model = modelBuilder.createBox(16f, 16f, 16f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); ModelInstance mis = new ModelInstance(model); mis.transform.setTranslation(position); instances.add(mis); } @Override public void render() { Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // The next two lines seem to improve the problem. Problem is almost totally gone // I tweaked the values in glPolygonOffset to make it work better Gdx.gl20.glEnable(Gdx.gl20.GL_POLYGON_OFFSET_FILL); Gdx.gl20.glPolygonOffset(0.1f,0.1f); // These make it worse! // Gdx.gl.glEnable(Gdx.gl20.GL_DEPTH_TEST); // Gdx.gl20.glDepthFunc(Gdx.gl20.GL_LEQUAL); // GL_LESS is default modelBatch.begin(cam); for(ModelInstance mi : instances) modelBatch.render(mi,environment); modelBatch.end(); } </code></pre> <p>Any ideas?</p> <p>Edit:</p> <p>Render on phone after changes to render() method (zoomed in, less bad edges): <img src="https://i.imgur.com/17zGnye.png" alt="Android Rendering after"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload