Minecraft Shaders Wiki

repository·main·Indexed 17 days ago

https://github.com/mctsts/minecraft-shaders-wiki

A technical guide for Minecraft shader developers documenting core and post-processing shaders. It covers the shader folder structure, the role of .vsh, .fsh, and .json files, and provides a detailed list of Non-Rendertype and Rendertype shaders used for game elements like blocks, entities, UI, and special effects. Includes guidance on using Suso's Shader Reload mod for debugging and calculating position values for UI shaders.

Tokens
9.2K
Snippets
24
Records
82
Agent score
66%

What's inside minecraft-shaders-wiki

  1. Overview of Minecraft Core Shaders

    main

    Minecraft core shaders are categorized into two main types: Non-Rendertype and Rendertype.

    • Non-Rendertype: General-purpose shaders that target broad elements like the sky, particles, or UI. These are not prefixed with rendertype_.
    • Rendertype: Shaders targeted at specific rendering elements (e.g., blocks, entities, UI). These are always prefixed with rendertype_.

    Use the shader type to determine which part of the game world or interface you can modify.

  2. Understand the Minecraft shader folder structure

    main

    Vanilla Minecraft shaders are located within the assets/minecraft/shaders directory of a resource pack. The shaders folder is organized into four primary subfolders:

    • core: Contains core shaders responsible for rendering most game elements (e.g., GUI elements, blocks).
    • post: Contains post-processing shaders.
    • program: Contains shader programs.
    • include: Contains shader include files.

    You can find a copy of the vanilla shader files in the mcmeta repository.

  3. Use Rendertype Block shaders for block rendering

    main

    Rendertype block shaders are used to modify how specific types of blocks appear.

    • rendertype_solid: Targets all solid blocks, lava, and (in fast mode) leaves. It also affects non-translucent falling blocks.
    • rendertype_cutout: Targets most non-cube-hitbox blocks. Refer to the specific block list for details.
  4. Use Non-Rendertype shaders for general effects

    main

    Non-Rendertype shaders target broad game elements. Common shaders include:

    • blit_screen: Copies one buffer to another. Note: This cannot be overridden in a resource pack.
    • particle: Affects weather (snow/rain) and all particles. The alpha value in the shader overrides the particle's inbuilt transparency (e.g., for sneeze particles).
    • position: Affects the color of the sky and text highlighting.
    • position_color: Handles sunset/sunrise sky overlays and F3+G chunk border displays. In versions prior to 1.20, it also handled various UI backgrounds (chat, pause menu, etc.).
    • position_tex: Handles the Sun, Moon, worldborder, most GUI textures (hotbar, buttons), overlays (pumpkin blur, vignette), and the crosshair.
    • position_tex_color: Handles the End sky, main menu backgrounds, fire overlays, and wall overlays.
  5. Structure of Core and Post Shaders

    main

    Core shaders and post-processing shaders typically consist of three distinct file types that work together:

    1. .vsh (Vertex Shader): Handles the processing of vertices.
    2. .fsh (Fragment Shader): Handles the processing of pixels/fragments.
    3. .json: A configuration file that defines how the shaders are linked and used.

    Note that post-processing shaders often share a single vertex shader across multiple fragment shaders.

  6. Identify block transparency types

    main

    In this shader system, blocks are categorized into three transparency types: solid, cutout_mipped, cutout, and translucent. Any block not explicitly listed in the cutout_mipped, cutout, or translucent categories is treated as solid.

    Understanding these categories is essential for determining how shaders will render specific block textures and their alpha channels.

  7. Use GameTime for time-based animations

    main

    The GameTime uniform is a constantly incrementing value synchronized with the server. It ranges from 0 to 1, repeating every 24,000 ticks (approximately 20 minutes).

    To create a loop that repeats roughly every second, use fract(GameTime * 1200).

    Note: Because it is synchronized with the server, it is affected by tick lag and may not be perfectly consistent.

    // Example: looping effect every ~1 second
    float timeLoop = fract(GameTime * 1200.0);
  8. Calculate World-Space Position for Entities

    main

    In Entity Shaders, the Position uniform represents the XYZ coordinates in view-space (relative to the camera).

    To get the actual vector position in world space, you must add the ChunkOffset to the Position and then multiply the result by the ModelViewMatrix.

    Formula: WorldPosition = ModelViewMat * (Position + ChunkOffset)

    // Entity Shader world position calculation
    vec3 worldPos = ModelViewMat * (Position + ChunkOffset);
  9. What are Uniforms in Minecraft shaders?

    main
    Uniforms are read-only variables passed to core shaders to determine their behavior. They are constant across every vertex and fragment of the same shader type within a single draw call. They allow shaders to access global game state such as time, fog parameters, camera position, and transformation matrices.