Shader

This article is about in-game shaders using resource packs. For the shaders provided by game modifications, see Shader pack. For the shaders available in the options menu before Java Edition 1.9, see Super Secret Settings. For the built-in shaders in Bedrock Edition, see Vibrant Visuals.
This article is a work in progress.
 
Please help expand and improve it. The talk page may contain suggestions.
Note: The bedrock edition section is incomplete and would benefit from more information. Java Edition History section could be expanded to include more details for changes made around 1.17 to 1.19. The Java Edition "Render process" section would benefit from more information

Shaders are used to define the game's rendering of certain elements.

Java Edition

Two distinct kinds of shaders exist: core shaders and post-processing shaders.

Core shaders are used to render fundamental parts of the game such as entities and terrain.

Post-processing shaders are used to apply slightly more complex visual effects to the screen.

Shaders are written in the OpenGL Shading Language (GLSL). Each single render program comes in two parts, "vertex" and "fragment"; vertex shaders modify the positions of individual vertices, whereas fragment shaders are applied to every pixel. For example, vertex shaders are often used to create waving foliage and water, and fragment shaders can be used to add effects like bloom, god rays, and blur. In Minecraft, vertex shaders must use the extension ".vsh", and fragment shaders, likewise, ".fsh"

Shaders programs are stored in the assets/minecraft/shaders directory of client.jar, and can be replaced with a resource pack. Note that if any error occurs when loading the shaders, the resource pack is disabled and fabulous graphics mode is turned off.

Core shaders

Although core shaders can be replaced with a resource pack, this isn't an intended or supported feature and may change at any time.

Core shaders are used to render almost everything in the game, including terrain, entities, gui elements, etc. The shader programs for core shaders are located in the assets/<namespace>/shaders/core directory of a resourcepack.

List of core shaders

A list of all core shaders can be found by expanding the header below, listing descriptions of what each shader is responsible for, as well as what uniforms, samplers, and define directives are available to each shader.

Include shaders

Include shaders (stored in assets/<namespace>/shaders/include) contain helper functions and variables that can be used in multiple shader programs. These must have the .glsl, .vsh, or .fsh file extensions.

To import an include shader, add one of the following import directives anywhere in a vertex or fragment shader program

  • #moj_import <filepath.glsl> imports a file from assets/minecraft/shaders/include/<filepath>.glsl
  • #moj_import <namespace:path.glsl> imports a file from assets/<namespace>/shaders/include/<path>.glsl
  • #moj_import "filepath.glsl" imports a file from assets/minecraft/<filepath>.glsl
  • #moj_import "namespace:path.glsl" imports a file from assets/<namespace>/<filepath>.glsl

When importing an include shader, the game replaces the import directive with the contents of the include shader. The imported file needs to end with an empty line, otherwise the shader does not load.

Vanilla include shaders

The following include shaders are used throughout the vanilla resource pack

Name Description
fog.glsl Contains the linear_fog function to calculate the color based on the vertex distance. Contains a definition of the Fog uniform block
light.glsl Contains the minecraft_mix_light function, used to calculate face lighting in entity shaders. Contains a definition of the Lighting uniform block
matrix.glsl Contains the mat2_rotate_z function that returns the rotation matrix for a vec2 around the z-axis.
projection.glsl Contains the projection_from_position function. Contains a definition of the Projection uniform block
globals.glsl Contains a definition of the Globals uniform block.
dynamictransforms.glsl Contains a definition of the DynamicTransforms uniform block.

Post-processing effects

As mentioned previously, post-processing effects are used in menu backgrounds, when spectating certain mobs to create vision effects, the Fabulous! graphics setting, and when rendering the glowing effect.

Post-effect file format

Post-processing effects are made up of multiple passes and render targets. A target is a buffer that can be read from and written to. The game provides some built-in targets that contain certain parts of the game world (particles, water, etc), and you can define your own to read and write data to. A pass can have multiple inputs from png textures or render targets.

