---
id: "stylized-nonlinear-monte-carlo"
title: "Stylized nonlinear Monte Carlo rendering"
domain: "npr"
stage: "lighting"
realtime: "offline"
platforms: [cuda, cpu]
year_introduced: 2025
inputs: [mesh, material-params]
outputs: [hdr-image, ldr-image]
style: "stylized"
dynamic: "both"
cost: "offline"
authority: "Tong & Hachisuka, 2025"
url: "https://texelatlas.vercel.app/t/stylized-nonlinear-monte-carlo/"
sources_verified_at: "2026-11-29"
---
# Stylized nonlinear Monte Carlo rendering (Tong & Hachisuka, 2025)

> Applies nonlinear artistic operators inside the path-tracing estimator, so stylization such as banding or thresholding is applied to light transport before it is averaged.

## Reach for it when

- stylisation breaks when path tracing averages samples
- toon banding on indirect light in offline renders
- thresholded shading gets noisy or washed out in pt
- need stylised global illumination in film rendering
- art operators applied before averaging light

## How it works

Ordinary path tracing averages unbiased samples, so applying a nonlinear stylisation (a toon ramp, a threshold) to the final pixel average is not the same as applying it inside the light-transport integral. The paper studies rendering in which artist-defined nonlinear operators act within the Monte Carlo estimator, so that stylisation becomes part of how light bounces (for example banded or thresholded indirect lighting), and develops practical estimators for evaluating those nonlinear expressions from path samples. The result is stylised global illumination rather than a stylised final image. A reference implementation accompanies the paper; see the sources for the project page and code

## When to use it

Choose it for offline stylised films or stills where indirect light must stay stylised. Prefer [Toon / cel shading with lighting ramps](https://texelatlas.vercel.app/t/toon-shading.md) for real-time use where only direct lighting is shaded in toon style, and [Guilty Gear Xrd anime-style 3D shading](https://texelatlas.vercel.app/t/guilty-gear-xrd-shading.md) for artist-directed real-time looks.

## Cost

offline — Offline path-tracing cost; the nonlinearity needs extra samples or estimators for low noise.
Measured GPU Weight: 61.52× baseline (extreme) — 2.024 ms median / 2.1282 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 58.54× baseline (heavy) — 0.9308 ms median (2.17× faster on L4).
Ampere A100 scaling: 40.69× baseline (heavy) — 1.172 ms median (1.73× faster on A100).

## Failure modes

- Nonlinear functions amplify noise, so more samples are needed than for a plain path tracer
- Nonlinear estimators can trade bias against variance
- Hard to preview interactively
- Reference code repository is archived

## Dataflow

- Inputs: mesh, material-params
- Outputs: hdr-image, ldr-image
- Platforms: cuda, cpu

## Presets

### Stylized Nonlinear Monte Carlo — post-average toon ramp (left) vs in-integrator nonlinear sample stylization (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_BANDS": 4,
  "P_PENUMBRA": 0.75,
  "P_BOUNCE_STYLE": 0.85,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_BANDS = 4.00; // P Toon Bands [2.0, 6.0, 1.0]
const float P_PENUMBRA = 0.75; // P Area Light Size [0.15, 1.3, 0.05]
const float P_BOUNCE_STYLE = 0.85; // P Nonlinear Bounce [0.0, 1.2, 0.05]
const float P_SPLIT = 0.48; // P Post-Toon / NL-MC [0.0, 1.0, 0.02]

float hash21(vec2 p) {
  p = fract(p * vec2(127.1, 311.7));
  p += dot(p, p + 34.5);
  return fract(p.x * p.y);
}

// Nonlinear artistic stylization operator phi(L): quantizes luminance into crisp chromatic ink bands!
vec3 nonlinearOp(vec3 rad, float bands) {
  float lum = dot(rad, vec3(0.299, 0.587, 0.114));
  float qLum = floor(clamp(lum, 0.0, 1.4) * bands + 0.35) / bands;
  // Subtle artistic warm-highlight / cool-shadow chromatic shift inside the operator
  vec3 tint = mix(vec3(0.72, 0.84, 1.16), vec3(1.14, 0.98, 0.82), clamp(qLum, 0.0, 1.0));
  return (rad / max(lum, 0.02)) * qLum * tint;
}

vec2 mapRoom(vec3 p) {
  float dFloor = p.y + 0.54;
  vec2 res = vec2(dFloor, 1.0);
  // Coral bounce wall on left
  float dWall = p.x + 1.05;
  if (dWall < res.x) res = vec2(dWall, 2.0);
  // Hero central ceramic sphere
  float dSph1 = length(p - vec3(0.06, -0.14, -0.05)) - 0.40;
  if (dSph1 < res.x) res = vec2(dSph1, 3.0);
  // Floating small blocker orb casting a rich soft penumbra across sphere & floor!
  float dSph2 = length(p - vec3(0.32, 0.36, 0.25)) - 0.16;
  if (dSph2 < res.x) res = vec2(dSph2, 4.0);
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.0025, 0.0);
  return normalize(vec3(
    mapRoom(p + e.xyy).x - mapRoom(p - e.xyy).x,
    mapRoom(p + e.yxy).x - mapRoom(p - e.yxy).x,
    mapRoom(p + e.yyx).x - mapRoom(p - e.yyx).x
  ));
}

