### Customize Block Rendering with Fragment Shader - rendertype_solid Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Fragment shader example for modifying solid block appearance by applying custom tinting based on color values. Demonstrates texture sampling, vertex color multiplication, and conditional color modifications for specific block types like stone. ```glsl #version 150 uniform sampler2D Sampler0; uniform sampler2D Sampler2; in vec4 vertexColor; in vec2 texCoord0; in vec2 texCoord2; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0); // Apply custom tint to stone blocks (example) if (color.rgb == vec3(0.5, 0.5, 0.5)) { color.rgb *= vec3(1.0, 0.8, 0.8); // Reddish tint } fragColor = color * vertexColor; } ``` -------------------------------- ### Minecraft Core Vertex Shader Structure - rendertype_solid Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Example vertex shader demonstrating the basic structure for processing vertex positions, colors, UV coordinates, and applying model-view and projection transformations. This shader handles position calculations for opaque blocks, lava, and falling blocks in Minecraft. ```glsl #version 150 in vec3 Position; in vec4 Color; in vec2 UV0; in ivec2 UV2; uniform mat4 ModelViewMat; uniform mat4 ProjMat; uniform vec3 ChunkOffset; out vec4 vertexColor; out vec2 texCoord0; void main() { gl_Position = ProjMat * ModelViewMat * vec4(Position + ChunkOffset, 1.0); vertexColor = Color; texCoord0 = UV0; } ``` -------------------------------- ### Customize Particle Appearances (GLSL) Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt This fragment shader modifies the appearance of all particles and weather effects by altering the `particle.fsh` shader. The example demonstrates making particles rainbow-colored based on their distance and overriding transparency. The `ColorModulator` uniform can be used for further tinting. ```glsl #version 150 uniform sampler2D Sampler0; uniform vec4 ColorModulator; in vec4 vertexColor; in vec2 texCoord0; in float vertexDistance; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0); // Make particles rainbow colored color.r = abs(sin(vertexDistance * 0.1)); color.g = abs(sin(vertexDistance * 0.1 + 2.094)); color.b = abs(sin(vertexDistance * 0.1 + 4.189)); // Override particle transparency (affects some particles) color.a = vertexColor.a; fragColor = color * ColorModulator; } ``` -------------------------------- ### Customize Text Rendering with Position.z (GLSL) Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt This fragment shader customizes text rendering, including the F3 menu, chat, and UI text, by utilizing the `position.z` value. Different text elements are assigned distinct z-coordinate ranges. The example highlights chat text by mixing its color with yellow and includes a check to discard transparent pixels. ```glsl #version 150 uniform sampler2D Sampler0; uniform vec4 ColorModulator; in vec4 vertexColor; in vec2 texCoord0; in vec3 position; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0) * vertexColor; // Text shadows are at base z, text is at z + 0.03 // z = 0.0: title text, bossbar // z = 100.0: chat // z = 200.0: hotbar item count // z = 300.0: inventory item count if (position.z > 99.0 && position.z < 101.0) { // Make chat text highlighted color.rgb = mix(color.rgb, vec3(1.0, 1.0, 0.0), 0.3); } if (color.a < 0.1) { discard; } fragColor = color * ColorModulator; } ``` -------------------------------- ### Create Animated Effects with GameTime Uniform (GLSL) Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt This fragment shader utilizes the `GameTime` uniform to create animated effects. `GameTime` increments from 0 to 1 over 24000 ticks, synchronizing animations across players. The example shows how to create a pulsing effect on glass blocks and add wave distortion to textures. ```glsl #version 150 uniform sampler2D Sampler0; uniform float GameTime; in vec4 vertexColor; in vec2 texCoord0; in vec3 Position; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0); // Create pulsing effect on glass blocks float pulse = sin(GameTime * 1200.0) * 0.5 + 0.5; color.rgb = mix(color.rgb, vec3(0.5, 0.7, 1.0), pulse * 0.3); // Add wave distortion vec2 distortedUV = texCoord0; distortedUV.x += sin(Position.y + GameTime * 1200.0) * 0.01; color = texture(Sampler0, distortedUV); fragColor = color * vertexColor; } ``` -------------------------------- ### Customize Enchantment Glint Effect (GLSL) Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt This fragment shader modifies the enchantment glint effect on items and blocks. It uses the `TextureMat` uniform for animation and `GlintAlpha` for accessibility settings. The example changes the glint color dynamically based on `GameTime` and applies the `GlintAlpha` multiplier to the final color's alpha channel. ```glsl #version 150 uniform sampler2D Sampler0; uniform mat4 TextureMat; uniform float GlintAlpha; uniform float GameTime; in vec4 vertexColor; in vec2 texCoord0; out vec4 fragColor; void main() { // Apply texture matrix transformation vec4 transformedUV = TextureMat * vec4(texCoord0, 0.0, 1.0); vec4 color = texture(Sampler0, transformedUV.xy); // Change glint color based on time float hue = fract(GameTime * 0.5); vec3 glintColor; if (hue < 0.33) { glintColor = vec3(1.0, 0.5, 1.0); // Magenta } else if (hue < 0.66) { glintColor = vec3(0.5, 1.0, 1.0); // Cyan } else { glintColor = vec3(1.0, 1.0, 0.5); // Yellow } color.rgb = glintColor; color.a *= GlintAlpha * vertexColor.a; fragColor = color; } ``` -------------------------------- ### Apply Fog and Lighting in GLSL Shaders Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Demonstrates using shared GLSL include files for fog and lighting calculations. `fog.glsl` provides functions like `linear_fog` and `linear_fog_fade`, while `light.glsl` allows sampling lightmaps. These functions take various parameters like color, distance, and lightmap texture coordinates to modify fragment output. ```glsl // Using fog functions in a shader #include "fog.glsl" uniform vec4 FogColor; uniform float FogStart; uniform float FogEnd; in float vertexDistance; in vec4 vertexColor; out vec4 fragColor; void main() { vec4 color = vertexColor; // Apply linear fog fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); // Or use fog fade factor float fogFade = linear_fog_fade(vertexDistance, FogStart, FogEnd); fragColor = mix(FogColor, color, fogFade); } ``` ```glsl // Using lightmap sampling in entity shader #include "light.glsl" uniform sampler2D Sampler2; // Lightmap in vec2 texCoord2; // Light UV coordinates void main() { vec4 color = texture(Sampler0, texCoord0); // Sample lightmap (texCoord2.x = block light * 16, texCoord2.y = sky light * 16) vec4 light = minecraft_sample_lightmap(Sampler2, texCoord2); fragColor = color * light; } ``` -------------------------------- ### Isolate GUI Elements in Entity Shaders (GLSL) Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt This vertex shader demonstrates how to isolate GUI elements from world modifications by using depth-based detection. It calculates depth and checks for orthographic projection, which is characteristic of GUI rendering. Specific depth values are noted for inventory, hotbar, and dragging items. ```glsl #version 150 in vec3 Position; in vec4 Color; in vec2 UV0; in ivec2 UV2; uniform mat4 ModelViewMat; uniform mat4 ProjMat; out vec4 vertexColor; out vec2 texCoord0; out float depth; out float isGui; void main() { gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); // Calculate depth for GUI detection depth = -(ModelViewMat * vec4(1.0)).z; // Check if rendering GUI (ProjMat[3].x == -1 for orthographic projection) isGui = (ProjMat[3].x == -1.0) ? 1.0 : 0.0; // Inventory items have specific depth values: // 1734 = inventory, 1834 = hotbar, 1602 = dragging vertexColor = Color; texCoord0 = UV0; } ``` -------------------------------- ### Modify Entity Appearance with Fragment Shader - rendertype_entity_cutout_no_cull Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Fragment shader for customizing entity rendering including mobs, signs, and player heads. Implements dynamic glow effects based on light levels and alpha channel discarding for transparency. Provides per-entity visual modifications without affecting vanilla compatibility. ```glsl #version 150 uniform sampler2D Sampler0; uniform sampler2D Sampler1; uniform vec4 ColorModulator; in vec4 vertexColor; in vec2 texCoord0; in vec2 texCoord1; in float vertexDistance; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0); // Make entities glow at night float lightLevel = texture(Sampler1, texCoord1).r; if (lightLevel < 0.5) { color.rgb += vec3(0.2); } if (color.a < 0.1) { discard; } fragColor = color * vertexColor * ColorModulator; } ``` -------------------------------- ### Isolating GUI Elements by Depth and Position in GLSL Source: https://github.com/mctsts/minecraft-shaders-wiki/blob/main/Isolating Items.md This GLSL code snippet demonstrates how to isolate GUI elements, specifically the hotbar, by checking the calculated depth and screen position. It utilizes screen size and model-view matrix information to refine the selection, preventing unintended shader modifications on other GUI components. ```glsl vec2 ScrSize = ceil(2 / vec2(ProjMat[0][0], -ProjMat[1][1])); vec2 Pos = ModelViewMat[3].xy; ... if (dist == 1834 && ScrSize.y - pos.y <= 13) { //code... } ``` -------------------------------- ### Calculate World Space Position in GLSL Shaders Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Illustrates converting chunk-relative block positions to world space coordinates in GLSL. This is crucial for effects dependent on absolute world positions, such as distance-based rendering or grid patterns. It utilizes `ChunkOffset` uniform and outputs `worldPos` for fragment shaders. ```glsl // Vertex shader calculating world position (rendertype_solid.vsh) #version 150 in vec3 Position; in vec4 Color; in vec2 UV0; uniform mat4 ModelViewMat; uniform mat4 ProjMat; uniform vec3 ChunkOffset; out vec4 vertexColor; out vec2 texCoord0; out vec3 worldPos; void main() { // Position is 0-16 within chunk, ChunkOffset gives chunk location worldPos = Position + ChunkOffset; gl_Position = ProjMat * ModelViewMat * vec4(worldPos, 1.0); vertexColor = Color; texCoord0 = UV0; } ``` ```glsl // Fragment shader using world position (rendertype_solid.fsh) #version 150 uniform sampler2D Sampler0; in vec3 worldPos; in vec2 texCoord0; out vec4 fragColor; void main() { vec4 color = texture(Sampler0, texCoord0); // Create grid pattern at y=64 if (abs(worldPos.y - 64.0) < 0.1) { if (mod(worldPos.x, 1.0) < 0.1 || mod(worldPos.z, 1.0) < 0.1) { color.rgb = vec3(1.0, 0.0, 0.0); } } // Distance-based effects from world origin float distFromOrigin = length(worldPos.xz); if (distFromOrigin > 1000.0) { color.rgb *= 0.5; // Darken distant blocks } fragColor = color; } ``` -------------------------------- ### Customize Sky Color and Gradients in GLSL Shaders Source: https://context7.com/mctsts/minecraft-shaders-wiki/llms.txt Shows how to modify sky rendering using GLSL fragment shaders. The `position.fsh` shader can alter the base sky color using `ColorModulator`, while `position_color.fsh` utilizes `vertexColor` to enhance sunrise and sunset gradients based on color values. ```glsl // Fragment shader for custom sky color (position.fsh) #version 150 uniform vec4 ColorModulator; out vec4 fragColor; void main() { // Default sky just uses ColorModulator (provided by game) // Can modify to create custom sky effects vec4 skyColor = ColorModulator; // Make sky purple skyColor.rgb = mix(skyColor.rgb, vec3(0.5, 0.0, 1.0), 0.5); fragColor = skyColor; } ``` ```glsl // Fragment shader for sunset/sunrise overlay (position_color.fsh) #version 150 in vec4 vertexColor; out vec4 fragColor; void main() { // vertexColor contains the sunset/sunrise gradient // Active between times 11315-14150 (sunset) and 21830-24670 (sunrise) vec4 color = vertexColor; // Enhance sunset colors if (color.r > 0.5 && color.g < 0.5) { color.r *= 1.5; color.g *= 0.8; } fragColor = color; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.