Post-processing effects are defined in assets/<namespace>/post_effect/<post effect>.json. Note that post-processing effects are applied before the HUD and GUI elements are rendered

  • [NBT Compound / JSON Object]: The root tag
    • [NBT Compound / JSON Object]  targets: Custom render targets to be used by render passes
      • [NBT Compound / JSON Object]  target definition: The key is the name of the target
        • [Int]  width: Defaults to the current viewport width. The width of the target
        • [Int]  height: Defaults to the current viewport height. The height of the target
        • [Boolean]  persistent: Defaults to false. If true, this target is not cleared between frames. It is still cleared when the game window is resized, however.
        • [NBT List / JSON Array][Int]  clear_color Defaults to [0, 0, 0, 0]. The colour this target is filled with when it is created or cleared. Supports two formats. A list of floats in 0-1 range [R, G, B, A], or a colour in decimal format calculated from the red, green and blue components using this formula:
          (Alpha << 24) + (Red << 16) + (Green << 8) + Blue
    • [NBT List / JSON Array]  passes: Render passes
      • [NBT Compound / JSON Object]  pass: A render pass
        • [String]  vertex_shader: The namespaced id of a vertex shader to use for this pass, relative to the shaders folder. minecraft:post/blit resolves to assets/minecraft/shaders/post/blit.vsh
        • [String]  fragment_shader: The namespaced id of a fragment shader to use for this pass, relative to the shaders folder. minecraft:post/box_blur resolves to assets/minecraft/shaders/post/box_blur.fsh
        • [NBT List / JSON Array]  inputs: A list of render target inputs and / or texture inputs
          • [NBT Compound / JSON Object]  render target input
            • [String]  sampler_name: The name of the sampler uniform
              • Setting this to MainDepth, for example, makes a sampler2D uniform called MainDepthSampler available to the shader program for this pass. This will also provide an additional vec2 to the SamplerInfo uniform block called <sampler_name>Size, for example MainDepthSize
            • [Boolean]  bilinear: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor
            • [String]  target: The name of the target. Can either be a custom target as specified in targets above, or one of the following built in targets: minecraft:main, minecraft:translucent, minecraft:item_entity, minecraft:particles, minecraft:weather, minecraft:clouds, or minecraft:entity_outline
            • [Boolean]  use_depth_buffer: Default: false. If set to true, it samples from the depth texture instead of the color texture.
          • [NBT Compound / JSON Object]  texture input
            • [String]  sampler_name: The name of the sampler uniform
              • Setting this to MyTexture, for example, makes a sampler2D uniform called MyTextureSampler available to the shader program for this pass. This will also provide an additional vec2 to the SamplerInfo uniform block called <sampler_name>Size, for example MyTextureSize
            • [Boolean]  bilinear: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor
            • [String]  location: The resource location of the texture. my_namespace:post_texture resolves to assets/my_namespace/textures/effect/post_texture.png
            • [Int]  width: The width of the texture in pixels
            • [Int]  height: The height of the texture in pixels
        • [String]  output: The target to output to. Can either be a custom target as specified in targets above or minecraft:main. Note: you cannot read and write to the same target in the same pass
        • [NBT Compound / JSON Object]  uniforms: An object of uniform blocks to pass to the vertex and fragment shaders. For example, uniforms: { "UniformBlockName": [ { "type": "vec2", "value": [...] } ] }
          • [NBT List / JSON Array]  uniform block: The key is what this uniform block will be called when referenced in a shader
            • [NBT Compound / JSON Object]  uniform definition
              • [String]  name: The name of the uniform. This is unused by the game, however it is recommended to set it for organizational purposes
              • [String]  type: The type of the uniform, can be any of: int, float, ivec3, vec2, vec3, vec4, and matrix4x4
              • [Int][Float][NBT List / JSON Array]  value: Uniform values. The amount and format of this depends on what the type field is set to
                • int requires a single int
                • float requires a single float
                • ivec3 requires list of 3 ints
                • vec2 requires list of 2 floats
                • vec3 requires list of 3 floats
                • vec4 requires list of 4 floats
                • matrix4x4 requires 16 floats

