Minecraft:Shader: Difference between revisions
More actions
Sync: updated from Minecraft |
Sync: updated from Minecraft |
||
| (16 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{About|in-game shaders using [[Minecraft:resource pack]]s|the shaders provided by game modifications|Shader pack|the shaders available in the [[Minecraft:options]] menu before [[Minecraft:Java Edition 1.9]]|Super Secret Settings|the built-in shaders and modern customization in ''Bedrock Edition''|Vibrant Visuals}}{{Exclusive|java}}{{Removed feature|edition=bedrock}}{{wip|Add historical Bedrock Edition 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. Java Edition would benefit from more information about post_effects (specifically vertex shaders before and after 25w31a) and vertex attributes for both post and core shaders}} | {{About|in-game shaders using [[Minecraft:resource pack]]s|the shaders provided by game modifications|Shader pack|the shaders available in the [[Minecraft:options]] menu before [[Minecraft:Java Edition 1.9]]|Super Secret Settings|the built-in shaders and modern customization in ''Bedrock Edition''|Vibrant Visuals}}{{Exclusive|java}}{{Removed feature|edition=bedrock}}{{wip|Add historical Bedrock Edition 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. Java Edition would benefit from more information about post_effects (specifically vertex shaders before and after 25w31a) and vertex attributes for both post and core shaders}} | ||
{{split|Post effect|reason=compiling everything shader-related onto this page makes it bulky and difficult to read. I think that having a smaller, dedicated page specifically for post effects would help with that specifically}} | |||
'''Shaders''' are used to define the game's rendering of certain elements. | '''Shaders''' are used to define the game's rendering of certain elements. | ||
| Line 15: | Line 16: | ||
{{Warning|section=1|Although core shaders can be replaced with a [[Minecraft:resource pack]], this isn't an intended or supported feature and may change at any time.}} | {{Warning|section=1|Although core shaders can be replaced with a [[Minecraft: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, | 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 <code>assets/<namespace>/shaders/core</code> directory of a resource pack. | ||
Some objects are not drawn using shaders, this includes: | Some objects are not drawn using shaders, this includes: | ||
* The sky in the nether and bottom half of the overworld. These are the | * The sky in the nether and bottom half of the overworld. These are the OpenGL clear color which is set to the same value as the <code>FogColor</code> uniform | ||
==== List of core shaders ==== | ==== List of core shaders ==== | ||
| Line 74: | Line 75: | ||
<code>Sampler2</code> - The lightmap. | <code>Sampler2</code> - The lightmap. | ||
|<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. | |<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as <code>0.5</code> for cutout textures, <code>0.1</code> for translucent textures, and not defined for solid textures. | ||
|- | |- | ||
| Line 112: | Line 113: | ||
<code>DissolveMaskSampler</code> - An alpha mask to use when the <code>DISSOLVE</code> define is set. | <code>DissolveMaskSampler</code> - An alpha mask to use when the <code>DISSOLVE</code> define is set. | ||
|<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. | |<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as <code>0.1</code> for cutout and translucent textures, and not defined for solid textures. | ||
<code>APPLY_TEXTURE_MATRIX</code> - Whether or not the uv should be offset by the <code>TextureMat</code> uniform. | <code>APPLY_TEXTURE_MATRIX</code> - Whether or not the uv should be offset by the <code>TextureMat</code> uniform. | ||
| Line 178: | Line 179: | ||
<code>Sampler2</code> - The lightmap. | <code>Sampler2</code> - The lightmap. | ||
|<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. | |<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as <code>0.1</code> for cutout and translucent textures, and not defined for solid textures. | ||
|- | |- | ||
|lightmap | |lightmap | ||
| Line 188: | Line 190: | ||
|<code>LightmapInfo</code> | |<code>LightmapInfo</code> | ||
|None present. | |None present. | ||
|None present. | |||
|- | |||
|oit_composite {{upcoming|je 26.3}} | |||
|Responsible for composisiting OIT coefficients when Improved Transparency is enabled. | |||
Uses the <code>core/screenquad.vsh</code> vertex program. | |||
| | |||
|<code>Projection</code> | |||
|<code>Sampler0</code>{{info needed|what do these samplers contain/what are they used for}} | |||
<code>Sampler2</code> | |||
<code>DepthBoundsSampler</code> | |||
|None present. | |None present. | ||
|- | |- | ||
| Line 279: | Line 296: | ||
|rendertype_beacon_beam | |rendertype_beacon_beam | ||
|Renders the beacon and end gateway beams. | |Renders the beacon and end gateway beams.{{info needed|and test block beams?}} | ||
| | | | ||
[[File:Core shader rendertype beacon beam highlight.png|thumb]] | [[File:Core shader rendertype beacon beam highlight.png|thumb]] | ||
| Line 292: | Line 309: | ||
|rendertype_clouds | |rendertype_clouds (renamed to clouds {{in upcoming|je 26.3}}) | ||
|Renders the clouds. | |Renders the clouds. | ||
| | | | ||
| Line 323: | Line 340: | ||
|rendertype_end_portal | |rendertype_end_portal | ||
|Renders | |Renders [[Minecraft:starfield]] objects | ||
| | | | ||
[[File:Core shader rendertype end portal highlight JE2.png|thumb]] | [[File:Core shader rendertype end portal highlight JE2.png|thumb]] | ||
| Line 492: | Line 509: | ||
|rendertype_world_border | |rendertype_world_border (renamed to world_border {{in upcoming|je 26.3}}) | ||
|Renders the world border. | |Renders the world border. | ||
| | | | ||
| Line 542: | Line 559: | ||
<code>Sampler2</code> - The lightmap. | <code>Sampler2</code> - The lightmap. | ||
|<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. | |<code>ALPHA_CUTOUT</code> - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as <code>0.5</code> for cutout textures, <code>0.1</code> for translucent textures, and not defined for solid textures. | ||
|- | |- | ||
|text_background | |text_background | ||
|Renders text background, for example those seen on entity nameplates or text display entities. | |Renders text background, for example those seen on entity nameplates or text display entities. | ||
| | | | ||
| Line 559: | Line 576: | ||
|text | |text | ||
|Renders text in the world and in GUIs. Also renders maps in item frames or when held in first person. | |Renders text in the world and in GUIs. Also renders maps in item frames or when held in first person. | ||
| | | | ||
| Line 581: | Line 598: | ||
Include shaders (stored in <code>assets/<namespace>/shaders/include</code>) contain helper functions and variables that can be used in multiple shader programs. These must have the <code>.glsl</code>, <code>.vsh</code>, or <code>.fsh</code> file extensions. | Include shaders (stored in <code>assets/<namespace>/shaders/include</code>) contain helper functions and variables that can be used in multiple shader programs. These must have the <code>.glsl</code>, <code>.vsh</code>, or <code>.fsh</code> file extensions. | ||
{{INUntil|je 26.3}}, to import an include shader add one of the following import directives anywhere in a vertex or fragment shader program | |||
* <code>#moj_import <filepath.glsl></code> imports a file from <code>assets/minecraft/shaders/include/<filepath>.glsl</code> | * <code>#moj_import <filepath.glsl></code> imports a file from <code>assets/minecraft/shaders/include/<filepath>.glsl</code> | ||
* <code>#moj_import <namespace:path.glsl></code> imports a file from <code>assets/<namespace>/shaders/include/<path>.glsl</code> | * <code>#moj_import <namespace:path.glsl></code> imports a file from <code>assets/<namespace>/shaders/include/<path>.glsl</code> | ||
* <code>#moj_import "filepath.glsl"</code> imports a file from <code>assets/minecraft/shaders/core/<filepath>.glsl</code> | * <code>#moj_import "filepath.glsl"</code> imports a file from <code>assets/minecraft/shaders/core/<filepath>.glsl</code> | ||
{{INUpcoming|je 26.3}}, to import an include shader you can use the <code>#include</code> directive with an identifier pointing to a shader. For example: | |||
* <code>#include <filepath.glsl></code> imports a file from <code>assets/minecraft/shaders/include/<filepath>.glsl</code> | |||
* <code>#include <namespace:path.glsl></code> imports a file from <code>assets/<namespace>/shaders/include/<path>.glsl</code> | |||
* <code>#include "filepath.glsl"</code> imports a file from <code>assets/minecraft/shaders/core/<filepath>.glsl</code> | |||
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.'' | 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.'' | ||
| Line 620: | Line 642: | ||
| sample_lightmap.glsl | | sample_lightmap.glsl | ||
| Contains the <code>sample_lightmap</code> function, used by various shaders to sample the lightmap texture. | | Contains the <code>sample_lightmap</code> function, used by various shaders to sample the lightmap texture. | ||
|- | |||
| oit.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|- | |||
| oit_add_transmittance.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|- | |||
| oit_common.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|- | |||
| oit_depth_bounds.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|- | |||
| oit_depth_sample.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|- | |||
| oit_sample.glsl {{upcoming|je 26.3}} | |||
| {{info needed|what this contains and what its used for}} | |||
|} | |} | ||
=== Post-processing effects === | === Post-processing effects === | ||
As mentioned previously, post-processing effects are used in menu backgrounds, when spectating certain mobs to create vision effects, the | As mentioned previously, post-processing effects are used in menu backgrounds, when spectating certain mobs to create vision effects, the Improved Transparency graphics setting{{until|je 26.3}}, and when rendering the [[Minecraft:glowing]] effect. Custom post effects can also be defined and displayed using the [[Minecraft:Commands/posteffect|/posteffect]] command.{{upcoming|je 26.3}} | ||
==== Post-effect file format ==== | ==== Post-effect file format ==== | ||
| Line 645: | Line 685: | ||
***** {{nbt | compound | render target input}} | ***** {{nbt | compound | render target input}} | ||
****** {{nbt | string | sampler_name}}: The name of the sampler uniform | ****** {{nbt | string | sampler_name}}: The name of the sampler uniform | ||
******* ''Setting this to <code>MainDepth</code>, for example, makes a sampler2D uniform called <code>MainDepthSampler</code> available to the shader program for this pass. This | ******* ''Setting this to <code>MainDepth</code>, for example, makes a sampler2D uniform called <code>MainDepthSampler</code> available to the shader program for this pass. This also provides an additional vec2 to the <code>SamplerInfo</code> uniform block called <code><sampler_name>Size</code>, for example <code>MainDepthSize</code>'' | ||
****** {{nbt | boolean | bilinear}}: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor | ****** {{nbt | boolean | bilinear}}: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor | ||
****** {{nbt | string | target}}: The name of the target. Can either be a custom target as specified in <code>targets</code> above, or one of the following built in targets: <code>minecraft:main</code>, <code>minecraft:translucent</code>, <code>minecraft:item_entity</code>, <code>minecraft:particles</code>, <code>minecraft:weather</code>, <code>minecraft:clouds</code>, or <code>minecraft:entity_outline</code> | ****** {{nbt | string | target}}: The name of the target. Can either be a custom target as specified in <code>targets</code> above, or one of the following built in targets: <code>minecraft:main</code>, <code>minecraft:translucent</code>, <code>minecraft:item_entity</code>, <code>minecraft:particles</code>, <code>minecraft:weather</code>, <code>minecraft:clouds</code>, or <code>minecraft:entity_outline</code> | ||
| Line 651: | Line 691: | ||
***** {{nbt | compound | texture input}} | ***** {{nbt | compound | texture input}} | ||
****** {{nbt | string | sampler_name}}: The name of the sampler uniform | ****** {{nbt | string | sampler_name}}: The name of the sampler uniform | ||
******* ''Setting this to <code>MyTexture</code>, for example, makes a sampler2D uniform called <code>MyTextureSampler</code> available to the shader program for this pass. This | ******* ''Setting this to <code>MyTexture</code>, for example, makes a sampler2D uniform called <code>MyTextureSampler</code> available to the shader program for this pass. This also provides an additional vec2 to the <code>SamplerInfo</code> uniform block called <code><sampler_name>Size</code>, for example <code>MyTextureSize</code>'' | ||
****** {{nbt | boolean | bilinear}}: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor | ****** {{nbt | boolean | bilinear}}: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor | ||
****** {{nbt | string | location}}: The resource location of the texture. <code>my_namespace:post_texture</code> resolves to <code>assets/my_namespace/textures/effect/post_texture.png</code> | ****** {{nbt | string | location}}: The resource location of the texture. <code>my_namespace:post_texture</code> resolves to <code>assets/my_namespace/textures/effect/post_texture.png</code> | ||
| Line 658: | Line 698: | ||
**** {{nbt | string | output}}: The target to output to. Can either be a custom target as specified in <code>targets</code> above or <code>minecraft:main</code>. ''Note: you cannot read and write to the same target in the same pass'' | **** {{nbt | string | output}}: The target to output to. Can either be a custom target as specified in <code>targets</code> above or <code>minecraft:main</code>. ''Note: you cannot read and write to the same target in the same pass'' | ||
**** {{nbt | compound | uniforms}}: An object of uniform blocks to pass to the vertex and fragment shaders. For example, <code>uniforms: { "UniformBlockName": [ { "type": "vec2", "value": [...] } ] }</code> | **** {{nbt | compound | uniforms}}: An object of uniform blocks to pass to the vertex and fragment shaders. For example, <code>uniforms: { "UniformBlockName": [ { "type": "vec2", "value": [...] } ] }</code> | ||
***** {{nbt | list | uniform block}}: The key is what this uniform block | ***** {{nbt | list | uniform block}}: The key is what this uniform block is called when referenced in a shader | ||
****** {{nbt | compound | uniform definition}} | ****** {{nbt | compound | uniform definition}} | ||
******* {{nbt | string | name}}: The name of the uniform. This is unused by the game, however it is recommended to set it for organizational purposes | ******* {{nbt | string | name}}: The name of the uniform. This is unused by the game, however it is recommended to set it for organizational purposes | ||
| Line 708: | Line 748: | ||
[[File:Post effect spider.png|left|thumb]] | [[File:Post effect spider.png|left|thumb]] | ||
|- | |- | ||
| transparency | | transparency {{until|je 26.3}} | ||
| Combines multiple passes (targets) of different objects in the world | | Combines multiple passes (targets) of different objects in the world. Used when the "Improved Transparency" video setting is enabled. | ||
| | | | ||
<span style="white-space:nowrap;"><!-- | <span style="white-space:nowrap;"><!-- | ||
| Line 723: | Line 763: | ||
--><span style="display:inline-block;">[[File:Post effect transparency.png|left|thumb|Final image]]</span><!-- | --><span style="display:inline-block;">[[File:Post effect transparency.png|left|thumb|Final image]]</span><!-- | ||
--></span> | --></span> | ||
|- | |||
| end_of_frame | |||
| Runs after the world is rendered and before the gui and other post effects {{info needed|Does this include the hand and other '3d gui' elements}}. By default this post effect is unused, however a resourcepack can define it in which case it cannot be disabled in any way besides removing the resourcepack again. | |||
|} | |} | ||
| Line 738: | Line 781: | ||
* 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 <code>oversized_in_gui</code> field is set to true or false in the [[Minecraft:items model definition]]. For entities, each one always has a unique texture that it gets rendered to | * 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 <code>oversized_in_gui</code> field is set to true or false in the [[Minecraft: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 | * 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 necessary and | The game can skip rendering an item when necessary and uses 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 animated texture somewhere on its model | ||
* The item has an enchantment glint | * The item has an enchantment glint | ||
| Line 749: | Line 792: | ||
{{Warning|section=1|Using uniform blocks outside supported shaders may work in some cases, however this is undefined behavior and may cause unexpected results or crashes. Refer to [[#List of core shaders|the list of core shaders]] for more info}} | {{Warning|section=1|Using uniform blocks outside supported shaders may work in some cases, however this is undefined behavior and may cause unexpected results or crashes. Refer to [[#List of core shaders|the list of core shaders]] for more info}} | ||
Uniforms blocks use the [https://ptgmedia.pearsoncmg.com/images/9780321552624/downloads/0321552628_AppL.pdf std140 layout]. All uniforms must be specified and in the correct order and with the correct type, otherwise weird and undefined behavior | Uniforms blocks use the [https://ptgmedia.pearsoncmg.com/images/9780321552624/downloads/0321552628_AppL.pdf std140 layout]. All uniforms must be specified and in the correct order and with the correct type, otherwise weird and undefined behavior occurs. For convenience, some uniform blocks are pre-defined in include shaders, see the [[#Include_shaders|include shaders]] section for more information. | ||
Some shaders may not use all uniforms in a given uniform block, in this case the unused uniforms | Some shaders may not use all uniforms in a given uniform block, in this case the unused uniforms have a 'default' value. For example, while the <code>rendertype_lines</code> core shader has the proper value for the <code>LineWidth</code> uniform, other shaders have a "default value" that is unlikely to be useful. | ||
==== Common blocks ==== | ==== Common blocks ==== | ||
| Line 762: | Line 805: | ||
* (vec2) <code>ScreenSize</code> The width and height of the current framebuffer in pixels. | * (vec2) <code>ScreenSize</code> The width and height of the current framebuffer in pixels. | ||
* (float) <code>GlintAlpha</code> The value of the Glint Strength accessibility setting in a 0-1 range. | * (float) <code>GlintAlpha</code> The value of the Glint Strength accessibility setting in a 0-1 range. | ||
* (float) <code>GameTime</code> 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 <code>(<age of the world> modulo 24000) / 24000 | * (float) <code>GameTime</code> 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 <code>(<age of the world> modulo 24000) / 24000</code>. | ||
* (int) <code>MenuBlurRadius</code> The value of the Menu Background Blur accessibility setting in a 0-10 range. | * (int) <code>MenuBlurRadius</code> The value of the Menu Background Blur accessibility setting in a 0-10 range. | ||
* (int) <code>UseRgss</code> A "boolean" value. Value is 1 if the [[Minecraft:Options#Video_Settings|texture filtering video setting]] is set to RGSS, otherwise 0. | * (int) <code>UseRgss</code> A "boolean" value. Value is 1 if the [[Minecraft:Options#Video_Settings|texture filtering video setting]] is set to RGSS, otherwise 0. | ||
| Line 844: | Line 887: | ||
== History == | == History == | ||
{{info needed section| | |||
* 21w11a end portal changes | |||
* during development, before linear blur, 1.20.5 used box blur. how did this differ in definition and in visual outcome? and when did turning the slider to off get rid of the shader entirely rather than just make it have no visual effect?}} | |||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|java}} | |{{HistoryLine|java}} | ||
|{{HistoryLine||1.7.2|dev=13w38a | |{{HistoryLine||1.7.2|dev=13w38a | ||
| | |Post-processing shaders were added, accessible via the [[Minecraft:Super Secret Settings]] button. | ||
}} | }} | ||
|{{HistoryLine||1.8|dev=14w05a | |{{HistoryLine||1.8|dev=14w05a | ||
|The | |The {{code|creeper}} and {{code|spider}} shaders were added. Shaders are automatically applied in [[Minecraft:spectator]] mode when viewing the world as a [[Minecraft:creeper]], [[Minecraft:spider]], [[Minecraft:cave spider]] or [[Minecraft:enderman]]. | ||
}} | }} | ||
|{{HistoryLine|||dev=14w05b | |{{HistoryLine|||dev=14w05b | ||
| Line 856: | Line 902: | ||
}} | }} | ||
|{{HistoryLine|||dev=14w06a | |{{HistoryLine|||dev=14w06a | ||
|The <code>entity_outline</code> post effect shader was added. | |The <code>entity_outline</code> post effect shader was added for the [[Minecraft:glowing]] effect. | ||
}} | }} | ||
|{{HistoryLine||1.9|dev=15w31a | |{{HistoryLine||1.9|dev=15w31a | ||
| Line 863: | Line 909: | ||
|{{HistoryLine||1.16|dev=20w22a | |{{HistoryLine||1.16|dev=20w22a | ||
|The <code>transparency</code> post effect shader was added for ''Fabulous!'' graphics mode. | |The <code>transparency</code> post effect shader was added for ''Fabulous!'' graphics mode. | ||
}} | |||
|{{HistoryLine||1.15|dev=19w41a | |||
|Something about the shader for glowing entities has changed allowing for atlases to be passed to them, allowing for [https://discord.com/channels/154777837382008833/157097006500806656/634263809342570506 this resource pack] to work. | |||
}} | }} | ||
|{{HistoryLine||1.17|dev=21w10a | |{{HistoryLine||1.17|dev=21w10a | ||
| Line 880: | Line 929: | ||
}} | }} | ||
|{{HistoryLine||1.19|dev=22w12a | |{{HistoryLine||1.19|dev=22w12a | ||
|There are now shader files for translucent entity rendering. | |There are now shader files for translucent entity rendering.{{info needed|elaborate on this, im sure there were more changed made in 1.19 too}} | ||
}} | }} | ||
|{{HistoryLine||1.20.5|dev=24w05a | |{{HistoryLine||1.20.5|dev=24w05a | ||
| Line 897: | Line 946: | ||
|{{HistoryLine||1.21.2|dev=24w34a | |{{HistoryLine||1.21.2|dev=24w34a | ||
|Shader program configurations can now specify preprocessor define directives to apply to their linked shaders. | |Shader program configurations can now specify preprocessor define directives to apply to their linked shaders. | ||
|The format of | |Various individual shader programs have been merged into one with the shader program configuration files defining preprocessor directives for specific behaviour. For example the <code>core/rendertype_solid.json</code>, <code>core/rendertype_translucent.json</code>, <code>core/rendertype_cutout.json</code>, <code>core/rendertype_cutout_mipped.json</code>, and <code>core/rendertype_tripwire.json</code> program configurations all point to the <code>core/terrain</code> fragment and vertex programs, with some defining an <code>ALPHA_CUTOUT</code> directive. | ||
|The <code>fragment</code> and <code>vertex</code> fields in shader program configurations can now include a [[Minecraft:identifier#namespace|namespaces]] instead of being hardcoded to <code>minecraft</code>. Additionally, the paths are now relative to the <code>assets/namespace/shaders/</code> directory instead of <code>assets/minecraft/shaders/core/</code>. | |||
|The format of post-processing effects has changed and are now located under the <code>assets/namespace/post_effects/</code> directory. | |||
|The <code>rendertype_entity_glint_direct</code> core shader has been removed and replaced by <code>rendertype_entity_glint</code>. | |The <code>rendertype_entity_glint_direct</code> core shader has been removed and replaced by <code>rendertype_entity_glint</code>. | ||
|The <code>rendertype_entity_translucent_cull</code> shader has been removed and replaced by <code>rendertype_item_entity_translucent_cull</code>. | |The <code>rendertype_entity_translucent_cull</code> shader has been removed and replaced by <code>rendertype_item_entity_translucent_cull</code>. | ||
|The <code>ChunkOffset</code> uniform has been renamed to <code>ModelOffset</code>. | |||
| | |||
}} | }} | ||
|{{HistoryLine|||dev=? | |{{HistoryLine|||dev=? | ||
| Line 922: | Line 968: | ||
|In post-processing effects, the field <code>program</code> was replaced with <code>vertex_shader</code> and <code>fragment_shader</code> which resolve to <code>assets/<namespace>/shaders/<path>.<vsh or fsh></code> | |In post-processing effects, the field <code>program</code> was replaced with <code>vertex_shader</code> and <code>fragment_shader</code> which resolve to <code>assets/<namespace>/shaders/<path>.<vsh or fsh></code> | ||
|In post-processing effects, <code>type</code> is now a required field for each <code>uniform</code>, with the possible values being <code>int</code>, <code>ivec3</code>, <code>float</code>, <code>vec2</code>, <code>vec3</code>, <code>vec4</code> and <code>matrix4x4</code> | |In post-processing effects, <code>type</code> is now a required field for each <code>uniform</code>, with the possible values being <code>int</code>, <code>ivec3</code>, <code>float</code>, <code>vec2</code>, <code>vec3</code>, <code>vec4</code> and <code>matrix4x4</code> | ||
|In post-processing effects, the <code>values</code> field is now option for each <code>uniform</code>. Leaving it unset is not recommended | |In post-processing effects, the <code>values</code> field is now option for each <code>uniform</code>. Leaving it unset is not recommended because this results in undefined behavior. Leaving it unset is only used for runtime configuration of the blur post-processing effect in the vanilla rendering | ||
|The <code>EndPortalLayers</code> uniform has been removed and replaced by a pre-processor define called <code>PORTAL_LAYERS</code>}} | |The <code>EndPortalLayers</code> uniform has been removed and replaced by a pre-processor define called <code>PORTAL_LAYERS</code>}} | ||
|{{HistoryLine|||dev=25w10a | |{{HistoryLine|||dev=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 behavior | |"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 behavior occurs | ||
|Currently, the "global" uniforms are: <code>ModelViewMat</code>, <code>ProjMat</code>, <code>TextureMat</code>, <code>ScreenSize</code>, <code>ColorModulator</code>, <code>Light0_Direction</code>, <code>Light1_Direction</code>, <code>GlintAlpha</code>, <code>FogStart</code>, <code>FogEnd</code>, <code>FogColor</code>, <code>FogShape</code>, <code>LineWidth</code>, <code>GameTime</code>, and <code>ModelOffset</code> | |Currently, the "global" uniforms are: <code>ModelViewMat</code>, <code>ProjMat</code>, <code>TextureMat</code>, <code>ScreenSize</code>, <code>ColorModulator</code>, <code>Light0_Direction</code>, <code>Light1_Direction</code>, <code>GlintAlpha</code>, <code>FogStart</code>, <code>FogEnd</code>, <code>FogColor</code>, <code>FogShape</code>, <code>LineWidth</code>, <code>GameTime</code>, and <code>ModelOffset</code>. ''Note that this is not the same as the <code>Globals</code> uniform block added in 1.21.6, these are individual uniforms that must be declared individually. There is also no <code>globals.glsl</code> include shader which was also added in 1.21.6'' | ||
}} | }} | ||
|{{HistoryLine||1.21.6|dev=25w16a | |{{HistoryLine||1.21.6|dev=25w16a | ||
| Line 966: | Line 1,012: | ||
|Minor change to uv calculations in the <code>minecraft_sample_lightmap</code> function in the <code>core/terrain.vsh</code> program. | |Minor change to uv calculations in the <code>minecraft_sample_lightmap</code> function in the <code>core/terrain.vsh</code> program. | ||
}} | }} | ||
|{{HistoryLine|||dev=25w37a|The <code>core/entity</code> shader can now have a <code>PER_FACE_LIGHTING</code> flag. When set, cardinal lighting | |{{HistoryLine|||dev=25w37a|The <code>core/entity</code> shader can now have a <code>PER_FACE_LIGHTING</code> flag. When set, cardinal lighting is computed separately for front and back faces of each quad. | ||
|The game now requires OpenGL 3.3 Core Profile. | |The game now requires OpenGL 3.3 Core Profile. | ||
|Upgraded all shader programs from glsl version <code>150</code> to <code>330</code> | |Upgraded all shader programs from glsl version <code>150</code> to <code>330</code> | ||
| Line 992: | Line 1,038: | ||
}} | }} | ||
|{{HistoryLine||26.1|dev= | |{{HistoryLine||26.1|dev=snap1 | ||
|The <code>core/lightmap.fsh</code> shader has been mostly rewritten | |The <code>core/lightmap.fsh</code> shader has been mostly rewritten | ||
|Added two new uniforms to the <code>LightmapInfo</code> uniform block: <code>vec3 BlockLightTint</code> and <code>vec3 NightVisionColor</code>. | |Added two new uniforms to the <code>LightmapInfo</code> uniform block: <code>vec3 BlockLightTint</code> and <code>vec3 NightVisionColor</code>. | ||
| Line 999: | Line 1,045: | ||
|Added a new <code>include/smooth_lighting.glsl</code> shader. Contains a function called <code>minecraft_sample_lightmap</code> used by various shaders to sample the lightmap texture. | |Added a new <code>include/smooth_lighting.glsl</code> shader. Contains a function called <code>minecraft_sample_lightmap</code> used by various shaders to sample the lightmap texture. | ||
}} | }} | ||
|{{HistoryLine|||dev= | |{{HistoryLine|||dev=snap5 | ||
|Various shaders now sample the lightmap texture using the <code>texture</code> function instead of <code>texelFetch</code>. This includes <code>core/entity.vsh</code>, <code>core/rendertype_entity_decal.vsh</code>, <code>core/rendertype_item_entity_translucent_cull.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, and <code>core/rendertype_translucent_moving_block.vsh</code>. | |Various shaders now sample the lightmap texture using the <code>texture</code> function instead of <code>texelFetch</code>. This includes <code>core/entity.vsh</code>, <code>core/rendertype_entity_decal.vsh</code>, <code>core/rendertype_item_entity_translucent_cull.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, and <code>core/rendertype_translucent_moving_block.vsh</code>. | ||
}} | }} | ||
|{{HistoryLine|||dev= | |{{HistoryLine|||dev=snap6 | ||
|The <code>core/rendertype_item_entity_translucent_cull</code> shader has been removed, most things that were previously handled by this shader are now handled by <code>core/entity</code>. | |The <code>core/rendertype_item_entity_translucent_cull</code> shader has been removed, most things that were previously handled by this shader are now handled by <code>core/entity</code>. | ||
|The <code>core/rendertype_entity_alpha</code> and <code>core/rendertype_entity_decal</code> shaders have been removed and replaced by a <code>DISSOLVE</code> define directive in <code>core/entity</code> | |The <code>core/rendertype_entity_alpha</code> and <code>core/rendertype_entity_decal</code> shaders have been removed and replaced by a <code>DISSOLVE</code> define directive in <code>core/entity</code> | ||
|All item models are now rendered using a new <code>core/item</code> shader instead of <code>core/entity</code>, with the exception of special model renderers which still use <code>core/entity</code> | |All item models are now rendered using a new <code>core/item</code> shader instead of <code>core/entity</code>, with the exception of special model renderers which still use <code>core/entity</code> | ||
}} | }} | ||
|{{HistoryLine|||dev= | |{{HistoryLine|||dev=snap7 | ||
|The <code>core/terrain.vsh</code> and <code>core/block.vsh</code> shaders no longer have the <code>Normal</code> vertex attribute | |The <code>core/terrain.vsh</code> and <code>core/block.vsh</code> shaders no longer have the <code>Normal</code> vertex attribute | ||
|Some small changes were to how various shaders sample the lightmap texture. This includes <code>core/entity.vsh</code>, <code>core/item.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, and <code>core/rendertype_translucent_moving_block.vsh</code>. | |Some small changes were to how various shaders sample the lightmap texture. This includes <code>core/entity.vsh</code>, <code>core/item.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, and <code>core/rendertype_translucent_moving_block.vsh</code>. | ||
}} | }} | ||
|{{HistoryLine|||dev= | |{{HistoryLine|||dev=snap10 | ||
|The <code>include/smooth_lighting.glsl</code> shader has been removed and replaced by a new <code>include/sample_lightmap.glsl</code> shader. This contains a function called <code>sample_lightmap</code> used by various shaders to sample the lightmap texture. | |The <code>include/smooth_lighting.glsl</code> shader has been removed and replaced by a new <code>include/sample_lightmap.glsl</code> shader. This contains a function called <code>sample_lightmap</code> used by various shaders to sample the lightmap texture. | ||
|The following shaders; <code>core/block.vsh</code>, <code>core/entity.vsh</code>, <code>core/item.vsh</code>, <code>core/particle.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, <code>core/rendertype_translucent_moving_block.vsh</code>, and <code>core/terrain.vsh</code>, now sample the lightmap texture using the helper function declared in <code>include/sample_lightmap.glsl</code>. | |The following shaders; <code>core/block.vsh</code>, <code>core/entity.vsh</code>, <code>core/item.vsh</code>, <code>core/particle.vsh</code>, <code>core/rendertype_leash.vsh</code>, <code>core/rendertype_text.vsh</code>, <code>core/rendertype_text_background.vsh</code>, <code>core/rendertype_text_intensity.vsh</code>, <code>core/rendertype_translucent_moving_block.vsh</code>, and <code>core/terrain.vsh</code>, now sample the lightmap texture using the helper function declared in <code>include/sample_lightmap.glsl</code>. | ||
|<code>core/rendertype_crumbling.vsh</code> no longer defines a varying named <code>texCoord2</code> | |<code>core/rendertype_crumbling.vsh</code> no longer defines a varying named <code>texCoord2</code> | ||
}} | }} | ||
|{{HistoryLine|||dev= | |{{HistoryLine|||dev=pre1 | ||
|The <code>core/rendertype_translucent_moving_block</code> shaders have been removed. Objects which were previously rendered by this shader are now handled by <code>core/block</code> | |The <code>core/rendertype_translucent_moving_block</code> shaders have been removed. Objects which were previously rendered by this shader are now handled by <code>core/block</code> | ||
}} | }} | ||
|{{HistoryLine||26.2|dev=snap1 | |||
|The game now uses a reversed depth buffer. The <code>post/transparency.fsh</code> shader has had its depth logic reversed to account for this. | |||
|{{HistoryLine||26.2|dev= | |||
|The <code>core/rendertype_text</code>, <code>core/rendertype_text_see_through</code>, <code>core/rendertype_text_intensity</code>, and <code>core/rendertype_text_intensity_see_through</code> shaders have been merged into new <code>core/text</code> shaders. Three defines are available for handling variants of text; <code>IS_GUI</code>, <code>IS_SEE_THROUGH</code>, and <code>IS_GRAYSCALE</code>. | |The <code>core/rendertype_text</code>, <code>core/rendertype_text_see_through</code>, <code>core/rendertype_text_intensity</code>, and <code>core/rendertype_text_intensity_see_through</code> shaders have been merged into new <code>core/text</code> shaders. Three defines are available for handling variants of text; <code>IS_GUI</code>, <code>IS_SEE_THROUGH</code>, and <code>IS_GRAYSCALE</code>. | ||
|The <code>core/rendertype_text_background</code> and <code>core/rendertype_text_background_see_through</code> shaders have been merged into new <code>core/text_background</code> shaders. The <code>IS_SEE_THROUGH</code> define is availble for handling see-through backgrounds. | |The <code>core/rendertype_text_background</code> and <code>core/rendertype_text_background_see_through</code> shaders have been merged into new <code>core/text_background</code> shaders. The <code>IS_SEE_THROUGH</code> define is availble for handling see-through backgrounds. | ||
|When the games graphics api is set to Vulkan, some minor pre-processing is now done to shaders. Notably, <code>gl_VertexID</code> is replaced with <code>gl_VertexIndex</code> and <code>gl_InstanceID</code> is replaced with <code>gl_InstanceIndex</code>. | |When the games graphics api is set to Vulkan, some minor pre-processing is now done to shaders. Notably, <code>gl_VertexID</code> is replaced with <code>gl_VertexIndex</code> and <code>gl_InstanceID</code> is replaced with <code>gl_InstanceIndex</code>. | ||
|This snapshot has a bug which prevents the game from loading any shaders from resourcepack after the initial resource load. This only applies when the graphics api is set to Vulkan. | |The <code>core/rendertype_crumbling.vsh</code> no longer has a <code>vec3 Normal</code> vertex attribute. | ||
|The <code>core/item</code> shaders have been updated slightly. The item pipelines now have an overlay texture similar to entity pipelines; <code>sampler2d Sampler1</code>. The vertex program now defines two varyings <code>vec4 lightMapColor</code> and <code>vec4 overlayColor</code>. These are then mixed and multiplied onto the base texture color in the fragment program. | |||
|The <code>core/entity.vsh</code> shader no longer imports the <code>minecraft:light.glsl</code> include when both <code>PER_FACE_LIGHTING</code> and <code>NO_CARDINAL_LIGHTING</code> are not defined. | |||
|This snapshot has a bug which prevents the game from loading any shaders from resourcepack after the initial resource load. This only applies when the graphics api is set to Vulkan {{bug|MC-307311}}. | |||
}} | |||
|{{HistoryLine|||dev=snap2 | |||
|{{bug|MC-307311}} has been fixed, allowing shaders to be loaded from resourcepacks properly again. | |||
|The <code>core/rendertype_beacon_beam.fsh</code> has been updated slightly to account for the reversed depth buffer, as it was missed in 26.1-snapshot-1. | |||
}} | |||
|{{HistoryLine|||dev=pre3 | |||
|The <code>ALPHA_CUTOUT</code> define in the <code>core/terrain</code> shader is now defined as <code>0.1</code> for translucent quads instead of <code>0.01</code> as a fix for {{bug|MC-308245}} | |||
}} | |||
|{{HistoryLine|upcoming java}} | |||
|{{HistoryLine||26.3|dev=snap2|Replaced old "Improved Transparency" approach with a new Order-independent Transparency (OIT) algorithm which is expected to be much better at solving translucency issues. | |||
|The <code>transparency</code> post effect and <code>post/transparency.fsh</code> shader have been removed. | |||
|Added new includes with various utilities for OIT <code>include/oit.glsl</code>, <code>include/oit_add_transmittance.glsl</code>, <code>include/oit_common.glsl</code>, <code>include/oit_depth_bounds.glsl</code>, <code>include/oit_depth_sample.glsl</code>, and <code>include/oit_sample.glsl</code>. | |||
|Added a <code>core/oit_composite.fsh</code> shader responsible for normalising and outputting accumulated rgb values when OIT is enabled. | |||
|Various new defines have been added to support OIT: | |||
* <code>OIT</code> - A boolean indicating if OIT is enabled | |||
* <code>OIT_DEPTH_BOUNDS</code> - A boolean indicating if the depth bounds pass is being executed | |||
* <code>OIT_TRANSMITTANCE</code> - A boolean indicating if the transmittance pass is being executed | |||
* <code>OIT_ACCUMULATE</code> - A boolean indicating if the accumulate pass is being executed | |||
* <code>OIT_ALPHA_ONLY</code> - A boolean indicating if either the depth bounds or transmittance pass is being executed | |||
* <code>OIT_ADDITIVE</code> - A boolean indicating that the OIT algorithm should emulate additive blending for the executing pipeline | |||
* <code>OIT_OPAQUE_PARTS_THRESHOLD</code> - A float determining above which alpha threshold a fragment should be considered solid and not go through OIT | |||
* <code>WAVELET_RANK</code> - An integer internal to the OIT algorithm | |||
* <code>COEFF_COUNT</code> - An integer internal to the OIT algorithm | |||
* <code>COEFF_ATTACHMENT_COUNT</code> - An integer internal to the OIT algorithm | |||
As a result of this, many core shaders have been updated to make use of these for OIT including: | |||
* <code>core/block.fsh</code> | |||
* <code>core/block.vsh</code> | |||
* <code>core/clouds.fsh</code> | |||
* <code>core/clouds.vsh</code> | |||
* <code>core/entity.fsh</code> | |||
* <code>core/entity.vsh</code> | |||
* <code>core/item.fsh</code> | |||
* <code>core/item.vsh</code> | |||
* <code>core/particle.fsh</code> | |||
* <code>core/position_color.fsh</code> | |||
* <code>core/rendertype_beacon_beam.fsh</code> | |||
* <code>core/rendertype_crumbling.fsh</code> | |||
* <code>core/rendertype_entity_shadow.fsh</code> | |||
* <code>core/rendertype_lightning.fsh</code> | |||
* <code>core/rendertype_lines.fsh</code> | |||
* <code>core/terrain.fsh</code> | |||
* <code>core/terrain.vsh</code> | |||
* <code>core/text.fsh</code> | |||
* <code>core/text_background.fsh</code> | |||
* <code>core/world_border.fsh</code> | |||
* <code>core/world_border.vsh</code> | |||
|Added a new <code>B3D_IS_ZERO_TO_ONE</code> define - A boolean indicating if the current rendering backend uses the depth range of [0, 1], it is available globally to all shaders | |||
|Extracted the texture sampling logic from <code>core/terrain.fsh</code> into a new <code>include/texture_sampling.glsl</code> include shader. | |||
|Renamed <code>core/rendertype_clouds</code> shaders to <code>core/clouds</code> | |||
|Renamed <code>core/rendertype_world_border</code> shaders to <code>core/world_border</code> | |||
}} | |||
|{{HistoryLine|||dev=snap3|Added a new {{cd|minecraft:end_of_frame}} post effect. When defined by a resourcepack this post effect runs after the world and before the gui and other post effects. It cannot be disabled in any way other than removing the resourcepack | |||
|Added a way to display custom post effects with a new [[Minecraft:Commands/posteffect|/posteffect]] command | |||
}} | |||
|{{HistoryLine|||dev=snap4|Added a new shader for OIT: <code>core/oit_depth_bounds_cull.fsh</code>. | |||
|Various OIT-related include shaders have been uptated slightly. As a result of this, <code>core/entity.fsh</code> and <code>core/item.fshM</code> no longer call the <code>handleOpaquePartDiscards(float)</code> function. | |||
|Added a new define for OIT; <code>OIT_ALWAYS_WRITE_DEPTH</code> - A boolean indicating that the OIT algorithm should always write depth for the executing pipeline during the depth bounds stage | |||
|Added a new <code>core/integrate_depth.fsh</code> shader that is used to integrate the "3d hud" and always-on-top gizmo depth buffers into the main depth buffer. | |||
}} | |||
|{{HistoryLine|||dev=snap5|On OpenGL, shaders are now compiled using ShaderC, identically to Vulkan. This means shader compilation on OpenGL is more strict in some cases, for example, the <code>#version</code> define ''must'' be the first line of a shader | |||
|Shader includes are now handled by ShaderC using <code>#include</code> instead of <code>#moj_import</code> | |||
|Shader <code>in</code>s and <code>out</code>s now require a location to be specified, so that the <code>GL_ARB_separate_shader_objects</code> extension must now be enabled for compilation. Vertex input names must still match expected names. Vertex outputs are matched to fragment inputs solely by location, the name is now ignored. | |||
}} | }} | ||
Latest revision as of 11:12, 26 July 2026
|
For the {{{Description}}} of the same name, see [[{{{Destination}}}]]. |
Template:ExclusiveTemplate:Removed featureTemplate:Wip Template:Split
Shaders are used to define the game's rendering of certain elements.
Java Edition
Template:In, two distinct kinds of shaders are used: core shaders and post-processing shaders. Core shaders are used to render fundamental parts of the game such as entities and terrain, while post-processing shaders are used to apply visual effects to the screen after core shaders have ran.
Examples of post-processing shaders include the menu background blur, certain mob vision types as seen in Minecraft:spectator, the Fabulous! Minecraft:graphics setting's fixed handling of translucent object, and the Minecraft:glowing status effect.
Shaders are written in the OpenGL Shading Language (GLSL). Each shader programTemplate:Note comes in two parts, the vertex and fragment shader. Vertex shaders define the positions of individual vertices, whereas fragment shaders define the final color of a single render fragment. 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 Template:Code, and fragment shaders Template:Code.
Shader programs are stored in the Template:Code directory of Minecraft:client.jar, and can be replaced with a Minecraft: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
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 resource pack.
Some objects are not drawn using shaders, this includes:
- The sky in the nether and bottom half of the overworld. These are the OpenGL clear color which is set to the same value as the
FogColoruniform
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.
| Name | Used for | Sample images | Available uniforms blocks | Available samplers.
All samplers are of type |
Define directives |
|---|---|---|---|---|---|
| animate_sprite_blit | Renders non-interpolated texture animations, as well as any non-animated sprite to a texture atlas.
Uses the |
SpriteAnimationInfo
|
Sprite - The next animation frame
|
None present. | |
| animate_sprite_interpolate | Renders interpolated texture animations to a texture atlas.
Uses the |
SpriteAnimationInfo
|
CurrentSprite - The current animation frame
|
None present. | |
| blit_screen | Copies one buffer to another. Used for the Minecraft:Glowing effect.
Uses the |
None present. | Sampler0 - The buffer to copy from.
|
None present. | |
| block | Renders blocks that aren't part of chunk meshes such as falling sand, blocks being moved by a piston, or pistons while moving a block. Template:Info needed | DynamicTransforms
|
Sampler0 - The blocks atlas.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as 0.5 for cutout textures, 0.1 for translucent textures, and not defined for solid textures.
| |
| debug_point | Used for some debug renderers Template:Info needed
Uses the |
DynamicTransforms
|
None present. | None present. | |
| entity | Renders most entities including but not limited to:
|
DynamicTransforms
|
Sampler0 - The base texture of the entity.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as 0.1 for cutout and translucent textures, and not defined for solid textures.
| |
| glint | Renders the enchantment glint on items, equipment, etc. | DynamicTransforms
|
Sampler0 - The enchantment glint texture.
|
None present. | |
| gui | Renders flat colored gui elements including but not limited to:
|
DynamicTransforms
|
None present. | None present. | |
| item | Renders item models in various contexts, such as when dropped on the ground, held in an entities hand, in a display entity, etc | DynamicTransforms
|
Sampler0 - The items or blocks atlas depending on the model currently being rendered.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as 0.1 for cutout and translucent textures, and not defined for solid textures.
| |
| lightmap | Renders the lightmap which is used by other shaders to determine how bright or dark parts of the world should be.
Uses the |
LightmapInfo
|
None present. | None present. | |
| oit_composite Template:Upcoming | Responsible for composisiting OIT coefficients when Improved Transparency is enabled.
Uses the |
Projection
|
Sampler0Template:Info needed
|
None present. | |
| panorama | Renders the title screen panorama cubemap. |
|
DynamicTransforms
|
Sampler0 (samplerCube) - A cubemap sampler containing all 6 panorama images.
|
None present. |
| particle | Renders all particle effects. Also renders the rain and snow weather effects. |
|
DynamicTransforms
|
Sampler0 - The particles or blocks atlas, depending on the particle that is being rendered. If rendering a weather effect then this is the corresponding texture for that effect.
|
None present. |
| position_color | Renders the lower half of the sky at sunrise and sunset. Also renders the F3 debug pie and chunk borders. |
|
DynamicTransforms
|
None present. | None present. |
| position_tex_color | Renders some miscellaneous textured things including but not limited to:
|
|
DynamicTransforms
|
Sampler0 - For most gui widgets and icons, this is the gui atlas. For world, resourcepack, etc icons, mojang logo, camera overlays, or other non-gui things this is the texture of the object being rendered.
|
None present. |
| position_tex | Renders celestial bodies including the sun, moon, and end flashes. | DynamicTransforms
|
Sampler0 - The celestials atlas
|
None present. | |
| position | Handles depth for the ender dragon's death raysTemplate:Info needed. | DynamicTransforms
|
None present. | None present. | |
| rendertype_beacon_beam | Renders the beacon and end gateway beams.Template:Info needed |
|
DynamicTransforms
|
Sampler0 - The texture of the current part of the beam being rendered.
|
None present. |
| rendertype_clouds (renamed to clouds Template:In upcoming) | Renders the clouds. |
|
CloudInfo
|
CloudFaces (isamplerBuffer) - Data about cloud facesTemplate:Info needed
|
None present. |
| rendertype_crumbling | Renders the block breaking animation. |
|
DynamicTransforms
|
Sampler0 - The texture for current stage of the block breaking animation.
|
None present |
| rendertype_end_portal | Renders Minecraft:starfield objects |
|
DynamicTransforms
|
Sampler0 - The end sky texture textures/environment/end_sky.png.
|
PORTAL_LAYERS - The amount of star layers to render.
|
| rendertype_entity_shadow | Renders the shadow that appears under most entities. |
|
DynamicTransforms
|
Sampler0 - The shadow texture textures/misc/shadow.png.
|
None present. |
| rendertype_leash | Renders leads that are attached to entities in the world. |
|
DynamicTransforms
|
Sampler2 - The lightmap.
|
None present. |
| rendertype_lightning | Renders lightning bolts and the ender dragon's death rays. |
|
DynamicTransforms
|
None present. | None present. |
| rendertype_lines | Renders all types of lines including:
|
|
DynamicTransforms
|
None present. | None present. |
| rendertype_outline | Renders a flat colored outline of entities which have the glowing effect.
The color 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 |
|
DynamicTransforms
|
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. |
|
DynamicTransforms
|
None present. | None present. |
| rendertype_text_background | Renders the background of text display entities that are not set to render through blocks. |
|
DynamicTransforms
|
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. |
|
DynamicTransforms
|
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. |
|
DynamicTransforms
|
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_water_mask | A mask used to hide water inside boats. |
|
DynamicTransforms
|
None present. | None present. |
| rendertype_world_border (renamed to world_border Template:In upcoming) | Renders the world border. |
|
DynamicTransforms
|
Sampler0 - The world border texture textures/misc/forcefield.png.
|
None present. |
| sky | Renders the upper half of the overworld skybox. |
|
DynamicTransforms
|
None present. | None present. |
| stars | Renders the stars in the overworld sky at night. |
|
DynamicTransforms
|
None present. | None present. |
| terrain | Renders all blocks and fluids in the world. |
|
ChunkSection
|
Sampler0 - The blocks atlas.
|
ALPHA_CUTOUT - Minimum opacity before pixels are discarded, if not defined no pixels get discarded. This is defined as 0.5 for cutout textures, 0.1 for translucent textures, and not defined for solid textures.
|
| text_background | Renders text background, for example those seen on entity nameplates or text display entities. | DynamicTransforms
|
Sampler2 - The lightmap
|
IS_SEE_THROUGH - Defined if the shader has no depth test and can be seen through other objects.
| |
| text | Renders text in the world and in GUIs. Also renders maps in item frames or when held in first person. | DynamicTransforms
|
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.
|
IS_GRAYSCALE - Defined if the shader should treat the font texture as an intensity texture for TTF font rendering.
|
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.
Template:INUntil, 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/shaders/core/<filepath>.glsl
Template:INUpcoming, to import an include shader you can use the #include directive with an identifier pointing to a shader. For example:
#include <filepath.glsl>imports a file fromassets/minecraft/shaders/include/<filepath>.glsl#include <namespace:path.glsl>imports a file fromassets/<namespace>/shaders/include/<path>.glsl#include "filepath.glsl"imports a file fromassets/minecraft/shaders/core/<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.
|
| chunksection.glsl | Contains a definition of the ChunkSection uniform block.
|
| animation_sprite.glsl | Contains a definition of the SpriteAnimationInfo uniform block.
|
| sample_lightmap.glsl | Contains the sample_lightmap function, used by various shaders to sample the lightmap texture.
|
| oit.glsl Template:Upcoming | Template:Info needed |
| oit_add_transmittance.glsl Template:Upcoming | Template:Info needed |
| oit_common.glsl Template:Upcoming | Template:Info needed |
| oit_depth_bounds.glsl Template:Upcoming | Template:Info needed |
| oit_depth_sample.glsl Template:Upcoming | Template:Info needed |
| oit_sample.glsl Template:Upcoming | Template:Info needed |
Post-processing effects
As mentioned previously, post-processing effects are used in menu backgrounds, when spectating certain mobs to create vision effects, the Improved Transparency graphics settingTemplate:Until, and when rendering the Minecraft:glowing effect. Custom post effects can also be defined and displayed using the /posteffect command.Template:Upcoming
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
- Template:Nbt: The root tag
- Template:Nbt: Custom render targets to be used by render passes
- Template:Nbt: The key is the name of the target
- Template:Nbt: Defaults to the current viewport width. The width of the target
- Template:Nbt: Defaults to the current viewport height. The height of the target
- Template:Nbt: Defaults to false. If true, this target is not cleared between frames. It is still cleared when the game window is resized, however.
- Template:NbtTemplate:Nbt Defaults to
[0, 0, 0, 0]. The color 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 color in decimal format calculated from the red, green and blue components using this formula:
(Alpha << 24) + (Red << 16) + (Green << 8) + Blue
- Template:Nbt: The key is the name of the target
- Template:Nbt: Render passes
- Template:Nbt: A render pass
- Template:Nbt: The namespaced id of a vertex shader to use for this pass, relative to the shaders folder.
minecraft:post/blitresolves toassets/minecraft/shaders/post/blit.vsh - Template:Nbt: The namespaced id of a fragment shader to use for this pass, relative to the shaders folder.
minecraft:post/box_blurresolves toassets/minecraft/shaders/post/box_blur.fsh - Template:Nbt: A list of render target inputs and / or texture inputs
- Template:Nbt
- Template:Nbt: The name of the sampler uniform
- Setting this to
MainDepth, for example, makes a sampler2D uniform calledMainDepthSampleravailable to the shader program for this pass. This also provides an additional vec2 to theSamplerInfouniform block called<sampler_name>Size, for exampleMainDepthSize
- Setting this to
- Template:Nbt: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor
- Template:Nbt: The name of the target. Can either be a custom target as specified in
targetsabove, or one of the following built in targets:minecraft:main,minecraft:translucent,minecraft:item_entity,minecraft:particles,minecraft:weather,minecraft:clouds, orminecraft:entity_outline - Template:Nbt: Default: false. If set to true, it samples from the depth texture instead of the color texture.
- Template:Nbt: The name of the sampler uniform
- Template:Nbt
- Template:Nbt: The name of the sampler uniform
- Setting this to
MyTexture, for example, makes a sampler2D uniform calledMyTextureSampleravailable to the shader program for this pass. This also provides an additional vec2 to theSamplerInfouniform block called<sampler_name>Size, for exampleMyTextureSize
- Setting this to
- Template:Nbt: Default: false. If set to true, the sampler uses bilinear filtering instead of nearest neighbor
- Template:Nbt: The resource location of the texture.
my_namespace:post_textureresolves toassets/my_namespace/textures/effect/post_texture.png - Template:Nbt: The width of the texture in pixels
- Template:Nbt: The height of the texture in pixels
- Template:Nbt: The name of the sampler uniform
- Template:Nbt
- Template:Nbt: The target to output to. Can either be a custom target as specified in
targetsabove orminecraft:main. Note: you cannot read and write to the same target in the same pass - Template:Nbt: An object of uniform blocks to pass to the vertex and fragment shaders. For example,
uniforms: { "UniformBlockName": [ { "type": "vec2", "value": [...] } ] }- Template:Nbt: The key is what this uniform block is called when referenced in a shader
- Template:Nbt
- Template:Nbt: The name of the uniform. This is unused by the game, however it is recommended to set it for organizational purposes
- Template:Nbt: The type of the uniform, can be any of:
int,float,ivec3,vec2,vec3,vec4, andmatrix4x4 - Template:NbtTemplate:NbtTemplate:Nbt: Uniform values. The amount and format of this depends on what the
typefield is set tointrequires a single intfloatrequires a single floativec3requires list of 3 intsvec2requires list of 2 floatsvec3requires list of 3 floatsvec4requires list of 4 floatsmatrix4x4requires 16 floats
- Template:Nbt
- Template:Nbt: The key is what this uniform block is called when referenced in a shader
- Template:Nbt: The namespaced id of a vertex shader to use for this pass, relative to the shaders folder.
- Template:Nbt: A render pass
- Template:Nbt: Custom render targets to be used by render passes
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 Minecraft:creeper. |
|
| entity_outline | Applies a blur over a solid color silhouette of an entity. Used when an entity with the Minecraft:glowing effect is on-screen. |
|
| invert | Inverts the colors of the screen. Used when spectating an Minecraft:enderman. |
|
| spider | Renders a blurred version of the screen with 5 additional copies overlapped on top with blurred edges. Used when spectating a Minecraft:spider. |
|
| transparency Template:Until | Combines multiple passes (targets) of different objects in the world. Used when the "Improved Transparency" video setting is enabled. |
|
| end_of_frame | Runs after the world is rendered and before the gui and other post effects Template:Info needed. By default this post effect is unused, however a resourcepack can define it in which case it cannot be disabled in any way besides removing the resourcepack again. |
Render process
General game rendering
Each frame is rendered in the following orderTemplate:Info 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)
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_guifield is set to true or false in the Minecraft: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 necessary and uses 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, orprofiledata components
Vanilla uniform blocks
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 behavior occurs. 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 have a 'default' value. For example, while the rendertype_lines core shader has the proper value for the LineWidth uniform, other shaders have a "default value" that is unlikely to 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.
- (ivec3)
CameraBlockPosBlock position of the camera in world-space coordinates. - (vec3)
CameraOffsetFractional position of the camera in world-space coordinates. - (vec2)
ScreenSizeThe width and height of the current framebuffer in pixels. - (float)
GlintAlphaThe value of the Glint Strength accessibility setting in a 0-1 range. - (float)
GameTimeA 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)
MenuBlurRadiusThe value of the Menu Background Blur accessibility setting in a 0-10 range. - (int)
UseRgssA "boolean" value. Value is 1 if the texture filtering video setting is set to RGSS, otherwise 0.
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)
FogColorColor of the fog. - (float)
FogEnvironmentalStartStarting distance of environmental fog. - (float)
FogEnvironmentalEndEnding distance of environmental fog. - (float)
FogRenderDistanceStartStarting distance of render distance fog. - (float)
FogRenderDistanceEndEnding distance of render distance fog. - (float)
FogSkyEndEnding distance of fog for the upper portion of the sky. - (float)
FogCloudsEndEnding distance for clouds fog.
DynamicTransforms
- (mat4)
ModelViewMatThe model-view matrix. - (vec4)
ColorModulatorA color multiplier that can be set in game code to modify the final color of objects. - (vec3)
ModelOffsetThe offset of the model being rendered. - (mat4)
TextureMatA 4D matrix used to transform UV's for some animated effects, such as the enchantment glint, breeze and wind charge wind, world border, etc.
Lighting
This uniform block is always bound, however may not have proper values if used outside shaders which support it.
- (vec3)
Light0_DirectionFirst light direction. Used to calculate directional entity shading. - (vec3)
Light1_DirectionSecond 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)
ProjMatThe projection matrix
LightmapInfo
- (float)
SkyFactorA value that specifies how much to brighten the lightmap by when the sky flashes, typically when a lightning strike occurs. This value comes from theminecraft:visual/sky_light_factorenvironment attribute. - (float)
BlockFactorA value that fluctuates randomly, used in the vanilla shader for block light flickering. - (float)
NightVisionFactorA value in a 0-1 range that specifies how much the Night Vision status effect should brighten the lightmap by. - (float)
DarknessScaleA value in a 0-1 range that specifies how much the Darkness status effect should darken the lightmap by. - (float)
BossOverlayWorldDarkeningFactorA 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 Template:Info needed. - (float)
BrightnessFactorThe value of the brightness video setting in a 0-1 range. - (vec3)
BlockLightTintThe color of block light. This value comes from theminecraft:visual/block_light_tintenvironment attribute. - (vec3)
SkyLightColorThe color of sky light. This value comes from theminecraft:visual/sky_light_colorenvironment attribute. - (vec3)
AmbientColorThe ambient light color. This value comes from theminecraft:visual/ambient_light_colorenvironment attribute. - (vec3)
NightVisionColorThe color of the Night Vision status effect. This value comes from theminecraft:visual/night_vision_colorenvironment attribute.
CloudInfo
- (vec4)
CloudColorThe color of the clouds. - (vec3)
CloudOffsetOffset of the clouds Template:Info needed. - (vec3)
CellSizeSize of each individual cloud Template:Info needed.
ChunkSection
- (mat4)
ModelViewMatThe model-view matrix. - (float)
ChunkVisibilityValue that increments from 0 to 1 once a chunk section has been displayed. The amount of time this takes is dependent on the "Chunk Fade" video setting - (ivec2)
TextureSizeTemplate:Info needed - (ivec3)
ChunkPositionTemplate:Info needed
SpriteAnimationInfo
- (mat4)
ProjectionMatrixThe projection matrix - (mat4)
SpriteMatrixTemplate:Info needed - (float)
UPaddingTemplate:Info needed - (float)
VPaddingTemplate:Info needed - (int)
MipMapLevelTemplate:Info needed
Post-processing blocks
The following uniform blocks are only available in post-processing shaders.
SamplerInfo
- (vec2)
OutSizeThe 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,MainSizefor an input with a name of "Main"
Bedrock Edition
Since Minecraft:Bedrock Edition 1.18.30, third-party shader in resource packs are no longer supported on all devices due to the implementation of Minecraft: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 Minecraft: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 Minecraft:shader packs.
History
Gallery
-
The creeper vision shader
-
The enderman vision shader
-
The spider vision shader
Issues
Notes
References
External links
Template:Navbox resource packs Template:Navbox Java Edition technical
Minecraft:de:Shaderdaten Minecraft:es:Sombreador Minecraft:fr:Filtres Minecraft:ja:シェーダー Minecraft:pl:Shadery Minecraft:pt:Shader Minecraft:ru:Шейдеры Minecraft:zh:着色器