Introduction

Ever wondered how Optifine Shaders renders Minecraft? Want to know what all those gbuffers files do, and why they're different from the composite files? Need to figure out what exactly gbuffers_entities affects?

You've come to the right place. This page documents the Optifine Shaders pipeline, also known as Legacy Mode in Nova. Here we'll walk you through how Minecraft becomes an image on your screen.

The inspiration for this page, along with many of the images in it, came from the BSL Shaders Breakdown, which documents the BSL shaders.

Overview

Legacy Mode divides rendering into a few specific steps:

  1. Render the shadowmap
  2. Render opaque gbuffer shaders
  3. Render transparent gbuffer shaders
  4. Render composite shaders
  5. Render the final shaders
  6. Render the GUI

Let's explain them a little:

Shadowmap

The shadowmap as rendered by BSL shaders

The shadowmap as rendered by BSL shaders

Above is the shadowmap, as rendered by BSL Shaders. A shadowmap tells you how far it is from the shadow casting light to the closest bit of geometry. You can see some variation in this shadowmap - the left side is darker than the right side, and a couple dark patches are present on the right side. In a shadowmap, lighter values mean that things are farther away from the light, while darker values mean that things are closer. The dark patches in this shadowmap are structures that were build to illustrate various effects (you'll see them in a little bit).

Gbuffers

Legacy Mode implements a deferred rendering pipeline. The basics of deferred rendering is that you copy material parameters to an intermediate framebuffer when you draw geometry, then run a few shaders on the entire screen to calculate lighting. There's a lot more to it than that, so you should definitely ask Google about it, but that's the basics.

The intermediate framebuffer is often referred to as the Geometry Buffer, or gbuffer (GEE-buffer) for short. All the shaders that start with "gubffers_" will write to the gbuffer, and they're all run before any of the composite shaders

The data in the gbuffers in BSL. Top row, left to right: color of opaque objects, color of transparent objects, normals of opaque objects, normals of transparent objects. Bottom row, left to right: material flags and lightmap data of opaque objects, material flags and lightmap data of transparent objects, unused, and weather

The data in the gbuffers in BSL. Top row, left to right: color of opaque objects, color of transparent objects, normals of opaque objects, normals of transparent objects. Bottom row, left to right: material flags and lightmap data of opaque objects, material flags and lightmap data of transparent objects, unused, and weather

Composite

The composite passes are fullscreen passes rendered in numeric order. First is composite, then composite1, then composite2, etc. Legacy Mode supports up to 8 composite shaders. These are frequently used to render lighting, shadows, bloom, reflections, clouds, and other effects. In most shaders, the majority of the interesting work happens in the composite shaders (POM being a notable exception).

The output of BSL shaders after the first composite shader is rendered. Note that shadows and directional lighting have been applied to the image

The output of BSL shaders after the first composite shader is rendered. Note that shadows and directional lighting have been applied to the image