Make a minecraft shader In Glsl
using .fsh and .vsh file gbuffers_basic.fsh gbuffers_basic.vsh gbuffers_terrian.vsh gbuffers_terrian.fsh
Also So You Know How To Make A Minecraft Shader
Heres The Iris Doc
Overview
The Shaders Mod makes use of a deferred rendering pipeline.
The gbuffer shaders come first in the pipeline. They render data to textures that will be sent to the composite shaders.
Optional composite shaders can be added after the shadow map (shadowcomp), before terrain (prepare) and before water rendering (deferred).
The composite shaders then render to textures that will be sent to the final shader.
The final shader renders directly to the screen.
Shader Files
All shader files are placed in the folder "shaders" of the shader pack.
The shader source files use the name of the program in which they are to be used with extension depending on their type.
Geometry shaders need either OpenGL 3.2 with layout qualifiers or the extension GL_ARB_geometry_shader4 (GL_EXT_geometry_shader4)
with configuration "maxVerticesOut".
Color Attachments
The data is passed from shader to shader using color attachments.
There are at least 4 for all machines. For machines that can support it, there are up to 16.
MacOS is limited to 8 color attachments, even with modern GPUs.
In the deferred, composite and final shaders, these are referenced by the gcolor, gdepth, gnormal, composite, gaux1, gaux2, gaux3 and gaux4 uniforms.
(colortex0 to colortex15 can be used instead of gcolor, gdepth etc.)
Despite the naming, all of these color attachments are the same and can be used for any purpose with the exception of the first two.
The first one, gcolor has its color cleared to the current fog color before rendering.
The second one, gdepth has its color cleared to solid white before rendering and uses a higher precision storage buffer suitable for storing depth values.
The rest have their color cleared to black with 0 alpha.
Each color attachment uses 2 buffers (A and B) with logical names "main" and "alt", which can be used as ping-pong buffers.
When the buffers are flipped the mapping between main/alt and A/B is reversed.
Gbuffer programs always read from "main" (only gaux1-4) and write to "main" buffers (they shouldn't read and write to the same buffer at the same time).
Deferred/composite programs always read from "main" and write to "alt" buffers.
After a deferred/composite program is rendered the buffers that it writes to are flipped so the next programs can see the current output as input.
The property "flip..=<true|false>" can be used to enable or disable the flip independant of the buffer write.
The virtual programs "deferred_pre" and "composite_pre" can be used for buffer flipping before the deferred/composite pass.
Output color attachments are configured with the "/* DRAWBUFFERS:XYZ RENDERTARGETS: X,Y,Z */" comment, placed in the fragment shader.
Gbuffers, deferred and composite programs can write to any color attachment, but no more than 8 at the same time.
If the output color attachments are not configured, then the program will write to the first 8 color attachments.
Assistant
/" or "/
In shaders using the modern syntax (130 and above) the outputs of the fragment shader should use the outColor names. Example:
/* DRAWBUFFERS:3,4,7 */
out vec4 outColor0; // Writes to buffer 3
out vec4 outColor1; // Writes to buffer 4
out vec4 outColor2; // Writes to buffer 7
When writing to the color attachments in the composite shader, blending is disabled.
Writing to color attachments that the composite shader also reads from will generate artifacts (unless you just copy the original contents)
The shaders configuration parsing is affected by the preprocessor conditional compilation directives.
The following preprocessor directives are currently recognized:
#define
#undef
#ifdef
#ifndef
#if
#if defined
#if !defined
#elif
#elif defined
#elif !defined
#else
#endif
The current shaderpack can be reloaded by pressing "F3+R" or using the command "/reloadShaders".
Compute Shaders
A list of compute shaders can be attached to every program except gbuffers programs.
They are named like the program with optional suffix, for example "composite.csh", "composite_a.csh" ... "composite_z.csh".
Compute shaders run before the program and can read from all buffers using texture samplers.
They can read and write to colortex0-5 and shadowcolor0-1 buffers as images using the aliases colorimg0-5 and shadowcolorimg0-1,
for example "layout (rgba8) uniform image2D colorimg0;"
Compute shaders need at least "#version 430" and local size definition, for example: "layout (local_size_x = 16, local_size_y = 16) in;".
Work groups are defined either fixed via "const ivec3 workGroups = ivec3(50, 30, 1);" or relative to render size
via "const vec2 workGroupsRender = vec2(0.5f, 0.5f);".
The default configuration is "const vec2 workGroupsRender = vec2(1.0f, 1.0f);", which executes the compute shader once per pixel.
Image access
All programs can read and write to colorimg0-5 and shadowcolorimg0-1 using imageLoad() and imageStore().
The programs shadow_solid, shadow_cutout, gbuffers_terrain_solid, gbuffers_terrain_cutout and gbuffers_terrain_cutout_mip are not used
Todo:
Separate programs for world border, entities (by id, by type), cape, elytra, wolf collar, etc.
Attributes
Source Value Comment
in vec3 vaPosition; position (x, y, z) 1.17+, for terrain it is relative to the chunk origin, see "chunkOffset"
in vec4 vaColor; color (r, g, b, a) 1.17+
in vec2 vaUV0; texture (u, v) 1.17+
in ivec2 vaUV1; overlay (u, v) 1.17+
in ivec2 vaUV2; lightmap (u, v) 1.17+
in vec3 vaNormal; normal (x, y, z) 1.17+
in vec3 mc_Entity; xy = blockId, renderType "blockId" is used only for blocks specified in "block.properties"
in vec2 mc_midTexCoord; st = midTexU, midTexV Sprite middle UV coordinates
in vec4 at_tangent; xyz = tangent vector, w = handedness
in vec3 at_velocity; vertex offset to previous frame In view space, only for entities and block entities
in vec3 at_midBlock; offset to block center in 1/64m units Only for blocks
Uniforms
Source Value
uniform int heldItemId; held item ID (main hand), used only for items defined in "item.properties"
uniform int heldBlockLightValue; held item light value (main hand)
uniform int heldItemId2; held item ID (off hand), used only for items defined in "item.properties"
uniform int heldBlockLightValue2; held item light value (off hand)
uniform int fogMode; GL_LINEAR, GL_EXP or GL_EXP2
uniform float fogStart; fog start distance (m)
uniform float fogEnd; fog end distance (m)
uniform int fogShape; 0 = sphere, 1 = cylinder
uniform float fogDensity; 0.0-1.0
uniform vec3 fogColor; r, g, b
uniform vec3 skyColor; r, g, b
uniform int worldTime; = worldTicks % 24000
uniform int worldDay; = worldTicks / 24000
uniform int moonPhase; 0-7
uniform int frameCounter; Frame index (0 to 720719, then resets to 0)
uniform float frameTime; last frame time, seconds
uniform float frameTimeCounter; run time, seconds (resets to 0 after 3600s)
uniform float sunAngle; 0.0-1.0
uniform float shadowAngle; 0.0-1.0
uniform float rainStrength; 0.0-1.0
uniform float aspectRatio; viewWidth / viewHeight
uniform float viewWidth; viewWidth
uniform float viewHeight; viewHeight
uniform float near; near viewing plane distance
uniform float far; far viewing plane distance
uniform vec3 sunPosition; sun position in eye space
uniform vec3 moonPosition; moon position in eye space
uniform vec3 shadowLightPosition; shadow light (sun or moon) position in eye space
uniform vec3 upPosition; direction up
uniform vec3 cameraPosition; camera position in world space
uniform vec3 previousCameraPosition; last frame cameraPosition
uniform mat4 gbufferModelView; modelview matrix after setting up the camera transformations
uniform mat4 gbufferModelViewInverse; inverse gbufferModelView
uniform mat4 gbufferPreviousModelView; last frame gbufferModelView
uniform mat4 gbufferProjection; projection matrix when the gbuffers were generated
uniform mat4 gbufferProjectionInverse; inverse gbufferProjection
uniform mat4 gbufferPreviousProjection; last frame gbufferProjection
uniform mat4 shadowProjection; projection matrix when the shadow map was generated
uniform mat4 shadowProjectionInverse; inverse shadowProjection
uniform mat4 shadowModelView; modelview matrix when the shadow map was generated
uniform mat4 shadowModelViewInverse; inverse shadowModelView
uniform float wetness; rainStrength smoothed with wetnessHalfLife or drynessHalfLife
uniform float eyeAltitude; view entity Y position
uniform ivec2 eyeBrightness; x = block brightness, y = sky brightness, light 0-15 = brightness 0-240
uniform ivec2 eyeBrightnessSmooth; eyeBrightness smoothed with eyeBrightnessHalflife
uniform ivec2 terrainTextureSize; not used
uniform int terrainIconSize; not used
uniform int isEyeInWater; 1 = camera is in water, 2 = camera is in lava, 3 = camera is in powder snow
uniform float nightVision; night vision (0.0-1.0)
uniform float blindness; blindness (0.0-1.0)
uniform float screenBrightness; screen brightness (0.0-1.0)
uniform int hideGUI; GUI is hidden
uniform float centerDepthSmooth; centerDepth smoothed with centerDepthSmoothHalflife
uniform ivec2 atlasSize; texture atlas size (only set when the atlas texture is bound)
uniform vec4 spriteBounds; sprite bounds in the texture atlas (u0, v0, u1, v1), set when MC_ANISOTROPIC_FILTERING is enabled
uniform vec4 entityColor; entity color multiplier (entity hurt, creeper flashing when exploding)
uniform int entityId; entity ID
uniform int blockEntityId; block entity ID (block ID for the tile entity, only for blocks specified in "block.properties")
uniform ivec4 blendFunc; blend function (srcRGB, dstRGB, srcAlpha, dstAlpha)
uniform int instanceId; instance ID when instancing is enabled (countInstances > 1), 0 = original, 1-N = copies
uniform float playerMood; player mood (0.0-1.0), increases the longer a player stays underground
uniform int renderStage; render stage, see "Standard Macros", "J. Render stages"
uniform int bossBattle; 1 = custom, 2 = ender dragon, 3 = wither, 4 = raid
// 1.17+
uniform mat4 modelViewMatrix; model view matrix
uniform mat4 modelViewMatrixInverse; inverse model view matrix
uniform mat4 projectionMatrix; projection matrix
uniform mat4 projectionMatrixInverse; inverse projection matrix
uniform mat4 textureMatrix = mat4(1.0); texture matrix, default is identity
uniform mat3 normalMatrix; normal matrix
uniform vec3 chunkOffset; terrain chunk origin, used with attribute "vaPosition"
uniform float alphaTestRef; alpha test reference value, the check is "if (color.a < alphaTestRef) discard;"
// 1.19+
uniform float darknessFactor; strength of the darkness effect (0.0-1.0)
uniform float darknessLightFactor; lightmap variations caused by the darkness effect (0.0-1.0)
depthtex0 everything
depthtex1 no translucent objects (water, stained glass)
depthtex2 no translucent objects (water, stained glass), no handheld objects
Shadow buffers usage
Name Usage
shadowtex0 everything
shadowtex1 no translucent objects (water, stained glass)
Vertex Shader Configuration
Source Effect Comment
in vec3 mc_Entity; useEntityAttrib = true
in vec2 mc_midTexCoord; useMidTexCoordAttrib = true
in vec4 at_tangent; useTangentAttrib = true
const int countInstances = 1; when "countInstances > 1" the geometry will be rendered several times, see uniform "instanceId"
Geometry Shader Configuration
Source Effect Comment
#extension GL_ARB_geometry_shader4 : enable Enable GL_ARB_geometry_shader4
const int maxVerticesOut = 3; Set GEOMETRY_VERTICES_OUT_ARB for GL_ARB_geometry_shader4
BYTE
SHORT
INT
HALF_FLOAT
FLOAT
UNSIGNED_BYTE
UNSIGNED_BYTE_3_3_2
UNSIGNED_BYTE_2_3_3_REV
UNSIGNED_SHORT
UNSIGNED_SHORT_5_6_5
UNSIGNED_SHORT_5_6_5_REV
UNSIGNED_SHORT_4_4_4_4
UNSIGNED_SHORT_4_4_4_4_REV
UNSIGNED_SHORT_5_5_5_1
UNSIGNED_SHORT_1_5_5_5_REV
UNSIGNED_INT
UNSIGNED_INT_8_8_8_8
UNSIGNED_INT_8_8_8_8_REV
UNSIGNED_INT_10_10_10_2
UNSIGNED_INT_2_10_10_10_REV
Block ID mapping
The block ID mapping is defined in "shaders/block.properties" included in the shader pack.
Forge mods may add custom block mapping as "assets//shaders/block.properties" in the mod JAR file.
The "block.properties" file can use conditional preprocessor directives (#ifdef, #if, etc.)
For more details see section "Standard Macros" A to I. Option macros are also available.
Format "block.= ..."
The key is the substitute block ID, the values are the blocks which are to be replaced.
Only one line per block ID is allowed.
See "properties_files.txt" for the block matching rules.
Layers
solid - no alpha, no blending (solid textures)
cutout - alpha, no blending (cutout textures)
cutout_mipped - alpha, no blending, mipmaps (cutout with mipmaps)
translucent - alpha, blending, mipmaps (water, stained glass)
Blocks which are solid opaque cubes (stone, dirt, ores, etc) can't be rendered on a custom layer
as this would affect face culling, ambient occlusion, light propagation and so on.
For exaple:
layer.translucent=glass_pane fence wooden_door
Item ID mapping
The item ID mapping is defined in "shaders/item.properties" included in the shader pack.
Forge mods may add custom item mapping as "assets//shaders/item.properties" in the mod JAR file.
The "item.properties" file can use conditional preprocessor directives (#ifdef, #if, etc.)
For more details see section "Standard Macros" A to I. Option macros are also available.
Format "item.= ..."
The key is the substitute item ID, the values are the items which are to be replaced.
Only one line per item ID is allowed.
Short format
item.5000=diamond_sword dirt
Long format
item.5001=minecraft:diamond_sword botania:reeds
Entity ID mapping
The entity ID mapping is defined in "shaders/entity.properties" included in the shader pack.
Forge mods may add custom entity mapping as "assets//shaders/entity.properties" in the mod JAR file.
The "entity.properties" file can use conditional preprocessor directives (#ifdef, #if, etc.)
For more details see section "Standard Macros" A to I. Option macros are also available.
Format "entity.= ..."
The key is the substitute entity ID, the values are the entities which are to be replaced.
Only one line per entity ID is allowed.
Short format
entity.2000=sheep cow
Long format
entity.2001=minecraft:pig botania:pixie
Standard Macros
The standard macros are automatically included after the "#version" declaration in every shader file
A. Minecraft version
#define MC_VERSION
The value is in format 122 (major 1, minor 2, release 2)
For example: 1.9.4 -> 10904, 1.11.2 -> 11102, etc.
B. Maximum supported GL version
#define MC_GL_VERSION
The value is integer, for example: 210, 320, 450
C. Maximum supported GLSL version
#define MC_GLSL_VERSION
The value is integer, for example: 120, 150, 450
D. Operating system
One of the following:
#define MC_OS_WINDOWS
#define MC_OS_MAC
#define MC_OS_LINUX
#define MC_OS_OTHER
E. Driver
One of the following:
#define MC_GL_VENDOR_AMD
#define MC_GL_VENDOR_ATI
#define MC_GL_VENDOR_INTEL
#define MC_GL_VENDOR_MESA
#define MC_GL_VENDOR_NVIDIA
#define MC_GL_VENDOR_XORG
#define MC_GL_VENDOR_OTHER
F. GPU
One of the following:
#define MC_GL_RENDERER_RADEON
#define MC_GL_RENDERER_GEFORCE
#define MC_GL_RENDERER_QUADRO
#define MC_GL_RENDERER_INTEL
#define MC_GL_RENDERER_GALLIUM
#define MC_GL_RENDERER_MESA
#define MC_GL_RENDERER_OTHER
G. OpenGL extensions
Macros for the supported OpenGL extensions are named like the corresponding extension with a prefix "MC_".
For example the macro "MC_GL_ARB_shader_texture_lod" is defined when the extension "GL_ARB_shader_texture_lod" is supported.
Only the macros which are referenced and supported are added to the shader file.
H. Options
#define MC_FXAA_LEVEL // When FXAA is enabled, values: 2, 4
#define MC_NORMAL_MAP // When the normal map is enabled
#define MC_SPECULAR_MAP // When the specular map is enabled
#define MC_RENDER_QUALITY // Values: 0.5, 0.70710677, 1.0, 1.4142135, 2.0
#define MC_SHADOW_QUALITY // Values: 0.5, 0.70710677, 1.0, 1.4142135, 2.0
#define MC_HAND_DEPTH // Values: 0.0625, 0.125, 0.25
#define MC_OLD_HAND_LIGHT // When Old Hand Light is enabled
#define MC_OLD_LIGHTING // When Old Lighting is enabled
#define MC_ANISOTROPIC_FILTERING // When anisotropic filtering is enabled
I. Textures
#define MC_TEXTURE_FORMAT_LAB_PBR // Texture format LabPBR (https://github.com/rre36/lab-pbr/wiki)
#define MC_TEXTURE_FORMAT_LAB_PBR_1_3 // Version 1.3
(see "texture.properties")
J. Render stages
// Constants for the uniform "renderStage"
// The constants are given in the order in which the stages are executed
#define MC_RENDER_STAGE_NONE // Undefined
#define MC_RENDER_STAGE_SKY // Sky
#define MC_RENDER_STAGE_SUNSET // Sunset and sunrise overlay
#define MC_RENDER_STAGE_CUSTOM_SKY // Custom sky
#define MC_RENDER_STAGE_SUN // Sun
#define MC_RENDER_STAGE_MOON // Moon
#define MC_RENDER_STAGE_STARS // Stars
#define MC_RENDER_STAGE_VOID // Void
#define MC_RENDER_STAGE_TERRAIN_SOLID // Terrain solid
#define MC_RENDER_STAGE_TERRAIN_CUTOUT_MIPPED // Terrain cutout mipped
#define MC_RENDER_STAGE_TERRAIN_CUTOUT // Terrain cutout
#define MC_RENDER_STAGE_ENTITIES // Entities
#define MC_RENDER_STAGE_BLOCK_ENTITIES // Block entities
#define MC_RENDER_STAGE_DESTROY // Destroy overlay
#define MC_RENDER_STAGE_OUTLINE // Selection outline
#define MC_RENDER_STAGE_DEBUG // Debug renderers
#define MC_RENDER_STAGE_HAND_SOLID // Solid handheld objects
#define MC_RENDER_STAGE_TERRAIN_TRANSLUCENT // Terrain translucent
#define MC_RENDER_STAGE_TRIPWIRE // Tripwire string
#define MC_RENDER_STAGE_PARTICLES // Particles
#define MC_RENDER_STAGE_CLOUDS // Clouds
#define MC_RENDER_STAGE_RAIN_SNOW // Rain and snow
#define MC_RENDER_STAGE_WORLD_BORDER // World border
#define MC_RENDER_STAGE_HAND_TRANSLUCENT // Translucent handheld objects
Sure! I'd be happy to help you create a basic Minecraft shader using GLSL with the files you mentioned: gbuffers_basic.fsh, gbuffers_basic.vsh, gbuffers_terrain.fsh, and gbuffers_terrain.vsh. These shaders will implement simple lighting and coloring effects that you can build upon.
Below, I'll provide the code for each shader file along with explanations to help you understand how they work. This should give you a solid starting point for creating your own custom Minecraft shaders.
1. gbuffers_basic.vsh (Vertex Shader for Basic Objects)
#version 120
// Vertex attributes provided by Minecraft
attribute vec3 mc_Vertex; // Vertex position
attribute vec2 mc_TexCoord0; // Texture coordinates
attribute vec3 mc_Normal; // Vertex normal
// Varying variables to pass data to the fragment shader
varying vec2 v_TexCoord;
varying vec3 v_Normal;
void main() {
// Pass texture coordinates to the fragment shader
v_TexCoord = mc_TexCoord0;
// Transform the normal vector to eye space
v_Normal = normalize(gl_NormalMatrix * mc_Normal);
// Transform the vertex position to clip space
gl_Position = gl_ModelViewProjectionMatrix * vec4(mc_Vertex, 1.0);
}
Explanation:
Attributes:
mc_Vertex: The position of the vertex.
mc_TexCoord0: The texture coordinates.
mc_Normal: The normal vector at the vertex.
Varyings:
v_TexCoord: Passed to the fragment shader for texture sampling.
v_Normal: The normal vector transformed to eye space for lighting calculations.
Main Function:
We pass the texture coordinates directly.
The normal is transformed using gl_NormalMatrix, which accounts for transformations applied to the model.
The vertex position is transformed using gl_ModelViewProjectionMatrix to project it onto the screen.
2. gbuffers_basic.fsh (Fragment Shader for Basic Objects)
#version 120
// Uniforms
uniform sampler2D gtexture; // The texture sampler
// Varying variables received from the vertex shader
varying vec2 v_TexCoord;
varying vec3 v_Normal;
void main() {
// Sample the texture using the texture coordinates
vec4 color = texture2D(gtexture, v_TexCoord);
// Simple ambient lighting factor
float ambient = 0.3;
// Light direction (pointing downwards)
vec3 lightDir = normalize(vec3(0.0, -1.0, 0.0));
// Diffuse lighting calculation
float diffuse = max(dot(v_Normal, lightDir), 0.0);
// Combine ambient and diffuse lighting
float lighting = ambient + (1.0 - ambient) * diffuse;
// Apply the lighting to the texture color
gl_FragColor = vec4(color.rgb * lighting, color.a);
}
Explanation:
Uniforms:
gtexture: The texture to apply to the object.
Varyings:
v_TexCoord: Used to sample the texture.
v_Normal: Used for lighting calculations.
Main Function:
We sample the texture to get the base color.
An ambient lighting term is defined to ensure objects are not completely dark when not lit.
We calculate diffuse lighting based on the dot product between the normal and light direction.
The total lighting is a combination of ambient and diffuse components.
The color is modulated by the lighting factor.
3. gbuffers_terrain.vsh (Vertex Shader for Terrain)
#version 120
// Vertex attributes
attribute vec3 mc_Vertex; // Vertex position
attribute vec2 mc_TexCoord0; // Texture coordinates
attribute vec3 mc_Normal; // Vertex normal
// Uniforms
uniform vec3 chunkOffset; // Offset for terrain chunks
// Varying variables
varying vec2 v_TexCoord;
varying vec3 v_Normal;
varying vec3 v_WorldPosition;
void main() {
// Compute the world position
vec3 worldPosition = mc_Vertex + chunkOffset;
// Pass the world position to the fragment shader
v_WorldPosition = worldPosition;
// Pass texture coordinates and normals
v_TexCoord = mc_TexCoord0;
v_Normal = normalize(gl_NormalMatrix * mc_Normal);
// Transform vertex to clip space
gl_Position = gl_ModelViewProjectionMatrix * vec4(mc_Vertex, 1.0);
}
Explanation:
Similar to gbuffers_basic.vsh, but we also calculate and pass the world position, which is useful for effects like fog or distant shading.
chunkOffset is a uniform that represents the position of the terrain chunk in the world.
4. gbuffers_terrain.fsh (Fragment Shader for Terrain)
#version 120
// Uniforms
uniform sampler2D gtexture; // Texture sampler
uniform vec3 cameraPosition; // Position of the camera in the world
uniform vec3 fogColor; // Color of the fog
uniform float fogStart; // Distance at which fog starts
uniform float fogEnd; // Distance at which fog is fully opaque
// Varying variables
varying vec2 v_TexCoord;
varying vec3 v_Normal;
varying vec3 v_WorldPosition;
void main() {
// Sample the terrain texture
vec4 color = texture2D(gtexture, v_TexCoord);
// Simple lighting
float ambient = 0.4;
vec3 lightDir = normalize(vec3(0.0, 1.0, 0.0)); // Light coming from above
float diffuse = max(dot(v_Normal, lightDir), 0.0);
float lighting = ambient + (1.0 - ambient) * diffuse;
// Apply lighting to the texture color
vec3 litColor = color.rgb * lighting;
// Compute distance from the camera to the fragment
float distance = length(v_WorldPosition - cameraPosition);
// Compute fog factor
float fogFactor = clamp((fogEnd - distance) / (fogEnd - fogStart), 0.0, 1.0);
// Mix the lit color with the fog color
vec3 finalColor = mix(fogColor, litColor, fogFactor);
gl_FragColor = vec4(finalColor, color.a);
}
Explanation:
Lighting:
Similar to the basic shader, but we assume the light is coming from above for terrain.
Fog Effect:
We compute the distance from the fragment to the camera.
The fog factor is calculated based on the fog start and end distances.
fogFactor determines how much the fog color blends with the fragment color.
The final color is a mix between the lit color and the fog color based on this factor.
How to Use These Shaders
Organize Your Shader Pack:
Create a folder for your shader pack inside the shaderpacks directory in your Minecraft installation.
Inside your shader pack folder, create a shaders directory.
Place the Shader Files:
Save the shader files provided above into the shaders directory.
Ensure the filenames match exactly: gbuffers_basic.vsh, gbuffers_basic.fsh, gbuffers_terrain.vsh, gbuffers_terrain.fsh.
Create a shaderpack.json File (Optional):
You can create a shaderpack.json file to provide metadata about your shader pack.
Example content:
{
"name": "My Custom Shader Pack",
"description": "A simple shader pack created for demonstration."
}
Select the Shader Pack in Minecraft:
Launch Minecraft with Iris installed.
Go to Options > Video Settings > Shaders.
Your shader pack should appear in the list. Select it to apply the shaders.
Test and Iterate:
Enter a world and observe the effects.
You can modify the shaders and reload them in-game by pressing F3 + R to see changes without restarting Minecraft.
Understanding the Iris Shader Pipeline
Shader Programs:
gbuffers_basic: Used for basic geometry like lines, particles, and simple models.
gbuffers_terrain: Used for rendering terrain blocks.
Uniforms and Varyings:
Uniforms are variables that remain constant during a draw call. They are set by the game or shader mod.
Varyings are used to pass data from the vertex shader to the fragment shader.
Attributes:
Attributes are per-vertex inputs provided by the game.
Rendering Pipeline:
Vertex Shader: Processes each vertex, transforming it into clip space and passing necessary data to the fragment shader.
Fragment Shader: Calculates the color of each pixel (fragment), applying textures, lighting, and other effects.
Tips for Shader Development
Start Simple: Begin with basic effects to ensure your shaders are working, then gradually add complexity.
Use Debugging Tools: GLSL shaders can be tricky to debug. Insert temporary colors or outputs to check values.
Consult Documentation: Refer to the Iris documentation for a comprehensive list of available uniforms, attributes, and functions.
Stay Organized: Comment your code and keep your shader files organized to make future edits easier.
Test Frequently: Make small changes and test them often to catch issues early.
Expanding Your Shaders
Advanced Lighting: Implement more complex lighting models like Phong or Blinn-Phong shading for realistic effects.
Shadow Mapping: Incorporate shadows into your shaders to add depth to the scene.
Normal Mapping: Use normal maps to add detailed surface textures without additional geometry.
Specular Highlights: Add shininess to surfaces by calculating specular reflections.
Dynamic Effects: Use uniforms like time to create animations or effects that change over time.
Resources for Learning GLSL and Shader Development