float softShadowRay(vec3 p, vec3 lPos) {
  vec3 toL = lPos - p;
  float dL = length(toL);
  vec3 dir = toL / max(dL, 1e-4);
  float t = 0.03;
  for (int i = 0; i < 20; i++) {
    float h = mapRoom(p + dir * t).x;
    if (h < 0.003) return 0.0;
    t += max(h, 0.03);
    if (t > dL - 0.04) break;
  }
  return 1.0;
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  bool isNLMC = screenX >= split;
  float bands = clamp(floor(P_BANDS + 0.5), 2.0, 6.0);
  float lightR = clamp(P_PENUMBRA, 0.10, 1.4) * 0.42;
  float bStyle = clamp(P_BOUNCE_STYLE, 0.0, 1.4);

  vec3 ro = vec3(0.12, 0.24, 2.22);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.08, -1.48));
  vec3 col = mix(vec3(0.08, 0.11, 0.18), vec3(0.20, 0.28, 0.42), smoothstep(-0.4, 0.5, uv.y));

  float dist = 0.05;
  vec2 hit = vec2(10.0, 0.0);
  for (int i = 0; i < 64; i++) {
    vec2 h = mapRoom(ro + rd * dist);
    if (h.x < 0.002) { hit = vec2(dist, h.y); break; }
    dist += h.x;
    if (dist > 8.0) break;
  }

  if (hit.y > 0.5) {
    vec3 p = ro + rd * hit.x;
    vec3 n = calcNormal(p);
    vec3 alb = vec3(0.84, 0.82, 0.78);
    if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.92, 0.34, 0.24);
    else if (hit.y > 2.5 && hit.y < 3.5) alb = vec3(0.92, 0.86, 0.76);
    else if (hit.y > 3.5) alb = vec3(0.22, 0.68, 0.84);

    // Area light center orbiting gently overhead
    vec3 areaCenter = vec3(0.72 + 0.22 * cos(iTime * 0.5), 1.05, 0.62 + 0.22 * sin(iTime * 0.5));

    // Evaluate 8 stratified Monte Carlo light-transport samples across the area light & bounce hemisphere:
    // Left (Post-process toon): linear average FIRST, then apply phi(E[L]) -> harsh binary cut, flat indirect!
    // Right (Nonlinear MC): apply phi(L_i) INSIDE the estimator E[phi(L)] -> smooth painterly penumbra transitions
    // AND vivid quantized coral indirect bounce bands!
    vec3 linearAcc = vec3(0.0);
    vec3 nlAcc = vec3(0.0);
    float jitter = hash21(floor(fragCoord) * 0.5) * 6.2831853;

    for (int s = 0; s < 8; s++) {
      float fs = float(s);
      float ang = (fs / 8.0) * 6.2831853 + jitter * 0.25;
      float rr = sqrt((fs + 0.5) / 8.0) * lightR;
      vec3 lPt = areaCenter + vec3(cos(ang) * rr, 0.0, sin(ang) * rr);
      vec3 lDir = normalize(lPt - p);
      float vis = softShadowRay(p + n * 0.01, lPt);
      float ndl = max(dot(n, lDir), 0.0);

      // Colored indirect bounce contribution from coral left wall (x = -1.05)
      float wallFactor = max(dot(n, normalize(vec3(-1.05, 0.0, 0.0) - p)), 0.0) / (0.65 + (p.x + 1.05) * (p.x + 1.05));
      vec3 bounceS = vec3(0.96, 0.36, 0.24) * wallFactor * (0.45 + 0.55 * sin(ang) * 0.3 + 0.35) * bStyle;
      vec3 skyS = vec3(0.22, 0.34, 0.54) * (0.5 + 0.5 * n.y) * 0.36;

      vec3 sampleRad = alb * (vec3(1.28, 1.18, 1.02) * ndl * vis + bounceS + skyS);
      linearAcc += sampleRad;
      nlAcc += nonlinearOp(sampleRad, bands);
    }

    vec3 avgLinear = linearAcc * 0.125;
    vec3 avgNL = nlAcc * 0.125;

    if (!isNLMC) {
      // Left: Standard post-process toon ramp phi(E[L]) -- rigid stair-step contour cutting penumbra harshly
      col = nonlinearOp(avgLinear, bands);
    } else {
      // Right: Stylized Nonlinear Monte Carlo E[phi(L)] -- rich ink-wash penumbra + vibrant banded indirect bounce!
      col = avgNL;
    }
    if (hit.y < 1.5) col = mix(vec3(0.08, 0.11, 0.18), col, exp(-hit.x * 0.10));
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.96, 0.98, 1.0), sep);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combination ideas

- [Toon-banded bounce light, learned live](https://texelatlas.vercel.app/ideas/stylized-bounce-radiance-cache/)

## Sources

1. [primary] Xiaochun Tong, Toshiya Hachisuka (2025) Practical Stylized Nonlinear Monte Carlo Rendering. Proceedings of the Special Interest Group on Computer Graphics and Interactive Techniques Conference Conference Papers. https://doi.org/10.1145/3721238.3730686 (verified via crossref on 2026-11-29)
2. [implementation] LuisaGroup (2025) LuisaGroup/practical-stylized. https://github.com/LuisaGroup/practical-stylized (verified via github on 2026-11-29)
3. [primary] Toshiya Hachisuka Toshiya Hachisuka's page (paper link). cs.uwaterloo.ca. https://cs.uwaterloo.ca/~thachisu (verified via http on 2026-11-29)

## Cite this entry

Texel. "Stylized nonlinear Monte Carlo rendering." https://texelatlas.vercel.app/t/stylized-nonlinear-monte-carlo/ (accessed 2026-12-01).