List of post-processing effects

There are currently six post-processing effects used in the game:

Name Used for Sample images
blur Used for the blur effect in the background of most menus in-game and on the title screen. This post effect is not used when the "Menu Background Blur" accessibility setting is set to 0.
creeper Adds a green filter over the screen and give the appearance of a reduced resolution. Used when spectating a creeper.
entity_outline Applies a blur over a solid color silhouette of an entity. Used when an entity with the glowing effect is on-screen.
Left side is the "minecraft:entity_outline" target before the post effect is applied, right side is the final image with the post effect applied
invert Inverts the colours of the screen. Used when spectating an enderman.
spider Renders a blurred version of the screen with 5 additional copies overlapped on top with blurred edges. Used when spectating a spider.
transparency Combines multiple passes (targets) of different objects in the world, resulting in slightly better translucency blending compared to "Fast" or "Fancy" graphics. Used when the graphics mode is set to "Fabulous!".
"minecraft:main" target
"minecraft:translucent" target

"minecraft:item_entity" target
"minecraft:particles" target

"minecraft:clouds" target
"minecraft:weather" target

Final image

Render process

This section needs expansion.
 
You can help by expanding it.

General game rendering

Each frame is rendered in the following order​

  • The world, including entities, blocks, the sky, items, etc is rendered (by core shaders)
  • Any Post effects are applied as necessary
  • The GUI and HUD elements are rendered (by core shaders)

GUI item and entity rendering

When the game draws an item or entity in a GUI the following process occurs:

  • The item or entity is pre-rendered to an internal texture. For items, this may be an atlas of all currently visible items ("GUI items atlas") or a single texture for that item. This depends on if the oversized_in_gui field is set to true or false in the items model definition. For entities, each one always has a unique texture that it gets rendered to
  • For each item or entity, a quad is drawn to the screen which samples from either the GUI items atlas or individual texture for the corresponding item or entity

The game can skip rendering an item when neccesary and will use whatever was drawn on the previous frame. An item is only re-rendered if one of the following conditions is met:

  • The item has an animated texture somewhere on its model
  • The item has an enchantment glint
  • The GUI items atlas fills up, in this case it is cleared and all currently visible GUI items are redrawn
  • The GUI scale is changed, in this case the GUI items atlas is cleared and all currently visible GUI items are redrawn
  • The item data is changed in a way that would cause a visual update. This includes but is not limited to: changing the item_model, custom_model_data, or profile data components

Vanilla uniform blocks

Using uniform blocks outside supported shaders may work in some cases, however this is undefined behaviour and may cause unexpected results or crashes. Refer to the the list of core shaders for more info

Uniforms blocks use the std140 layout. All uniforms must be specified and in the correct order and with the correct type, otherwise weird and undefined behaviour will occur. For convenience, some uniform blocks are pre-defined in include shaders, see the include shaders section for more information.

Some shaders may not use all uniforms in a given uniform block, in this case the unused uniforms will have a 'default' value. For example, while the rendertype_lines core shader will have the proper value for the LineWidth uniform, other shaders will have a "default value" for which will likely not be useful.

Common blocks

The following uniform blocks are available in both post-processing and core shaders.

Globals

This uniform block is always bound and has proper values in all shaders.

  • (vec2) ScreenSize The width and height of the current framebuffer in pixels.
  • (float) GlintAlpha The value of the Glint Strength accessibility setting in a 0-1 range.
  • (float) GameTime A value that constantly increases from 0-1 over the span of roughly 20 minutes, then resets to 0. The exact formula for this is (<age of the world> modulo 24000) / 24000.
  • (int) MenuBlurRadius The value of the Menu Background Blur accessibility setting in a 0-10 range.

Core blocks

The following uniform blocks are only available in core shaders.

Fog

