Download Extended Shaders — Minecraft Mods — MetaMods

Extended Shaders

Active

Downloads

0

Last update

3 years ago
Client
Libraries

Extended Shaders

API for Shaders in Mods

Extended Shaders is a coremod API that provides mod developers with the ability to use shaders and post-processing effects in their projects. This solution eliminates the need for deep immersion in creating coremods and ensures compatibility with other modifications using this system.

Requirements for Developers

Working with the API requires confident knowledge of the GLSL language, including the GLSL compatibility profile used in this system. Without this knowledge, effective use of the tool is impossible.

Compatibility with Optifine

The mod is fully compatible with Optifine, but post-processing effects will only work when the "fast render" option is disabled. With Optifine installed, shaders are activated through the shaderpacks selection menu, where you need to select 'Extended Shaders'. Without Optifine, shader management is done through the "Video Settings" menu.

System Requirements

For the mod to work, the computer must support framebuffers, framebuffer copying operations, and floating-point textures. If these capabilities are missing, the game will crash - this is intended behavior.

Developer Guide

Creating a Vertex Shader

  1. Create a file in your mod's resources with a list of uniform variables, variables, and constants:
uniform float burnAmount; // uniform variable
varying vec4 fragCol; // variable
#define col vec3(.976, .969, .816) // constant
  1. Create a file with shader code:
fragCol = fragCol  col;
  1. Create a ShaderData instance:
vertShader = new ShaderData(new ResourceLocation(modid, uniformslocation), new ResourceLocation(modid, codelocation), uniform name 1, uniform name 2, ...);
  1. To activate:
ShaderRegistry.addVertexShader(vertShader);
  1. To deactivate:
ShaderRegistry.removeVertexShader(vertShader);

Creating a Fragment Shader

  1. Create a file with a list of uniform variables, variables, and constants:
uniform float burnAmount; // uniform variable
varying vec2 textureCoords; // variable
#define col vec3(.976, .969, .816) // constant
  1. Create a file with shader code (working through gl_fragData[0]):
float depth = sqrt(eyePos.x  eyePos.x + eyePos.y  eyePos.y + eyePos.z  eyePos.z);
if (depth > 64.0) discard;
depth = clamp(depth / 64.0, 0, 1);
float val = (max(max(gl_FragData[0].r, gl_FragData[0].g), gl_FragData[0].b) + min(min(gl_FragData[0].r, gl_FragData[0].g), gl_FragData[0].b))  .25;
gl_FragData[0] = vec4(vec3(1.0) - col  (depth + val - depth  val), gl_FragData[0].a);
  1. Create a ShaderData instance:
fragShader = new ShaderData(new ResourceLocation(modid, uniformslocation), new ResourceLocation(modid, codelocation), uniform name 1, uniform name 2, ...);
  1. To activate:
ShaderRegistry.addFragmentShader(fragShader);
  1. To deactivate:
ShaderRegistry.removeFragmentShader(fragShader);

Creating a Post-Processor

  1. Create a file with a list of uniform variables and constants:
uniform float currentTime; // uniform variable
#define rad 3.0 // constant
  1. Create a file with post-processor code:
float tx1 = rad  dx;
float tx2 = tx1  .5;
float ty = rad  .5  sqrt(3.0)  dy;
vec3 cp1 = texture2D(tex0, texCoords).rgb;
vec3 cp1 = texture2D(tex0, texCoords + vec2(tx1, 0)).rgb;
vec3 cp3 = texture2D(tex0, texCoords + vec2(tx2, ty)).rgb;
vec3 cp4 = texture2D(tex0, texCoords + vec2(-tx2, ty)).rgb;
vec3 cp5 = texture2D(tex0, texCoords + vec2(-tx1, 0)).rgb;
vec3 cp6 = texture2D(tex0, texCoords + vec2(-tx2, -ty)).rgb;
vec3 cp7 = texture2D(tex0, texCoords + vec2(tx2, -ty)).rgb;
gl_FragData[0] = vec4((cp1 + cp2 + cp3 + cp4 + cp5 + cp6 + cp7) / 7, 1);
  1. Create a PostProcessor instance:
postProcessor = new PostProcessor(new ResourceLocation(modid, uniformslocation), new ResourceLocation(modid, codelocation), uniform name 1, uniform name 2, ...);
  1. To activate:
PostProcessorRegistry.addPostProcessor(postProcessor);
  1. To deactivate:
PostProcessorRegistry.removePostProcessor(postProcessor);

The API also supports priorities for shaders and post-processors. To learn about advanced features, study the API documentation.

Project members
FirEmerald

FirEmerald

Created: 16 May 2022

ID: 36601