Shader
Note: The bedrock edition section is incomplete and would benefit from more information. Java Edition built-in post-processing shaders could use expanded explanations similar to Super Secret Settings or the "List of core shaders" section.
Shaders are used to define the game's rendering of certain elements.
Java Edition Edit
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.
- The menu background blur
- Certain mob vision types as seen in the Spectator gamemode
- The Fabulous! graphics setting's fixed handling of translucent objects
- The Glowing status effect
- The Super Secret Settings shaders up to their removal in Java Edition 1.20.5
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 Edit
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 Edit
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.
Name | Used for | Sample images | Available uniforms | Available samplers | Define directives |
---|---|---|---|---|---|
blit_screen | Copies one buffer to another, cannot be fully overriden with a resourcepack. | None present. | Sampler0 - The buffer to copy from.
|
None present. | |
entity | Renders most entities including:
|
![]() |
ModelViewMat
|
Sampler0 - The base texture of the entity.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded.
|
glint | Renders the enchantment glint on items, equipment, etc. | ![]() |
ModelViewMat
|
Sampler0 - The enchantment glint texture.
|
None present. |
gui | Renders flat colored gui elements including:
|
![]() ![]() |
ModelViewMat
|
None present. | None present. |
lightmap | Renders the lightmap which is used by other shaders to determine how bright or dark parts of the world should be. Only the fragment shader can be overridden with a resourcepack. | ![]() |
AmbientLightFactor
|
None present. | None present. |
particle | Renders all particle effects. Also renders the rain and snow weather effects. |
![]() |
ModelViewMat
|
Sampler0 - The particles or blocks atlas, depending on the particle that is being rendered.
|
None present. |
position_color_lightmap
position_color_tex_lightmap |
Unused. | None present. | None present. | None present. | |
position_color | Renders the lower half of the sky at sunrise and sunset. Also renders the F3 debug pie and chunk borders. |
![]() ![]() |
ModelViewMat
|
None present. | None present. |
position_tex_color | Renders some miscellaneous textured things including:
|
![]() ![]() |
ModelViewMat
|
Sampler0 - The texture of the object being rendered. For most gui widgets and icons, this is the gui atlas.
|
None present. |
position_tex | Renders the title screen panorama. |
![]() |
ModelViewMat
|
Sampler0 - One of the panorama images.
|
None present. |
position | Renders the upper half of the overworld skybox and the stars. This also handles the depth for the ender dragon's death rays[more information needed]. |
![]() |
ProjMat
|
None present. | None present. |
rendertype_beacon_beam | Renders the beacon and end gateway beams. |
![]() |
ModelViewMat
|
Sampler0 - The texture of the current part of the beam being rendered.
|
None present. |
rendertype_clouds | Renders the clouds. |
![]() |
ModelViewMat
|
None present. | None present. |
rendertype_crumbling | Renders the block breaking animation. |
![]() |
ModelViewMat
|
Sampler0 - The texture for current stage of the block breaking animation.
|
None present |
rendertype_end_portal | Renders the end portal and end gateway "starfield" effect. |
![]() |
ModelViewMat
|
Sampler0 - The end sky texture textures/environment/end_sky.png .
|
PORTAL_LAYERS - The amount of star layers to render.
|
rendertype_entity_alpha | Acts as an alpha mask for the ender dragon while it is dying. Pixels that are discarded in this shader will make the corresponding pixels on the ender dragon invisible. |
![]() |
ModelViewMat
|
Sampler0 - The dragon exploding texture textures/entity/enderdragon/dragon_exploding.png .
|
None present. |
rendertype_entity_decal | Renders the textured parts of the ender dragon while it is dying. |
![]() |
ModelViewMat
|
Sampler0 - The base texture of the entity.
|
None present. |
rendertype_entity_shadow | Renders the shadow that appears under most entities. |
![]() |
ModelViewMat
|
Sampler0 - The shadow texture textures/misc/shadow.png .
|
None present. |
rendertype_item_entity_translucent_cull | Renders experience orbs and items that are not rendered by the entity shader including:
|
![]() |
ModelViewMat
|
Sampler0 - The texture of the object being rendered, either the blocks atlas or the experience orb texture.
|
None present. |
rendertype_leash | Renders leads that are attached to entities in the world. |
![]() |
ModelViewMat
|
Sampler2 - The lightmap.
|
None present. |
rendertype_lightning | Renders lightning bolts and the ender dragon's death rays. |
![]() ![]() |
ModelViewMat
|
None present. | None present. |
rendertype_lines | Renders all types of lines including:
|
![]() |
ModelViewMat
|
None present. | None present. |
rendertype_outline | Renders a flat colored outline of entities which have the glowing effect.
The colour of this is based on the team the entity is in, or the glow color override for display entities, which is passed to the shader via the The output of this shader is saved to a buffer and then later used in the |
![]() |
ModelViewMat
|
Sampler0 - The base texture of the object being rendered.
|
None present. |
rendertype_text_background_see_through | Renders the background of text display entities that are set to render through blocks. |
![]() |
ModelViewMat
|
None present. | None present. |
rendertype_text_background | Renders the background of text display entities that are not set to render through blocks. |
![]() |
ModelViewMat
|
None present. | None present. |
rendertype_text_see_through
rendertype_text_intensity_see_through |
Renders text that is visible through blocks. Also renders the background of player and entity nameplates.
Note: rendertype_text_intensity_see_through is identical, however it is only used to render ttf fonts. |
![]() |
ModelViewMat
|
Sampler0 - An automatically generated 256x256 atlas which contains the current character that is being rendered.
|
None present. |
rendertype_text
rendertype_text_intensity |
Renders text in the world and in GUIs. Also renders maps in item frames or when held in first person.
Note: rendertype_text_intensity is identical, however it is only used to render ttf fonts. |
![]() ![]() |
ModelViewMat
|
Sampler0 - An automatically generated 256x256 atlas which contains the current character that is being rendered. For maps, this is the map background texture, map_decorations atlas, or the map itself depending on which part is currently being rendered.
|
None present. |
rendertype_translucent_moving_block | Renders translucent blocks, such as stained glass, that are being moved by a piston. Non-translucent blocks are rendered by the terrain shader.
|
![]() |
ModelViewMat
|
Sampler0 - The blocks atlas
|
None present. |
rendertype_water_mask | A mask used to hide water inside boats. |
![]() |
ModelViewMat
|
None present. | None present. |
rendertype_world_border | Renders the world border. |
![]() |
TextureMat
|
Sampler0 - The world border texture textures/misc/forcefield.png .
|
None present. |
terrain | Renders all blocks and fluids in the world. |
![]() |
ModelViewMat
|
Sampler0 - The blocks atlas.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded.
|
Include shaders Edit
Include shaders (stored in assets/<namespace>/shaders/include
) contain helper functions and variables that can be used in multiple shader programs.
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 fromassets/minecraft/shaders/include/<filepath>.glsl
#moj_import <namespace:path.glsl>
imports a file fromassets/<namespace>/shaders/include/<path>.glsl
#moj_import "filepath.glsl"
imports a file fromassets/minecraft/<filepath>.glsl
#moj_import "namespace:path.glsl"
imports a file fromassets/<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 [upcoming JE 1.21.6]
|
light.glsl | Contains the minecraft_mix_light function, used to calculate face lighting in entity shaders. Contains a definition of the Lighting uniform block [upcoming JE 1.21.6]
|
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 [upcoming JE 1.21.6]
|
globals.glsl [upcoming JE 1.21.6] | Contains a definition of the Globals uniform block.
|
dynamictransforms.glsl [upcoming JE 1.21.6] | Contains a definition of the DynamicTransforms uniform block.
|
Post-processing effects Edit
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 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: The width of the target
- [Int] height: The height of the target
- If width and height are not present, the target matches the size of the game window
- [NBT Compound / JSON Object] target definition: The key is the name of the target
- [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 toassets/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 toassets/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 calledMainDepthSampler
available to the shader program for this pass
- Setting this to
- [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
, orminecraft:entity_outline
- [Boolean] use_depth_buffer: Default: false. If set to true, it samples from the depth texture instead of the color texture.
- [String] sampler_name: The name of the sampler uniform
- [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 calledMyTextureSampler
available to the shader program for this pass
- Setting this to
- [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 toassets/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] sampler_name: The name of the sampler uniform
- [NBT Compound / JSON Object] render target input
- [String] output: The target to output to. Can either be a custom target as specified in
targets
above orminecraft:main
. Note: you cannot read and write to the same target in the same pass - [NBT List / JSON Array] uniforms: A list of uniforms to pass to the vertex and fragment shaders
- [NBT Compound / JSON Object] uniform
- [String] name: The name of the uniform
- [String] type: The type of the uniform, can be any of:
int
,ivec3
,float
,vec2
,vec3
,vec4
, andmatrix4x4
- [NBT List / JSON Array] values: Uniform values
- [NBT Compound / JSON Object] uniform
- [String] vertex_shader: The namespaced id of a vertex shader to use for this pass, relative to the shaders folder.
- [NBT Compound / JSON Object] pass: A render pass
- [NBT Compound / JSON Object] targets: Custom render targets to be used by render passes
List of post-processing effects Edit
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. |
![]() |
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!". |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Render process Edit
Each frame is rendered in the following order[more information needed]
- 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)
Vanilla uniforms Edit
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.
- (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. - (float)
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 [more information needed]. - (float)
BrightnessFactor
The value of the brightness video setting in a 0-1 range.
Bedrock Edition Edit
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. However, they are supported with the Deferred Rendering Pipeline, currently being tested.[upcoming BE]
History Edit
[hide]Java Edition | |||||||
---|---|---|---|---|---|---|---|
1.7.2 | 13w38a | Shaders were added for Super Secret Settings. | |||||
1.8 | 14w05a | The Creeper and Spider shaders were added. Shaders are automatically applied in spectator mode when viewing the world as a creeper, spider or enderman. | |||||
14w05b | Shaders have been removed from view when changing perspective while spectating a mob.[1] | ||||||
F4 toggles different shaders rather than turning them off.[1] | |||||||
14w06a | The Entity Outline shader was added. | ||||||
1.9 | 15w31a | Removed the Super Secret Settings button for an internal rewrite.[2] | |||||
1.16 | 20w22a | The Transparency shader was added for Fabulous! graphics mode. | |||||
1.17 | 21w10a | Core shaders were added. | |||||
1.19 | 22w12a | There are now shader files for translucent entity rendering. | |||||
1.20.5 | 24w05a | The unused attributes array in core shader definitions has been removed. | |||||
The unused position_color_normal and position_tex_lightmap_color shaders have been removed | |||||||
The position_tex_color_normal shader (only used by clouds) has been replaced by 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 | |||||||
24w09a | The menu background dirt texture has been replaced by a post-processing blur shader. | ||||||
24w11a | All unused post-processing shaders that were used for Super Secret Settings have been removed. | ||||||
1.21.2 | 24w34a | Shader 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 shader has been removed (replaced by rendertype_entity_glint ). | |||||||
The rendertype_entity_translucent_cull shader has been removed (replaced by rendertype_item_entity_translucent_cull ). | |||||||
1.21.5 | 25w06a | Added a new shader, rendertype_world_border , which is used to render the world border | |||||
25w07a | Shader 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 resovle 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 matrix4 | |||||||
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 | |||||||
[hide]Java Edition | |||||||
1.21.6 | 25w16a | All 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 core/position_tex.fsh program is now unused as the panorama is now rendered with a new fragment shader, core/panaorama.fsh .
|
Gallery Edit
-
The creeper vision shader
-
The enderman vision shader
-
The spider vision shader
Issues Edit
Issues relating to "Shader" are maintained on the bug tracker. Issues should be reported and viewed there.
References Edit
- ↑ Jump up to: a b MC-46727 (comment #219617)
- ↑ "nah just rewriting it all :p They are still in the game, the button is just gone atm. It would make more sense to keybind imho" – @_grum (Erik Broes) on X (formerly Twitter), July 31, 2015
External links Edit
Edit
[hide] | |||||
---|---|---|---|---|---|
Components |
| ||||
Resource packs |
| ||||
Tutorials |
[hide] | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
|