This uniform block is always bound, however may not have proper values if used outside shaders which support it.

  • (vec4) FogColor Colour of the fog.
  • (float) FogEnvironmentalStart Starting distance of environmental fog.
  • (float) FogEnvironmentalEnd Ending distance of environmental fog.
  • (float) FogRenderDistanceStart Starting distance of render distance fog.
  • (float) FogRenderDistanceEnd Ending distance of render distance fog.
  • (float) FogSkyEnd Ending distance of fog for the upper portion of the sky.
  • (float) FogCloudsEnd Ending distance for clouds fog.
DynamicTransforms
  • (mat4) ModelViewMat The model-view matrix.
  • (vec4) ColorModulator A color multiplier that can be set in game code to modify the final color of objects.
  • (vec3) ModelOffset The offset of the model being rendered.
  • (mat4) TextureMat A 4D matrix used to transform UV's for some animated effects, such as the enchantment glint, breeze and wind charge wind, world border, etc.
  • (float) LineWidth The width of the line.
Lighting

This uniform block is always bound, however may not have proper values if used outside shaders which support it.

  • (vec3) Light0_Direction First light direction. Used to calculate directional entity shading.
  • (vec3) Light1_Direction Second light direction. Used to calculate directional entity shading.
Projection

This uniform block is always bound, however may not have proper values if used outside shaders which support it.

  • (mat4) ProjMat The projection matrix
LightmapInfo
  • (float) AmbientLightFactor How much ambient light there should be. This is 0.1 for the nether and 0 for the end and overworld.
  • (float) SkyFactor A value that specifies how much to brighten the lightmap by when the sky flashes, typically when a lightning strike occurs.
  • (float) BlockFactor A value that fluctuates randomly, used in the vanilla shader for block light flickering.
  • (int) UseBrightLightmap A "boolean" value that specifies if the current dimension has skylight, this is only used for The End in vanilla but can also apply to custom datapack dimensions.
  • (float) NightVisionFactor A value in a 0-1 range that specifies how much the Night Vision status effect should brighten the lightmap by.
  • (float) DarknessScale A value in a 0-1 range that specifies how much the Darkness status effect should darken the lightmap by.
  • (float) DarkenWorldFactor A value that specifies how much to darken the lightmap by when a bossbar is visible. This is seemingly only used in the ender dragon fight ​.
  • (float) BrightnessFactor The value of the brightness video setting in a 0-1 range.
  • (vec3) SkyLightColor The color of sky light.
CloudInfo
  • (vec4) CloudColor The color of the clouds.
  • (vec3) CloudOffset Offset of the clouds ​.
  • (vec3) CellSize Size of each individual cloud ​.

Post-processing blocks

The following uniform blocks are only available in post-processing shaders.

SamplerInfo
  • (vec2) OutSize The width and height of the output buffer in pixels.
  • (vec2) All other inputs specified in the same order as the post-effect definition. These are named as <sampler_name>Size, for example, MainSize for an input with a name of "Main"

Vanilla uniforms

In Java Edition 1.21.6, loose opaque uniforms have been removed and replaced with Uniform blocks

A list of uniforms that are provided by the game.

Post-processing uniforms

Uniforms available to post shaders.

  • (vec2) InSize The width and height of the input buffer in pixels.
  • (vec2) OutSize The width and height of the output buffer in pixels.
  • (matrix4x4) ProjMat The projection matrix.
  • (vec2) ScreenSize The resolution of the current framebuffer in pixels (width, height).
  • (float) GameTime The current age of the world. This is the result of /time query gametime modulo 24000 and divided by 24000. It increases from 0 and reaches 1 roughly 20 minutes later, it then resets back to 0.
Core uniforms

Uniforms available to core shaders. Note that not all uniforms are available in all shaders, refer to the list of core shaders.

