Skip to content

CustomRenderType

Ocelot edited this page Nov 22, 2024 · 2 revisions

Data-driven render types are located in the rendertypes folder in the resource pack. Use VeilRenderType#get to get a data-driven render type by id. Veil automatically caches the render types so there is no issue with putting this in a render loop.

Render types can be created using files in the resource pack instead of directly through code. This makes it easier for users to create new render types and edit existing ones.

Note: VeilRenderType#get calls should go in the render loop so whenever the render type updates in the resource pack it will also update the rendering

Example

{
  "format": "POSITION_COLOR_TEX_LIGHTMAP",
  "mode": "QUADS",
  "bufferSize": "TRANSIENT",
  "sort": false,
  "affectsCrumbling": true,
  "outline": false,
  "layers": [
    {
      "type": "minecraft:texture",
      "texture": "%1$s",
      "blur": true,
      "mipmap": false
    },
    {
      "type": "veil:shader",
      "name": "veil:test_shader"
    },
    {
      "type": "minecraft:depth_test",
      "mode": "always"
    },
    {
      "type": "minecraft:cull"
    },
    {
      "type": "minecraft:lightmap"
    },
    {
      "type": "minecraft:write_mask",
      "color": true,
      "depth": false
    }
  ]
}

test_rendertype.json

import com.mojang.blaze3d.vertex.VertexConsumer;
import foundry.veil.Veil;
import foundry.veil.api.client.render.rendertype.VeilRenderType;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

public class TestRenderer {

    private static final ResourceLocation RENDER_TYPE = ResourceLocation.fromNamespaceAndPath("examplemod", "test_rendertype");

    public static void render(MultiBufferSource bufferSource) {
        RenderType renderType = VeilRenderType.get(RENDER_TYPE, "test_texture.png");
        if (renderType == null) {
            // There was an error loading the render type
            return;
        }

        VertexConsumer builder = bufferSource.getBuffer(renderType);
        // do rendering code as usual
    }
}

TestRenderer.java

Syntax

{
  // Required
  // The vertex format to use. See DefaultVertexFormats
  "format": "POSITION",
  // Required
  // The type of primitives to construct and render with
  "mode": "QUADS",
  // Required
  // The size of the buffer in bytes. Alternatively, you can use BIG, SMALL, and TRANSIENT
  "bufferSize": "TRANSIENT",
  // Optional
  // Whether to sort the vertex data before rendering it
  "sort": false,
  // Optional
  // Whether this render type should affect the breaking animation
  "affectsCrumbling": true,
  // Optional
  // Whether this render type should be present in entity outlines
  "outline": false,
  // Required
  // All render type shards to include. See below for the available layers
  "layers": [
    ...
  ]
}

Note: layers can also be an array of arrays to create a layered render type

Layers

Layers are a single part of a render type definition. All string elements in render type fields support using java formatting codes to insert template values. However since the same list is used for all fields, you should reference elements directly (%$1s references the first element as a string for example).

Texture

Assigns a texture to unit 0.

{
  "type": "minecraft:texture",
  // Required
  "texture": "formatting_string",
  // Optional
  "blur": false,
  // Optional
  "mipmap": false,
}

Multi-Texture

A list of normal texture layers that assigns textures to texture units 0-11.

{
  "type": "minecraft:multi_texture",
  "textures": [
    {
      // Required
      "texture": "formatting_string",
      // Optional
      "blur": false,
      // Optional
      "mipmap": false,
    },
    {
      // Required
      "texture": "formatting_string",
      // Optional
      "blur": false,
      // Optional
      "mipmap": false,
    },
    // More layers can be specified up to 12 (The default minecraft render system max)
    ...
  ]
}

Vanilla Shader

A specific vanilla minecraft shader to use. This is based on the provided shader file name, without the minecraft namespace.

{
  "type": "minecraft:shader",
  // Required
  "name": "formatting_string",
}

Veil Shader

A specific veil shader to use. This will work for any registered veil shader.

{
  "type": "veil:shader",
  // Required
  "name": "formatting_string",
}

Transparency

The transparency blend mode to use.

Valid modes:

  • none // default
  • additive
  • lightning
  • glint
  • crumbling
  • translucent

Note: Most blend modes require transparency sorting to be enabled to render properly

{
  "type": "minecraft:transparency",
  // Required
  "mode": "formatting_string",
}

Depth-Test

The kind of depth testing to use. This determines how fragments are chosen to render over others.

Valid modes:

  • never
  • less
  • equal
  • lequal // default
  • greater
  • notequal
  • gequal
  • always
{
  "type": "minecraft:depth_test",
  // Required
  "mode": "formatting_string",
}

Cull

The faces to cull if desired.

Valid faces:

  • front
  • back // default
  • front_and_back
  • none
{
  "type": "minecraft:cull",
  // Required
  "face": "formatting_string",
}

Lightmap

Enables/disables the lightmap texture. By default, this layer enables the lightmap.

{
  "type": "minecraft:lightmap",
  // Optional
  "enabled": true,
}

Overlay

Enables/disables the overlay texture. By default, this layer enables the overlay.

{
  "type": "minecraft:overlay",
  // Optional
  "enabled": true,
}

Layering

Specifies the layering mode. This works by adding a small offset in view or polygon space to prevent Z-fighting in meshes.

Valid modes:

  • none
  • polygon_offset // default
  • view_offset
{
  "type": "minecraft:layering",
  // Optional
  "mode": "polygon_offset",
}

Output

The framebuffer to draw the result of this render into. The framebuffer field is the name of any transparency or veil framebuffer created.

{
  "type": "minecraft:output",
  // Required
  "framebuffer": "formatting_string",
}

Texturing

Sets the value of TextureMatrix in the shader to a scrolling UV coordinate for the vanilla enchantment glint effect.

{
  "type": "minecraft:texturing",
  // Required
  "scale": 1,
}

Write Mask

Sets the flags to draw into the color and depth buffers.

{
  "type": "minecraft:write_mask",
  // Optional
  "color": true,
  // Optional
  "depth": true,
}

Line

Sets the width of lines when rendering. If width is not specified, the window scale is used instead.

{
  "type": "minecraft:line",
  // Optional
  "width": 42,
}

Color Logic

Enables OpenGL color logic with the specified operation. In Vanilla MC this is used for making the text selection in GUIs an inverted color (or_reverse).

Valid operations:

  • and
  • and_inverted
  • and_reverse
  • clear
  • copy
  • copy_inverted
  • equiv
  • invert
  • nand
  • noop
  • nor
  • or
  • or_inverted
  • or_reverse
  • set
  • xor
{
  "type": "minecraft:color_logic",
  // Required
  "operation": "formatting_string",
}

Patches

Sets the per-vertex patch size when using tessellation shaders.

{
  "type": "veil:patches",
  // Required
  "patchVertices": 4,
}
Clone this wiki locally