### Example Shader Program with Definitions (Veil) - JSON5 Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Presents a complete example of a shader program configuration file in JSON5 format. It specifies the vertex and fragment shaders and includes a list of definitions required by this program, demonstrating how to include definitions within the program file. ```JSON5 { "vertex": "veil:example", "fragment": "veil:example", "definitions": [ "example_definition" ] } ``` -------------------------------- ### Veil Shader Program Definition (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Defines a shader program named 'example:test_shader'. It specifies 'veil:blit_screen' as the vertex shader (standard for screen-space effects) and 'example:test_shader' as the fragment shader, linking the program name to the fragment shader file. ```json5 { "vertex": "veil:blit_screen", // This should almost always be veil:blit_screen "fragment": "example:test_shader" } ``` -------------------------------- ### Creating and Using a Veil Animation Path in Java Source: https://github.com/nk3t/veil-wiki/blob/main/Animations.md This Java example demonstrates how to create a `Path` object by providing a list of `Keyframe`s. It then shows how to use the `frameAtProgress` method within a block entity render method to get the position for rendering based on the animation progress. ```Java Path arcPath=new Path(List.of( new Keyframe(new Vec3(0.5,0.5,-0.5),Vec3.ZERO,Vec3.ZERO,20,Easings.Easing.linear), new Keyframe(new Vec3(0.5,0.5,-0.5),Vec3.ZERO,Vec3.ZERO,5,Easings.Easing.easeInQuad), new Keyframe(new Vec3(0.5,1.15,-0.5),Vec3.ZERO,Vec3.ZERO,10,Easings.Easing.easeInBounce), new Keyframe(new Vec3(0.5,1.2,-0.25),Vec3.ZERO,Vec3.ZERO,5,Easings.Easing.easeInBounce), new Keyframe(new Vec3(0.5,1.2,0.25),Vec3.ZERO,Vec3.ZERO,5,Easings.Easing.easeInBounce), new Keyframe(new Vec3(0.5,1.2,0.75),Vec3.ZERO,Vec3.ZERO,10,Easings.Easing.easeInBounce), // Loop, then Bézier ),false,true) // block entity render method public void render(MyBlockEntity blockEntity,...){ //... int processingTicks=blockEntity.getProcessingTime(); Vec3 renderPos=arcPath.frameAtProgress(processingTicks/30f).position(); poseStack.translate(renderPos.x,renderPos.y,renderPos.z); //... } ``` -------------------------------- ### Example pack.mcmeta for Quasar Resource Pack (JSON) Source: https://github.com/nk3t/veil-wiki/blob/main/Quasar.md Provides a basic `pack.mcmeta` file configuration for a resource pack intended for use with Quasar particles. It specifies the `pack_format` (15 for Minecraft 1.20.1) and a descriptive text. ```json { "pack": { "pack_format": 15, "description": "Resource pack for testing Quasar" } } ``` -------------------------------- ### Veil Post-Processing Configuration (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Defines a post-processing stage using the 'veil:blit' type, applying the 'example:test_shader' to the 'minecraft:main' framebuffer. This configuration is typically placed in a post-processing JSON file. ```json5 { "stages": [ { "type": "veil:blit", "shader": "example:test_shader", // My custom shader "in": "minecraft:main" } ] } ``` -------------------------------- ### Defining Shader Program JSON Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Example JSON file defining a shader program, specifying vertex and fragment shaders and a texture. This file links shader source files and necessary textures. ```json { "vertex": "example", "fragment": "example", "textures": { "CustomTexture": "veil:textures/gui/item_shadow.png" } } ``` -------------------------------- ### Adding Veil Dependency (Neoforge) - Groovy Source: https://github.com/nk3t/veil-wiki/blob/main/Home.md Configures a Gradle build script to include the Veil library as an implementation dependency for a Neoforge project. It adds the necessary Maven repository and specifies the dependency artifact, excluding certain transitive dependencies. ```Groovy repositories { maven { name = 'BlameJared Maven (CrT / Bookshelf)' url = 'https://maven.blamejared.com' } } dependencies { implementation("foundry.veil:veil-neoforge-${project.minecraft_version}:${project.veil_version}") { exclude group: "maven.modrinth" exclude group: "me.fallenbreath" } } ``` -------------------------------- ### Drawing During Render Stages with Veil (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/RenderTypeStage.md This snippet illustrates how to use `VeilEventPlatform.INSTANCE.onVeilRenderTypeStageRender` to execute custom drawing logic during specific `VeilRenderLevelStageEvent.Stage`s. It shows how to obtain a `VertexConsumer` for a `RenderType` and perform drawing operations, explaining the importance of manually ending non-fixed buffers while fixed buffers are ended automatically. It also includes a repeated example of registering fixed buffers. ```java import com.mojang.blaze3d.vertex.VertexConsumer; import foundry.veil.api.event.VeilRenderLevelStageEvent; import foundry.veil.platform.services.VeilEventPlatform; public class RenderingClass { private static final RenderType CUSTOM_RENDER_TYPE = ...; private static final RenderType COOL_CUSTOM_RENDER_TYPE = ...; public static void init() { // This will draw custom things after particles have drawn VeilEventPlatform.INSTANCE.onVeilRenderTypeStageRender((stage, levelRenderer, bufferSource, poseStack, projectionMatrix, renderTick, partialTicks, camera, frustum) -> { if (stage == VeilRenderLevelStageEvent.Stage.AFTER_SKY) { VertexConsumer builder = bufferSource.getBuffer(CUSTOM_RENDER_TYPE); // Draw things // don't end buffer because it's a fixed buffer. It will be automatically finished after particles } else if (stage == VeilRenderLevelStageEvent.Stage.AFTER_PARTICLES) { VertexConsumer builder = bufferSource.getBuffer(COOL_CUSTOM_RENDER_TYPE); // Draw things // End buffer because it is not a fixed buffer bufferSource.endBatch(COOL_CUSTOM_RENDER_TYPE); } }); // Fixed buffers and arbitrary drawing can be combined // Buffers defined to end after a specific event will always finish after the event fires VeilEventPlatform.INSTANCE.onVeilRegisterFixedBuffers(registry -> { // Fixed buffers can also be used to allow arbitrary drawing without ending the buffer registry.registerFixedBuffer(VeilRenderLevelStageEvent.Stage.AFTER_PARTICLES, CUSTOM_RENDER_TYPE); }); } } ``` -------------------------------- ### Example Veil GLSL Include Shader (foo.glsl) Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md This GLSL code represents a simple include shader file (`foo.glsl`) located in the include directory. It defines a basic function `foo` that can be imported and reused in other shaders or include files. ```glsl vec3 foo(vec4 color) { return color.rgb; } ``` -------------------------------- ### Handling Veil Events (Common/Platform-Independent) - Java Source: https://github.com/nk3t/veil-wiki/blob/main/Events.md Demonstrates how to subscribe to a Veil event using the platform-independent VeilEventPlatform. This approach works regardless of whether the mod is running on Forge or Fabric. The listener is provided as a lambda function. ```Java import foundry.veil.event.FreeNativeResourcesEvent; import foundry.veil.platform.services.VeilEventPlatform; // This class is platform independent, so it uses the veil platform method public class ModCommon { public static void initCommon() { VeilEventPlatform.INSTANCE.onFreeNativeResources(() -> { // listener here }); } } ``` -------------------------------- ### Example Veil GLSL Include Shader (bar.glsl) Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md This GLSL code shows an include shader (`bar.glsl`) that demonstrates including another include shader (`veil:foo`) and then using the function defined in the included file. This illustrates code sharing between include shaders. ```glsl #include veil:foo vec3 bar(vec4 color) { return foo(color) / 2.0; } ``` -------------------------------- ### Adding Veil Dependency (Common) - Groovy Source: https://github.com/nk3t/veil-wiki/blob/main/Home.md Configures a Gradle build script to include the Veil library as an implementation dependency for a common module. It adds the necessary Maven repository and specifies the dependency artifact, excluding certain transitive dependencies. ```Groovy repositories { maven { name = 'BlameJared Maven (CrT / Bookshelf)' url = 'https://maven.blamejared.com' } } dependencies { implementation("foundry.veil:veil-common-${project.minecraft_version}:${project.veil_version}") { exclude group: "maven.modrinth" exclude group: "me.fallenbreath" } } ``` -------------------------------- ### Simple Texture Sampling Fragment Shader GLSL Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Example GLSL fragment shader that samples a texture named 'CustomTexture' using provided texture coordinates and outputs the color. It demonstrates basic texture lookup. ```glsl uniform sampler2D CustomTexture; in vec2 texCoord; out vec4 fragColor; void main() { fragColor = texture(CustomTexture, texCoord); } ``` -------------------------------- ### Adding Veil Dependency (Fabric) - Groovy Source: https://github.com/nk3t/veil-wiki/blob/main/Home.md Configures a Gradle build script to include the Veil library as a mod implementation dependency for a Fabric project. It adds the necessary Maven repository and specifies the dependency artifact, excluding certain transitive dependencies. ```Groovy repositories { maven { name = 'BlameJared Maven (CrT / Bookshelf)' url = 'https://maven.blamejared.com' } } dependencies { modImplementation("foundry.veil:veil-fabric-${project.minecraft_version}:${project.veil_version}") { exclude group: "maven.modrinth" exclude group: "me.fallenbreath" } } ``` -------------------------------- ### Resource Pack Structure for Quasar Particles (Markdown) Source: https://github.com/nk3t/veil-wiki/blob/main/Quasar.md Defines the required folder structure within a Minecraft resource pack for housing Quasar particle definitions. It shows the hierarchy starting from the `resourcepacks` folder down to specific particle component directories. ```markdown resourcepacks \-particles |-pack.mcmeta \-assets \-modid \-quasar |-emitters |-modules |-render |-update |-init |-force |---collision \-particle_data \-emitter \-particle \-shape ``` -------------------------------- ### Example Data-Driven Render Type Definition (JSON) Source: https://github.com/nk3t/veil-wiki/blob/main/CustomRenderType.md Provides a concrete example of a render type defined in a JSON file, illustrating the structure and common layers like texture, shader, depth test, cull, lightmap, and write mask. ```json { "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 } ] } ``` -------------------------------- ### Registering Fixed Render Buffers with Veil (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/RenderTypeStage.md This code demonstrates how to register custom `RenderType`s as fixed buffers using `VeilEventPlatform.INSTANCE.onVeilRegisterFixedBuffers`. It shows how to specify a `VeilRenderLevelStageEvent.Stage` to automatically end the buffer batch after that stage, or pass `null` to require manual ending of the buffer. This helps manage rendering batches for custom render types. ```java import foundry.veil.api.event.VeilRenderLevelStageEvent; import foundry.veil.platform.services.VeilEventPlatform; public class RenderingClass { private static final RenderType CUSTOM_RENDER_TYPE = ...; private static final RenderType COOL_CUSTOM_RENDER_TYPE = ...; public static void init() { VeilEventPlatform.INSTANCE.onVeilRegisterFixedBuffers(registry -> { // This will make it so anything using this render type will be batched together and drawn after particles registry.registerFixedBuffer(VeilRenderLevelStageEvent.Stage.AFTER_PARTICLES, CUSTOM_RENDER_TYPE); // This will register the render type as a fixed buffer, but will not end it // It is up to the programmer to finish this render type when it needs to finish registry.registerFixedBuffer(null, COOL_CUSTOM_RENDER_TYPE); }); } } ``` -------------------------------- ### Setting Uniforms for Veil Shaders (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md This Java example demonstrates how to obtain a Veil `ShaderProgram` instance, set custom float and matrix uniforms using their names, bind the shader for rendering, and then unbind it. Uniforms are automatically detected by name. ```java import com.mojang.blaze3d.vertex.PoseStack; import foundry.veil.Veil; import foundry.veil.api.client.render.VeilRenderSystem; import foundry.veil.api.client.render.shader.program.ShaderProgram; import net.minecraft.resources.ResourceLocation; import org.joml.Matrix4f; public class RenderClass { private static final ResourceLocation CUSTOM_SHADER = Veil.veilPath("test_shader"); public static void render(PoseStack stack, MultiBufferSource source, float partialTicks) { ShaderProgram shader = VeilRenderSystem.setShader(CUSTOM_SHADER); if (shader == null) { return; } shader.setFloat("CustomValue", 37.2F); shader.setMatrix("CustomProjection", new Matrix4f().ortho(0, 10, 10, 0, 0.3F, 100.0F, false)); shader.bind(); // rendering code here ShaderProgram.unbind(); } } ``` -------------------------------- ### Handling Veil Events (Forge) - Java Source: https://github.com/nk3t/veil-wiki/blob/main/Events.md Shows how to subscribe to a Veil event when running on the Forge platform. This uses the standard Forge event bus and the @SubscribeEvent annotation with the Forge-specific event class (ForgeFreeNativeResourcesEvent). The class needs to be registered with the MinecraftForge event bus. ```Java import foundry.veil.forge.event.ForgeFreeNativeResourcesEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod("modid") public class ModForge { public ModForge() { MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onEvent(ForgeFreeNativeResourcesEvent event) { // listener here } } ``` -------------------------------- ### Defining Custom Attributes and Buffers for VertexArray (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/VertexArray.md Provides a comprehensive example of using VertexArray with custom OpenGL buffers. It shows how to create and manage multiple owned buffers, upload vertex and index data manually, define a custom vertex format using VertexArrayBuilder with multiple attribute streams, apply vanilla formats, bind the array, draw, and free resources. ```Java VertexArray vertexArray = VertexArray.create(); // Arbitrary OpenGl buffers can be created int defaultVbo = vertexArray.getOrCreateBuffer(VertexArray.VERTEX_BUFFER); int extraVbo = vertexArray.getOrCreateBuffer(2); int vanillaVbo = vertexArray.getOrCreateBuffer(3); try (MemoryStack stack = MemoryStack.stackPush()) { ByteBuffer vertexData = stack.malloc(Float.BYTES * 5 * 4); // Put data in the buffer vertexData.asFloatBuffer().put(new float[]{ 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F }); // Upload the data into the buffer VertexArray.upload(defaultVbo, vertexData, VertexArray.DrawUsage.STATIC); // Upload some extra data to another buffer ByteBuffer extraData = stack.malloc(Integer.BYTES * 4); extraData.asIntBuffer().put(new int[]{0xFFFFFFFF, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF}); VertexArray.upload(extraVbo, extraData, VertexArray.DrawUsage.STATIC); // Manually upload indices vertexArray.uploadIndexBuffer(stack.bytes( (byte) 0, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 0 )); vertexArray.setIndexCount(6, VertexArray.IndexType.BYTE); vertexArray.setDrawMode(VertexFormat.Mode.TRIANGLES); // 1.2.0+ equivalent vertexArray.uploadIndexBuffer(stack.bytes( (byte) 0, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 0 ), VertexArray.IndexType.BYTE); } // Set up vertex format VertexArrayBuilder builder = vertexArray.editFormat(); // 5 floats per vertex builder.defineVertexBuffer(0, defaultVbo, 0, Float.BYTES * 5, 0); // 1 integer per vertex builder.defineVertexBuffer(1, extraVbo, 0, Integer.BYTES, 0); // Position builder.setVertexAttribute(0, 0, 3, VertexArrayBuilder.DataType.FLOAT, false, 0); // UV builder.setVertexAttribute(1, 0, 2, VertexArrayBuilder.DataType.FLOAT, false, Float.BYTES * 3); // Color builder.setVertexAttribute(2, 1, 4, VertexArrayBuilder.DataType.UNSIGNED_BYTE, false, 0); // Defines the vertex data to be pulled from the specified buffer and how the vanilla attributes should be applied builder.applyFrom(3, vanillaVbo, 2, DefaultVertexFormat.PARTICLE); vertexArray.bind(); vertexArray.draw(); // You can also use a render type to draw vertexArray.drawWithRenderType(RenderType.solid()); // Frees the vertex array and all owned verted buffers vertexArray.free(); ``` -------------------------------- ### Registering Render Type Stages with Veil (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/RenderTypeStage.md This snippet shows how to use `RenderTypeStageRegistry` to add custom or vanilla `RenderStateShard` instances to Minecraft `RenderType`s. It covers adding stages to specific render types by instance or string name, and adding generic stages based on a predicate. This allows modifying the rendering pipeline for existing or custom render types. ```java import foundry.veil.api.client.render.RenderTypeStageRegistry; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; public class CoolMod { public static void initClient() { // This adds arbitrary code to setup/clear for the solid render type RenderTypeStageRegistry.addStage(RenderType.solid(), new RenderStateShard("coolmod:debug", () -> System.out.println("Setting up solid blocks"), () -> System.out.println("Clearing up solid blocks")) { }); // Regular states can be added too RenderTypeStageRegistry.addStage(RenderType.cutout(), RenderType.TRANSLUCENT_TARGET); // This adds the particle shader to all render types that don't define a shader RenderTypeStageRegistry.addGenericStage(renderType -> renderType.state().shaderState == RenderType.NO_SHADER, new RenderStateShard.ShaderStateShard(GameRenderer::getParticleShader)); // Other mods can also have their render types modified if a string is used RenderTypeStageRegistry.addStage("coolmod:custom_render_type", RenderType.TRANSLUCENT_TARGET); } } ``` -------------------------------- ### Configuring Texture Filters in JSON5 Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Syntax example for defining texture sampling parameters within a shader program configuration, including filtering, mipmapping, anisotropy, wrapping, and border options. This overrides OpenGL texture object parameters. ```json5 "textures": { "TextureName": { "type": "location", "location": "minecraft:textures/atlas/particles.png", "filter": { "blur": false, // Whether the texture should use linear or nearest filtering "mipmap": false, // Whether the texture should use mipmaps "anisotropy": 1.0, // The maximum allowed level of "anisotropy". Any value > 1 enables anisotropic filtering (https://en.wikipedia.org/wiki/Anisotropic_filtering) "compareFunction": "never|always|less|lequal|equal|not_equal|gequal|greater", // Optional parameter. Indicates the type of depth comparison to make if a depth texture. Mostly used for shadow-mapping to allow correct interpolation when using blur (https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexParameter.xhtml) "wrapX|wrapY|wrapZ": "repeat|clamp_to_edge|clamp_to_border|mirrored_repeat|mirror_clamp_to_edge", // Default is repeat. Indicates how the texture should be sampled if the texture coordinates fall outside the range of 0 to 1 (for X/Y/Z S/T/R respectively) "borderColor": "0xFF000000", // Custom color when using clamp_to_border, "borderType": "float|int|uint", // Must be set when using an integer texture "seamless": false // Specifies cubemap textures to be sampled as seamless textures } } } ``` -------------------------------- ### Handling Veil Events (Fabric) - Java Source: https://github.com/nk3t/veil-wiki/blob/main/Events.md Illustrates how to subscribe to a Veil event when running on the Fabric platform. This utilizes the Fabric event registration mechanism, typically done within the client initializer for client-side events. It uses the Fabric-specific event class (FabricFreeNativeResourcesEvent). ```Java import foundry.veil.fabric.event.FabricFreeNativeResourcesEvent; import net.fabricmc.api.ClientModInitializer; public class ModFabric implements ClientModInitializer { @Override public void onInitializeClient() { FabricFreeNativeResourcesEvent.EVENT.register(() -> { // listener here }); } } ``` -------------------------------- ### Veil Fog Fragment Shader (GLSL) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Implements the fragment shader logic for the custom fog effect. It samples the main color and depth textures, calculates the camera-relative position using depth, determines the distance for fog using a Veil helper function, and applies linear fog based on configurable start, end, color, and shape parameters. ```glsl #include veil:fog #include veil:space_helper // The first color attachment from `in` uniform sampler2D DiffuseSampler0; // The depth attachment from `in` uniform sampler2D DiffuseDepthSampler; const float FogStart = -10; const float FogEnd = 40; uniform vec4 FogColor; uniform int FogShape; in vec2 texCoord; out vec4 fragColor; void main() { // Sample from the screen vec4 baseColor = texture(DiffuseSampler0, texCoord); // Sample from the depth texture float depthSample = texture(DiffuseDepthSampler).r; // Calculate the camera-relative position vec3 pos = screenToLocalSpace(texCoord, depthSample).xyz; // For fog, find the distance from the player float vertexDistance = fog_distance(pos, FogShape); // Output the mixed fog with the vanilla fog equation fragColor = linear_fog(baseColor, vertexDistance, FogStart, FogEnd, FogColor); } ``` -------------------------------- ### Implementing Layered Rendering for a Spider Entity (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/RenderTypeStage.md This Java code snippet demonstrates how to create a custom entity renderer that utilizes Veil's layered render types. It defines a `COOL_RENDER_TYPE` using `VeilRenderType.layered` to combine multiple `RenderType` instances (base texture, armor, spots) for a single entity model, allowing them to be drawn in one pass. The `getRenderType` method is overridden to return this layered type under specific conditions. ```java import com.mojang.blaze3d.vertex.PoseStack; import foundry.veil.api.client.render.VeilRenderType; import net.minecraft.client.model.SpiderModel; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.monster.Spider; import org.jetbrains.annotations.Nullable; public class CoolSpiderEntityRenderer extends LivingEntityRenderer> { private static final ResourceLocation BASE_TEXTURE = new ResourceLocation("veil", "textures/entity/spider/base.png"); private static final ResourceLocation ARMOR_TEXTURE = new ResourceLocation("veil", "textures/entity/spider/red_armor.png"); private static final ResourceLocation SPOT_TEXTURE = new ResourceLocation("veil", "textures/entity/spider/spot0.png"); private static final RenderType COOL_RENDER_TYPE = VeilRenderType.layered( RenderType.entityCutoutNoCull(BASE_TEXTURE), RenderType.entityCutoutNoCull(ARMOR_TEXTURE), RenderType.entityCutoutNoCull(SPOT_TEXTURE)); public CoolSpiderEntityRenderer(EntityRendererProvider.Context ctx) { super(ctx, new SpiderModel<>(ctx.bakeLayer(ModelLayers.SPIDER)), 1.0F); } @Override protected @Nullable RenderType getRenderType(Spider spider, boolean visible, boolean translucent, boolean glowing) { ResourceLocation textureLocation = this.getTextureLocation(spider); if (translucent) { return RenderType.itemEntityTranslucentCull(textureLocation); } else if (visible) { // This will draw all parts without having to re-draw the entire model return COOL_RENDER_TYPE; } else { return glowing ? RenderType.outline(textureLocation) : null; } } // In this example, the base texture will be used for glowing and semi-visible entities @Override public ResourceLocation getTextureLocation(Spider spider) { return BASE_TEXTURE; } } ``` -------------------------------- ### Defining Shader Definitions Syntax (Veil) - JSON5 Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Illustrates the JSON5 structure for specifying shader definitions. It shows how to list simple definition names and how to provide a definition with a default value using an object. This syntax is used within a shader program configuration file. ```JSON5 { "definitions": [ "foo", "bar", { "defaultValue": 4 } ] } ``` -------------------------------- ### Defining Veil Shader Modification Syntax Source: https://github.com/nk3t/veil-wiki/blob/main/ShaderModification.md This snippet illustrates the basic syntax and structure of a Veil shader modification file (.vsh.txt). It shows how to specify the shader version, priority, include other files, optionally replace the target shader, and define injection points using commands like [GET_ATTRIBUTE], [OUTPUT], [UNIFORM], and [FUNCTION]. ```text #version 330 // required #priority 1000 // default 1000 #include veil:camera // Test include // Replaces this with the defined shader // #replace veil:shader/test // Vertex Only [GET_ATTRIBUTE 0] vec3 InPos; // test [GET_ATTRIBUTE 4] vec3 Nom; [OUTPUT] // Outputs are guaranteed to be unique out vec4 Test; out vec3 TestNormal; [UNIFORM] uniform sampler2D Sampler8; [FUNCTION main(0) HEAD] TestNormal = #Nom; Test = vec4(#InPos, 1.0); ``` -------------------------------- ### Defining Veil Copy Stage (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Configures a 'copy' stage within a Veil post-pipeline, used for copying buffer contents from an input framebuffer ('in') to an output framebuffer ('out') without using a shader. It includes optional flags for copying color and depth buffers and enabling linear filtering. ```JSON5 { "type": "veil:copy", // Optional // The input scene is stored in veil:post "in": "modid:framebufferid", // Required // The framebuffer to draw into. It is generally good practice to draw into veil:post on the last stage "out": "modid:framebufferid", // Optional // Whether to copy color buffers "color": false, // Optional // Whether to copy depth buffers "depth": false, // Optional // Whether to use linear filtering if the out size does not equal the in size "linear": false } ``` -------------------------------- ### Initializing a Custom Skeleton in Java Source: https://github.com/nk3t/veil-wiki/blob/main/Necromancer.md Demonstrates creating a custom Skeleton class by extending `Skeleton`, initializing Bone objects with names and initial transforms, adding them to the skeleton, defining parent-child relationships between bones, and calling `buildRoots()` to finalize the structure. Requires the Veil Necromancer library. ```Java public class ExampleSkeleton extends Skeleton { protected final Bone Head, Body, LeftLeg, RightLeg; public ExampleSkeleton(ExampleEntity parent) { super(); this.Body = new Bone("Body"); this.Body.setInitialTransform(0F, 16F, 0F, new Quaternionf().rotationZYX(0F, 0F, 0F)); this.addBone(Body); this.Head = new Bone("Head"); this.Head.setInitialTransform(0F, 8F, 0F, new Quaternionf().rotationZYX(0F, 0F, 0F)); this.addBone(Head); this.LeftLeg = new Bone("LeftLeg"); this.LeftLeg.setInitialTransform(-8F, -8F, 0F, new Quaternionf().rotationZYX(1.5F, 0F, 0F)); this.addBone(LeftLeg); this.RightLeg = new Bone("RightLeg"); this.RightLeg.setInitialTransform(8F, 8F, 0F, new Quaternionf().rotationZYX(1.5F, 0F, 0F)); this.addBone(RightLeg); this.Body.addChild(Head); this.Body.addChild(RightLeg); this.Body.addChild(LeftLeg); this.buildRoots(); } } ``` -------------------------------- ### Defining Veil Blit Stage (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Configures a 'blit' stage within a Veil post-pipeline, used for drawing a quad with a specified shader. It requires 'shader' and 'out' parameters, and optionally takes an 'in' framebuffer and a 'clear' flag to clear the output buffer. ```JSON5 { "type": "veil:blit", // Required "shader": "modid:shaderid", // Optional // The input scene is stored in veil:post "in": "modid:framebufferid", // Required // The framebuffer to draw into. It is generally good practice to draw into veil:post on the last stage "out": "modid:framebufferid", // Optional // Whether to clear the out buffer before drawing "clear": true } ``` -------------------------------- ### Uploading Vertex Data to VertexArray (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/VertexArray.md Demonstrates the process of creating a VertexArray, building vertex data using Minecraft's BufferBuilder, uploading the data to the VertexArray, binding it for rendering, drawing the data, and finally freeing the resources. ```Java // This initializes the data BufferBuilder builder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // Build mesh builder.addVertex(0, 0, 0).setColor(-1); builder.addVertex(0, 1, 0).setColor(-1); builder.addVertex(1, 1, 0).setColor(-1); builder.addVertex(1, 0, 0).setColor(-1); VertexArray vertexArray = VertexArray.create(); vertexArray.upload(builder.buildOrThrow(), VertexArray.DrawUsage.STATIC); // This goes inside a render loop { // Make sure to bind vertexArray.bind(); // Draw data vertexArray.drawWithRenderType(RenderType.debugQuads()); } // When not being used anymore, make sure to free it vertexArray.free(); ``` -------------------------------- ### Defining Veil Shader Program Structure (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md This JSON5 snippet illustrates the structure used to define a Veil shader program. It specifies the paths to the shader stage files, lists global definitions, and defines textures to be bound, including various texture source types like locations and framebuffers. ```json5 { // Optional "vertex": "modid:shaderid", // Optional "tesselation_control": "modid:shaderid", // Optional "tesselation_evaluation": "modid:shaderid", // Optional "geometry": "modid:shaderid", // Optional "fragment": "modid:shaderid", // Optional "compute": "modid:shaderid", // Optional "definitions": [ "foo", "bar", { "defaultValue": 4 } ], // Optional "textures": { "LocationTexture": "veil:textures/gui/item_shadow.png", "AlternateLocationTexture": { "type": "location", "location": "minecraft:textures/atlas/particles.png" }, "ExampleFramebuffer": { "type": "framebuffer", "name": "veil:deferred", // This is used to identify what color buffer to sample from "sampler": 4 }, "ExampleFramebufferColor": { "type": "framebuffer", "name": "veil:deferred" }, "ExampleFramebufferDepth": { "type": "framebuffer", "name": "veil:deferred:depth", "filter": { ... } } } } ``` -------------------------------- ### Implementing a Custom Animator in Java Source: https://github.com/nk3t/veil-wiki/blob/main/Necromancer.md Illustrates creating a custom Animator class extending `Animator`, adding an animation using `addAnimation`, and implementing the `animate` method. The `animate` method updates the time and mix factor of the animation entry based on entity state and performs direct bone manipulation (idle bobbing). Includes an inner static `WalkAnimation` class demonstrating the `apply` method. Requires the Veil Necromancer library and potentially a math utility (`Mth`). ```Java public class ExampleAnimator extends Animator { final AnimationEntry walk; public ExampleAnimator(ExampleEntity entity, ExampleSkeleton skeleton) { this.walk = this.addAnimation(WalkAnimation.INSTANCE, 0); } public void animate(ExampleEntity entity) { super.animate(entity); // walk WalkAnimation walkState = entity.walkAnimation; this.walk.setTime(walkState.position()); this.walk.setMixFactor(walkState.speed()); // idle skeleton.Body.y += Mth.sin(entity.tickCount * 0.05F) * 2; } static class WalkAnimation extends Animation { static final INSTANCE = new WalkAnimation(); public void apply(ExampleEntity entity, ExampleSkeleton skeleton, float blendFactor, float time) { skeleton.LeftLeg .rotateDeg(45 * Mth.sin(time) * blendFactor, Direction.Axis.Z); skeleton.RightLeg.rotateDeg(45 * -Mth.cos(time) * blendFactor, Direction.Axis.Z); } } } ``` -------------------------------- ### Defining Shader Definition from Java (Veil) - Java Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Demonstrates how to programmatically define a shader definition using VeilRenderSystem.renderer().getDefinitions().define(). This makes the specified definition available to shaders that depend on it, potentially triggering recompilation. Requires access to the Veil rendering system. ```Java import foundry.veil.render.pipeline.VeilRenderSystem; import foundry.veil.render.pipeline.VeilRenderer; import foundry.veil.render.shader.definition.ShaderPreDefinitions; import foundry.veil.render.shader.program.ShaderProgram; import net.minecraft.resources.ResourceLocation; public class Foo { private static final ResourceLocation SHADER_ID = new ResourceLocation("veil", "example"); // Some event fired before rendering public static void onPreRender() { VeilRenderer renderer = VeilRenderSystem.renderer(); ShaderPreDefinitions definitions = renderer.getDefinitions(); // This adds #define EXAMPLE_DEFINITION to all shaders that depend on it definitions.define("example_definition"); } } ``` -------------------------------- ### Representing IThemeProperties in Veil Color Themes (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/Colors.md Illustrates the structure of key-value pairs within a Veil Color Theme's map when storing different types of IThemeProperties, such as Boolean, Number, String, and Consumer, associated with an Optional key. ```Java Optional,Boolean Optional,Number Optional,String Optional,Consumer ``` -------------------------------- ### Defining a Simple Quasar Module (JSON) Source: https://github.com/nk3t/veil-wiki/blob/main/Quasar.md This JSON snippet demonstrates the basic structure for defining a Quasar module instance. It specifies the type of module to use via the 'module' field. Additional fields would be added to provide parameters required by the specific module. ```json { "module": "die_on_collision" } ``` -------------------------------- ### Loading and Using a Data-Driven Render Type (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/CustomRenderType.md Demonstrates how to load a data-driven render type from a resource location using `VeilRenderType.get` and obtain a `VertexConsumer` for rendering. Includes error handling for loading failures. ```java 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 } } ``` -------------------------------- ### Applying easeOutQuad Easing (Java) Source: https://github.com/nk3t/veil-wiki/blob/main/Easings.md Demonstrates how to apply the easeOutQuad easing function from the Easings utility class in Veil. The `ease` method takes a float value representing the progress (typically between 0 and 1) and returns the eased value. ```Java Easings.Easing.easeOutQuad.ease(float) ``` -------------------------------- ### Defining Veil Post-Pipeline Structure (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Defines the top-level JSON structure for a Veil post-pipeline, including required stages and optional sections for textures, framebuffers, priority, and replacement behavior. The 'priority' and 'replace' fields control how pipelines with the same name are merged or overwritten. ```JSON5 { // Required "stages": [ ... ], // Optional "textures": { ... }, // Optional "framebuffers": { ... }, // Optional "priority": 1000, // Optional "replace": false } ``` -------------------------------- ### Using #include in Veil GLSL Shaders Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md This GLSL snippet demonstrates how to use the `#include` directive within a shader file to import code from a Veil include shader. The imported code becomes available for use in the current shader. ```glsl #include domain:includeid out vec4 fragColor; void main() { fragColor = vec4(1, 0, 1, 1); } ``` -------------------------------- ### Defining Shader Textures Syntax (Veil) - JSON5 Source: https://github.com/nk3t/veil-wiki/blob/main/Shader.md Details the JSON5 syntax for specifying textures within a shader program configuration. It shows how to define textures from file locations (both simple string and object format) and from framebuffers, including specifying a sampler index or using the depth attachment. ```JSON5 { "textures": { "LocationTexture": "veil:textures/gui/item_shadow.png", "AlternateLocationTexture": { "type": "location", "location": "minecraft:textures/atlas/particles.png" }, "ExampleFramebuffer": { "type": "framebuffer", "name": "veil:deferred", "sampler": 4 }, "ExampleFramebufferColor": { "type": "framebuffer", "name": "veil:deferred" }, "ExampleFramebufferDepth": { "type": "framebuffer", "name": "veil:deferred:depth" } } } ``` -------------------------------- ### Spawning Quasar Particles in Java (Fault-Tolerant) Source: https://github.com/nk3t/veil-wiki/blob/main/Quasar.md Provides two fault-tolerant Java methods for spawning Quasar particles. One method attaches the particle to an entity, while the other places it at a specific position. Both methods use a try-catch block to prevent crashes if particle creation fails. ```java public static void spawnParticle(Entity entity, ResourceLocation id){ try { ParticleSystemManager manager = VeilRenderSystem.renderer().getParticleManager(); ParticleEmitter emitter = manager.createEmitter(id); emitter.setAttachedEntity(entity); manager.addParticleSystem(emitter); } catch (Exception ignored) { } } public static void spawnParticle(Vec3 position, ResourceLocation id){ try { ParticleSystemManager manager = VeilRenderSystem.renderer().getParticleManager(); ParticleEmitter emitter = manager.createEmitter(id); emitter.setPosition(position); manager.addParticleSystem(emitter); } catch (Exception ignored) { } } ``` -------------------------------- ### Vanilla Shader Layer Syntax (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/CustomRenderType.md Describes the syntax for the `minecraft:shader` layer, used to specify a vanilla Minecraft shader by name. ```json5 { "type": "minecraft:shader", // Required "name": "formatting_string", } ``` -------------------------------- ### Defining Veil Mask Stage (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Configures a 'mask' stage within a Veil post-pipeline, used to control color and depth writing for all subsequent stages. It includes optional boolean flags to enable or disable writing to individual color channels (red, green, blue, alpha) and the depth buffer. ```JSON5 { "type": "veil:mask", // Optional // Whether to write into the red channel "red": true, // Optional // Whether to write into the green channel "green": true, // Optional // Whether to write into the blue channel "blue": true, // Optional // Whether to write into the alpha channel "alpha": true, // Optional // Whether to write into the depth buffer "depth": false } ``` -------------------------------- ### Defining Multiple Color Buffers in JSON5 Source: https://github.com/nk3t/veil-wiki/blob/main/Framebuffer.md Demonstrates how to define multiple color attachments within the 'color_buffers' array, each with potentially different formats and custom names, illustrating how names create alias bindings for shaders. ```json5 { "depth": true, "color_buffers": [ { "name": "AlbedoSampler", "format": "RGBA8" }, { "name": "NormalSampler", "format": "RGB16F" }, { "name": "MaterialSampler", "format": "R16F" }, { "name": "EmissiveSampler", "format": "RGBA8" }, { "name": "VanillaLightSampler", "format": "RG8" } ] } ``` -------------------------------- ### Defining Veil Depth Function Stage (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/PostProcessing.md Configures a 'depth_function' stage within a Veil post-pipeline, used to set the depth comparison function for all later stages. It requires a 'function' parameter specifying the desired OpenGL depth function name (e.g., "ALWAYS", "LESS", "LEQUAL"). ```JSON5 { "type": "veil:depth_function", // The function to use. The initial value is ALWAYS "function": "ALWAYS" } ``` -------------------------------- ### Multi-Texture Layer Syntax (JSON5) Source: https://github.com/nk3t/veil-wiki/blob/main/CustomRenderType.md Describes the syntax for the `minecraft:multi_texture` layer, allowing assignment of multiple textures to units 0-11, with options for blur and mipmap for each texture. ```json5 { "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) ... ] } ```