Using uniforms outside of shaders that they are normally available in may work in some cases, however this is undefined behaviour and may cause unexpected results or crashes.
  • (matrix4x4) ProjMat The projection matrix.
  • (matrix4x4) ModelViewMat The model-view matrix.
  • (vec2) ScreenSize The resolution of the current framebuffer in pixels (width, height).
  • (float) GameTime The current age of the world. This is the result of /time query gametime modulo 24000 and divided by 24000. It increases from 0 and reaches 1 roughly 20 minutes later, it then resets back to 0.
  • (vec4) ColorModulator A color multiplier that can be set in game code to modify the final color of objects.
  • (vec3) Light0_Direction First light direction, used in vanilla to calculate entity lighting.
  • (vec3) Light1_Direction Second light direction, used in vanilla to calculate entity lighting.
  • (float) FogStart The distance from the camera that fog starts to be applied.
  • (float) FogEnd The distance from the camera that fog is fully applied, objects further than this distance are typically hidden by fog.
  • (vec4) FogColor The color of the fog.
  • (vec3) ModelOffset The offset of the model being rendered. This is only available in terrain shaders to offset chunk sections to their correct position.
  • (float) GlintAlpha Contains the value of the glint strength accessibility setting in a 0-1 range.
  • (matrix4x4) TextureMat 4D matrix used to transform UV's for some animated effects, such as the enchantment glint, breeze and wind charge wind, world border, etc.
  • (float) LineWidth The width of the line.
  • (float) AmbientLightFactor How much ambient light there should be. This is 0.1 for the nether and 0 for the end and overworld.
  • (float) SkyFactor A value that specifies how much to brighten the lightmap by when the sky flashes, typically when a lightning strike occurs.
  • (float) BlockFactor A value that fluctuates randomly, used in the vanilla shader for block light flickering.
  • (int) UseBrightLightmap A "boolean" value that specifies if the current dimension has skylight, this is only used for The End in vanilla but can also apply to custom datapack dimensions.
  • (vec3) SkyLightColor The color of sky light.
  • (float) NightVisionFactor A value in a 0-1 range that specifies how much the Night Vision status effect should brighten the lightmap by.
  • (float) DarknessScale A value in a 0-1 range that specifies how much the Darkness status effect should darken the lightmap by.
  • (float) DarkenWorldFactor A value that specifies how much to darken the lightmap by when a bossbar is visible. This is seemingly only used in the ender dragon fight ​.
  • (float) BrightnessFactor The value of the brightness video setting in a 0-1 range.


Bedrock Edition

This section needs expansion.
 
You can help by expanding it.

Since Bedrock Edition 1.18.30, third-party shader in resource packs are no longer supported on all devices due to the implementation of RenderDragon.

Deferred rendering pipeline

The deferred rendering pipeline is an alternative rendering pipeline which can be customized via resource packs and is used in the vanilla game for the Vibrant Visuals graphics mode.

Although it doesn't directly support custom shaders, it offers ways to define properties about light, fog, atmosphere, and PBR texture materials. This can be used to create lighting effects similar to those seen in Java Edition's shader packs.

History

