TrueCraft icon indicating copy to clipboard operation
TrueCraft copied to clipboard

Client - don't draw unnecessary vertices.

Open UnknownShadow200 opened this issue 10 years ago • 9 comments

Currently, the client renders all vertices of all faces (example here, with all blocks being drawn at half extent to make the overdraw visible): truecraft1

There are two main ways you can reduce this: For solid blocks

  1. Add a 'IsSolidFace(Face...' method to BlockProvider. You can skip drawing a face when the face on this block is solid and the corresponding face on the neighbouring block is also solid. (There are some corner cases. For example, cactus would only be true for Y positive and Y negative)

For transparent and transluscent blocks, you can do this: 2) Add a 'CanShareWithNeighbours(Face...' method to BlockProvider. You can skip drawing a face when a block and its neighbour are the same type. (e.g. for glass, water) (Note that water is a bit trickier - for horizontal neighbours, you have to make sure that they have the same height and shape)

UnknownShadow200 avatar May 29 '15 20:05 UnknownShadow200

  1. Add a 'IsSolidFace(Face...' method to BlockProvider. You can skip drawing a face when the face on this block is solid and the corresponding face on the neighbouring block is also solid.

We already half do this. The chunk renderer only creates meshes for blocks that neighbor transparent blocks. You're suggesting to extend this to even omit faces that do not neighbor transparent blocks? It's a good idea but will be complicated to implement.

  1. Add a 'CanShareWithNeighbours(Face...' method to BlockProvider. You can skip drawing a face when a block and its neighbour are the same type. (e.g. for glass, water)

Yeah, good call.

ddevault avatar May 29 '15 20:05 ddevault

Maybe I didn't clarify enough. You can see above that the client is drawing the underlying stone and dirt - even when they are all hidden anyways.

UnknownShadow200 avatar May 29 '15 20:05 UnknownShadow200

In that screenshot, all of that dirt/stone is surrounded by air blocks and has to be drawn. I'm definitely missing something here.

ddevault avatar May 29 '15 20:05 ddevault

Sorry I didn't make that clear in the screenshot. I'd changed the 'CreateUniformCube' mesh size from 0.5 to 0.25 to show that the blocks are being drawn, even though they are normally completely hidden.

UnknownShadow200 avatar May 29 '15 20:05 UnknownShadow200

Oh, I understand. I thought the actual world had the spaces in it. This is definitely a bug, then. This code is meant to collect a list of coordinates that neighbor transparent blocks, and this code renders only those coordinates. Are you using the most up to date client? If so, then this is definitely a bug.

ddevault avatar May 29 '15 21:05 ddevault

Yeah, I've confirmed the bug for myself now. Investigating.

ddevault avatar May 29 '15 21:05 ddevault

var coords = new Coordinates3D(x, y, z);
var id = chunk.GetBlockId(coords);
var provider = BlockRepository.GetBlockProvider(id);
if (id != 0)
   DrawableCoordinates.Add(coords);

That always adds coordinates for opaque blocks though?

UnknownShadow200 avatar May 29 '15 21:05 UnknownShadow200

Yeah, found and fixed the error. I'll push up a commit shortly.

ddevault avatar May 29 '15 21:05 ddevault

Thanks for pointing out that mistake, @UnknownShadow200, performance is much better with that bug fixed.

ddevault avatar May 29 '15 22:05 ddevault