Monday, 13 April 2020

Quad Rendering [1.14.4+]

The basic rendering unit for most things you see in the world is the quad.  A quad will have
Position coordinates for its four vertices
Texture information
A facing direction (up, down, east, west, north, south).

Quads can be rendered in a number of different ways depending on the desired effect.  For example, the most significant RenderTypes for blocks are:
Opaque, cutout, translucent (see here)

The way that Quads are rendered is determined by which BufferBuilder they are rendered to.  Eg for block models, vanilla choses the renderbuffer based on the RenderType you have assigned to the block.

At the most basic level, rendering is performed by sending a stream of numbers to a BufferBuilder.  The numbers are grouped into Vertices, and the Vertices are grouped into objects (typically Quads).  For more background information about rendering, see OpenGL eg here 

Depending on what it is drawing, Minecraft uses a number of different VertexFormats.  Some formats have more information than others: for example, when drawing quads without any texture, only Position information is necessary for each Vertex.

The different type of VertexFormats can provide some or all of the following information for each Vertex:

  • Position coordinate (x,y,z)
  • Texture coordinate (u,v)
  • Multitexture (blocklight+skylight lighting)
  • Overlaytexture (Entity colour flash)
  • Colour (r, g, b)
  • Normal (nx, ny, nz) (used for shading of items) 

The required VertexFormat is determined by which BufferBuilder is being drawn to.

In addition, each BufferBuilder has settings which affect how the quads are drawn:

  • Texture sheet (which texture will be drawn on this quad)
  • Lightmap on/off (blocklight+skylight multitexture – see Lighting)
  • Alpha cutoff (for cutout rendering- any pixel with an alpha value less than threshold won’t be drawn)
  • Alpha blending (transparency blending type – controls the appearance of transparent quads)
  • Overlay texturing (similar to blocklight+skylight, but used for making an Entity flash a different colour- eg red when taking damage; or white for a creeper about to explode)
  • DiffuseLighting (uses vertex normal information to perform shading – for items and entities).  Do not confuse this with the diffuse lighting flag used by BlockModels: the concept is the same, but diffuse lighting for block models is applied in code, not using normals.
  • Culling (can you see the quad from both sides, or only from one side?)
  • Writemask (will this quad hide other quads which are drawn after it, even if the other quads are behind this quad in the scene?)
  • Depth test (will this quad check whether it is behind other quads already drawn in the scene?)


Interesting vanilla classes to explore:
BufferBuilder
RenderType
RenderTypes
RenderTypeBuffers
RenderTypeLookup
RenderState
VertexFormat
DefaultVertexFormats

Further information:
Minecraft Lighting
General OpenGL guide - concepts of rendering
Background info on 1.15.2 rendering
Block Rendering

No comments:

Post a comment