Work In Progress / 14 January 2025
Building Slime in Unreal Engine 5 : A Deep Dive into Shaders and Trail VFX
When I set out to create a slime shader in Unreal Engine, I wanted something that felt alive—squishy, translucent, and interactive. The challenge wasn’t just about making it look cool, but also ensuring it deformed fluidly and performed efficiently in real-time. This journey involved exploring advanced techniques, weighing their pros and cons, and experimenting until I found the perfect balance. Here’s how I approached the slime shader and its dynamic trail system, with an honest look at what worked and what didn’t.
Step 1: Creating the Slime Shader
The first task was building the slime itself—something that would feel gooey and dynamic while reacting to its environment. Achieving this meant experimenting with deformation techniques, translucency, and material tricks like refraction and fresnel highlights.
The Challenge: Realistic Deformation
Slime isn’t static; it interacts with its surroundings. I explored three different techniques for creating dynamic deformation, each with unique strengths and weaknesses.
1. Custom Fluid Physics Simulation
- What It Does: Simulates how fluids move and interact in real time, creating incredibly realistic slime deformation.
Why I Passed:
- Performance: Custom fluid physics simulations are computationally demanding. They can tank frame rates in real-time applications like games.
- Complexity: Asher Zhu’s beautiful implementation here is an inspiration, https://x.com/vuthric?lang=en&mx=2 Fluid sims often require expertise in physics engines or heavy use of custom shaders.
- Estimated Performance Impact:
- Cost: ~6–10 ms/frame depending on resolution and complexity.
- Use Case: Great for pre-rendered effects but rarely feasible for real-time games.
2. Raymarching in the Opacity Channel
- What It Does: Raymarching allows for visually stunning effects by calculating light rays interacting with a semi-transparent medium. It excels in creating detailed, layered materials like slime.

Why I Passed:
- Performance: Raymarching adds a heavy computational load, especially when used in translucent materials with refraction.
- Implementation Challenges: I prototyped a raymarching setup using a custom node inspired by this resource https://iquilezles.org/articles/distfunctions/. While it looked promising, edge-case bugs like visual breaks at certain angles made it inefficient to implement.
- Estimated Performance Impact:
- Cost: ~8–12 ms/frame, heavily GPU-dependent.
- Use Case: Interesting for cinematic visuals but not worth the cost
3. Distance Fields in World Position Offset (WPO)
- What It Does: Distance fields store data about the distance of any point from the nearest surface, enabling dynamic deformation based on nearby geometry. By plugging this into the WPO, the slime could bulge, flatten, or warp based on the objects it touched.
- Why I Chose It:
- Performance: Distance fields are GPU-efficient and natively supported in Unreal Engine.
- Cost: ~1–3 ms/frame, depending on scene complexity.
- Ease of Use: Relatively easy to integrate.
- Interactivity: Allowed the slime to dynamically respond to its environment in a believable way.
- Balanced Visual Quality: While not as detailed as raymarching or fluid simulation, the results were more than sufficient for gameplay.
Final Shader Setup
Translucency and Refraction:
-Translucent material with refraction gave the slime its jelly-like appearance.
- Fresnel highlights added glowing edges for an organic, wet feel.
Dynamic Deformation (WPO):
- Distance fields powered the deformation, letting the slime interact with nearby objects dynamically.
Subtle Wobble:
- Noise-driven WPO added a jiggle effect, bringing the slime to life as it moved.
Step 2: Crafting the Slime Trail
Once the slime shader was complete, the next challenge was to create a dynamic trail system. The slime needed to leave a lasting mark on any surface it touched, enhancing the sense of interaction and presence.
Trail Techniques: Trial and Error
I experimented with several techniques to achieve this, comparing their performance and visual quality along the way.
1. Decals + Niagara
What I Tried: Used deferred decals to project trails in real time.
Mesh Decal Renderer Niagara
Pros:
- Easy to implement and supports dynamic updates.
- High visual fidelity with detailed textures and blending options.
Cons:
- Performance: Multiple decals or large areas increased GPU overdraw, costing ~2–4 ms/frame for heavy use.
- Terrain Limitations: Distortion on uneven terrain reduced immersion.
2. Render Targets (paint into a texture)
What I tried: stamping particle hits into a TextureRenderTarget2D with Blueprint (Draw Material to Render Target), then using that mask in the ground material.
Why I didn’t use it for open world:
Gets blurry at scale. One RT stretched over a big landscape softens fast unless you crank the resolution.
Not cheap to update. Drawing to an RT every frame adds up.
Where I’d use it: small arenas/caves or painterly effects that need history (blur/erosion/drying). For big worlds you’d need tiled RTs per area, which is a bigger engineering ask.
3) Runtime Virtual Textures (RVT) + Niagara-driven HISM “stamps”
Instead of decals or RTs, I now spawn Hierarchical Instanced Static Mesh stamps from Niagara data and write into an RVT. The landscape samples that RVT to reveal the trail. RVT is built to cache shading over large areas and blend decal-like effects into terrain, so it feels seamless.
How it works:
Niagara → Blueprint: Niagara exports per-particle data (Position, optional Normal/Radius/Alpha). The Blueprint receives it and adds/updates HISM instances at those spots.
Stamps → RVT write: Each HISM uses an opaque/unlit material with Runtime Virtual Texture Output to write a soft mask (SphereMask) into the RVT. The component is set to Render to Virtual Textures and sits inside an RVT Volume that covers the area.
World reads it: The landscape material samples the RVT
Pros:
- World-aligned & streaming-friendly. Made for landscapes; looks integrated on slopes
- Scales well. HISMs batch efficiently, unlike piles of overlapping decals.
- One unified look. Any surface wired to the RVT sees the same trail.
Cons:
- it isn’t “free.” You have to shape the stamps so the trail feels intentional, not dotted.
WIP ...
Report