Java Edition
1.7.213w38aShaders were added for Super Secret Settings.
1.814w05aThe Creeper and Spider shaders were added. Shaders are automatically applied in spectator mode when viewing the world as a creeper, spider or enderman.
14w05bShaders have been removed from view when changing perspective while spectating a mob.[1]
F4 now toggles different shaders rather than turning them off.[1]
14w06aThe entity_outline post effect shader was added.
1.915w31aRemoved the Super Secret Settings button for an internal rewrite.[2]
1.1620w22aThe transparency post effect shader was added for Fabulous! graphics mode.
1.1721w10aAdded core shaders.
Added the fog.glsl, light.glsl, matrix.glsl, and projection.glsl include shaders
Upgraded the existing shader programs for post processing effects from glsl version 1.1 to 1.5
1.18.1?The fog.glsl include shader now has a cylindrical_distance function. All core shaders that previously used the builtin length function to calculate vertex distance use this.
1.18.2?In fog.glsl the cylindrical_distance function has been renamed to fog_distance. It also takes an additional int parameter for fog shape.
?Added the FogShape uniform for core shaders.
1.1922w12aThere are now shader files for translucent entity rendering.
1.20.524w05aThe unused attributes array in core shader definitions has been removed.
The unused position_color_normal and position_tex_lightmap_color core shaders have been removed
The position_tex_color_normal core shader has been renamed to rendertype_clouds
The IViewRotMat uniform has been removed, and the Position attribute for entities is now in (camera relative) world space
Light direction uniforms are no longer premultiplied by the view matrix
24w09aThe menu background dirt texture has been replaced by a post-processing blur shader.
24w11aAll unused post-processing shaders that were used for Super Secret Settings have been removed.
1.21.224w34aShader program configurations can now specify preprocessor define directives to apply to their linked shaders.
The format of core shader and post-processing shader configurations have been consolidated.
The rendertype_entity_glint_direct core shader has been removed and replaced by rendertype_entity_glint.
The rendertype_entity_translucent_cull shader has been removed and replaced by rendertype_item_entity_translucent_cull.
?Renamed the ChunkOffset uniform to ModelOffset
?Most textured gui elements now use the position_tex_color core shader instead of position_tex
1.21.525w06aAdded a new core shader, rendertype_world_border, which is used to render the world border
25w07aShader program configuration files have been removed. The shader programs are still present, however the only uniforms available to them are the default ones that are used in the vanilla rendering.
In post-processing effects, the field program was replaced with vertex_shader and fragment_shader which resolve to assets/<namespace>/shaders/<path>.<vsh or fsh>
In post-processing effects, type is now a required field for each uniform, with the possible values being int, ivec3, float, vec2, vec3, vec4 and matrix4x4
In post-processing effects, the values field is now option for each uniform. Leaving it unset is not recommended as it will result in undefined behaviour. Leaving it unset is only used for runtime configuration of the blur post-processing effect in the vanilla rendering
The EndPortalLayers uniform has been removed and replaced by a pre-processor define called PORTAL_LAYERS
25w10a"Global" uniforms can now be defined in shader programs. If a uniform is not usually available to that shader, or the type of the uniform is not defined as what it would normally be, undefined behaviour will occur
Currently, the "global" uniforms are: ModelViewMat, ProjMat, TextureMat, ScreenSize, ColorModulator, Light0_Direction, Light1_Direction, GlintAlpha, FogStart, FogEnd, FogColor, FogShape, LineWidth, GameTime, and ModelOffset
1.21.625w16aAll built-in uniforms are now uniform blocks instead of opaque loose uniforms
Custom uniforms provided to post-process shaders are now uniform blocks
In post-processing effects, targets now supports two new optional fields: persistent and clear_color
In post-processing effects, the uniforms field is now a list of uniform blocks, example: { "UniformBlockName": [ { "type": "vec2", "value": [...] } ] }.
In post-processing effect uniform definitions, the name field is now unused by the game but still present. The values field has been replaced with value, behaving largely the same but for the int and float uniform types this field accepts a single number instead of a list with 1 entry.
In post-processing effects, the list of size (all vec2 *Size) uniforms have been replaced with a single SamplerInfo uniform block.
The main menu panorama now uses a new fragment program, core/panorama.fsh.
The core/position_tex.fsh program is now unused.
The position core shader can now have a FOG_IS_SKY define directive.
The minecraft_sample_lightmap has been removed from the light.glsl include shader. All shaders that previously used this function now instead sample the lightmap texture directly.
25w17aAdded two new core shaders; stars, and sky which are used to render the stars and upper portion of the sky respectively.
Removed the FOG_IS_SKY define directive, as the sky now uses a separate shader.
25w19aThe main menu panorama now uses a new vertex program, core/panorama.vsh.
The core/position_tex.vsh program is now unused.
Added four new uniforms, FogEnvironmentalStart, FogEnvironmentalEnd, FogRenderDistanceStart and FogRenderDistanceEnd.
The FogShape, FogStart and FogEnd uniforms have been removed.

Gallery

Issues

Issues relating to "Shader" are maintained on the bug tracker. Issues should be reported and viewed there.

References

External links

Navigation