Record Class ScreenEffectDefinition

java.lang.Object
java.lang.Record
net.ixdarklord.coolcatcanvas.api.client.effect.ScreenEffectDefinition

public record ScreenEffectDefinition(Map<net.minecraft.resources.ResourceLocation,ScreenEffectDefinition.Target> targets, List<ScreenEffectDefinition.Pass> passes) extends Record
The passes and targets of a screen effect, in the post_effect format of later Minecraft versions. Loaded from assets/<namespace>/post_effect/<path>.json, or built with builder(). A vanilla 1.21 post chain (assets/<namespace>/shaders/post/<path>.json, vanilla's own included) loads too, when no post_effect file has that id.

Each pass draws a fragment shader over its output target: vertex_shader and fragment_shader name assets/<namespace>/shaders/<path>.vsh and .fsh, GLSL 150 with plain uniforms (minecraft:core/screenquad and minecraft:core/blit_screen stand for SCREENQUAD_VERTEX_SHADER and BLIT_FRAGMENT_SHADER).

  • An input is sampled as uniform sampler2D <sampler_name>Sampler, its size in pixels read as uniform vec2 <sampler_name>Size. InSize is the first input's size, OutSize the output's, ScreenSize the window's, and ProjMat the projection SCREENQUAD_VERTEX_SHADER uses.
  • Every uniform needs a "name", by which the effect sets it, and a type; the shader declares it as a plain uniform of that name. The block names they're grouped under only organize them.
  • Strength, Time, Age and Seed are set for every pass; see coolcatcanvas:screen_effect.glsl.
  • The only external target is minecraft:main; its depth can be read with "use_depth_buffer": true.
  • Field Details

    • MAIN_TARGET

      public static final net.minecraft.resources.ResourceLocation MAIN_TARGET
    • SCREENQUAD_VERTEX_SHADER

      public static final net.minecraft.resources.ResourceLocation SCREENQUAD_VERTEX_SHADER
      Draws the screen as a quad, giving the fragment shader texCoord.
    • BLIT_FRAGMENT_SHADER

      public static final net.minecraft.resources.ResourceLocation BLIT_FRAGMENT_SHADER
      Copies its In sampler, no uniforms.
    • RESERVED_UNIFORM_BLOCKS

      public static final Set<String> RESERVED_UNIFORM_BLOCKS
      Uniform block names taken by the runtime.
    • RESERVED_UNIFORMS

      public static final Set<String> RESERVED_UNIFORMS
      Uniform names the runtime sets, which no pass can declare.
    • CODEC

      public static final com.mojang.serialization.Codec<ScreenEffectDefinition> CODEC
  • Constructor Details

    • ScreenEffectDefinition

      public ScreenEffectDefinition(Map<net.minecraft.resources.ResourceLocation,ScreenEffectDefinition.Target> targets, List<ScreenEffectDefinition.Pass> passes)
      Creates an instance of a ScreenEffectDefinition record class.
      Parameters:
      targets - the value for the targets record component
      passes - the value for the passes record component
  • Method Details

    • builder

      public static ScreenEffectDefinition.Builder builder()
    • simple

      public static ScreenEffectDefinition simple(net.minecraft.resources.ResourceLocation fragmentShader, String uniformBlock, ScreenEffectDefinition.UniformSpec... uniforms)
      One fragment shader over the screen: reads minecraft:main as In, writes a swap target, then copies it back. The simplest effect there is.
      Parameters:
      uniformBlock - the name the uniforms are grouped under, ignored if uniforms is empty
      uniforms - the shader's uniforms
    • uniformNames

      public Set<String> uniformNames()
      Every uniform name any pass declares.
    • resolveShader

      public static net.minecraft.resources.ResourceLocation resolveShader(net.minecraft.resources.ResourceLocation shader)
      The shader ids of later versions' vanilla post shaders, mapped to CoolCatLib's equivalents.
    • validate

      public static com.mojang.serialization.DataResult<ScreenEffectDefinition> validate(ScreenEffectDefinition definition)
      Checks a definition built without the ScreenEffectDefinition.Builder, as loading it does.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • targets

      public Map<net.minecraft.resources.ResourceLocation,ScreenEffectDefinition.Target> targets()
      Returns the value of the targets record component.
      Returns:
      the value of the targets record component
    • passes

      Returns the value of the passes record component.
      Returns:
      the value of the passes record component