Skip to content

ShaderTexture

Since 2.2.1

ShaderTexture renders a region of the GUI using a custom GLSL shader. The shader receives the element's screen rectangle and mouse position as automatic uniforms, making it straightforward to create animated or interactive effects.

Registry name: shader_texture

INFO

Extends TransformTexture — supports rotate(), scale(), transform().

WARNING

ShaderTexture holds a GPU resource (LDShaderHolder) and implements AutoCloseable. Call close() when the texture is no longer needed, or ensure it is managed by the editor.


Usage

java
// Load a shader from assets/mymod/shaders/core/my_effect.json
IGuiTexture effect = new ShaderTexture(ResourceLocation.parse("mymod:my_effect"));

// Tinted shader (vertex colour passed to the shader)
IGuiTexture tinted = new ShaderTexture(ResourceLocation.parse("mymod:my_effect"))
    .setColor(0xFF44AAFF);

LSS

css
background: shader(mymod:my_effect);

Automatic Uniforms

The following uniforms are set automatically on every draw call:

UniformTypeDescription
U_GuiRectvec4Screen-space rect: (x, y, width, height) in GUI pixels.
U_GuiMousevec2Mouse position: (mouseX, mouseY) in GUI pixels.

Vertex colour (setColor) is passed as the standard vertex colour attribute.

Additional uniforms can be exposed by the shader JSON and edited in the UI editor via LDShaderHolder.


Shader File Location

Place the shader JSON at:

assets/<namespace>/shaders/core/<name>.json

Then reference it as namespace:name (without the .json extension).


Fields

NameTypeDescription
shaderLocationResourceLocationThe registered shader location.
colorintARGB tint passed as vertex colour. Default: -1 (white).
shaderHolderLDShaderHolder (nullable)The compiled GPU shader resource. null if compilation failed.

Methods

MethodReturnsDescription
setShader(ResourceLocation)ShaderTextureLoads or reloads the shader. Safe to call from any thread.
setColor(int)ShaderTextureSets the ARGB tint.
close()voidReleases the GPU shader resource.

Released under the MIT License.