Featured Article

Getting started with volume shaders: a beginner guide

Volume Shader Team
2025-10-29
7 min read
763 views
Tutorial
Beginner
GLSL
Getting started with volume shaders: a beginner guide

Getting started with volume shaders: a beginner guide

A volume shader renders something you can look through: fog, smoke, clouds, fire, nebulae, medical scans, or abstract fields. Instead of drawing only a surface, the shader samples many points along a ray and accumulates color and density.

The core idea is simple: send a ray into a volume, step forward, sample density, add color, and stop when the ray leaves the scene or the result is opaque enough.

A beginner ray marching diagram through a transparent smoke volume

The basic loop

A beginner volume shader usually has four parts: a camera ray, a marching loop, a density function, and color accumulation.

float t = 0.0;
vec3 color = vec3(0.0);

for (int i = 0; i < 64; i++) {
  vec3 p = rayOrigin + rayDirection * t;
  float density = sampleDensity(p);
  color += density * vec3(0.3, 0.8, 1.0);
  t += 0.03;
}

This is not a complete renderer, but it shows the shape of the work. Most volume effects are variations on this loop.

Density creates the object

The density function decides what exists inside the volume. It can be a sphere, a noise field, a texture, or a fractal. High density adds visible material. Low density lets the ray pass through.

A node-like overview of volume shader building blocks

Start with a sphere or soft noise. Once the density feels right, add color ramps and simple lighting. Do not begin with a complex fractal unless you already understand the loop.

Why performance changes quickly

Volume shaders are expensive because the fragment shader does repeated work for every pixel. Doubling the ray steps roughly doubles the cost. Raising resolution multiplies the number of pixels before the shader even starts marching.

The most useful controls are ray steps, step size, density complexity, device pixel ratio, and early exit behavior. In the editor, tune those values before adding more visual features.

First experiments

Open the presets page and choose Fog Sphere. Change the density multiplier, then the ray step count, then the color. After each change, ask what changed visually and why.

Once the loop feels natural, move to smoke, clouds, and fractals. You can use the GPU test to see how heavier shaders behave on your hardware.

FAQ

What is a volume shader in simple terms?
A volume shader renders material inside space instead of only a surface. It samples points along a ray and accumulates color and density for effects like fog, smoke, clouds, and abstract fields.
What should I learn first: ray marching or noise?
Learn the ray marching loop first. Once you understand camera rays, step size, density, and accumulation, noise becomes a useful way to shape the volume.
Why do volume shaders get slow so quickly?
They repeat work for every pixel and every ray step. Increasing resolution, ray steps, noise octaves, or fractal iterations can multiply the fragment shader cost.

Related Articles

Enjoyed this article?

Stay updated with the latest volume shading tutorials, techniques, and updates delivered straight to your inbox.

Subscribe to our newsletter