✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: January 1, 2026
  • 8 min read

Improving Diffuse Shading with Hermite‑Based Quadratic Remapping


Rethinking Diffuse Shading: From Lambertian Limits to Hermite‑Optimized Cloud Rendering

The diffuse shading model can be improved by remapping the classic Lambertian dot‑product and applying a Hermite‑based quadratic formula, which yields smoother lighting and eliminates harsh black‑spot artifacts—especially useful for realistic cloud rendering.

Why the Classic Lambertian Model Falls Short

In traditional graphics pipelines, the Lambertian diffuse term is expressed as max(0, L·N), where L is the light direction and N the surface normal. This simple formulation guarantees energy conservation and works well for many materials, but it also creates a stark problem: any surface facing away from the light source receives zero illumination, resulting in completely black regions. For tech enthusiasts, graphics programmers, and 3D artists experimenting with quick demos or procedural clouds, those black patches obscure geometry and break immersion.

While production‑grade engines mitigate the issue with multiple lights, ambient occlusion, or texture‑based tricks, developers often need a one‑liner that works out‑of‑the‑box. Below we explore a mathematically elegant alternative that retains the simplicity of a single expression while delivering far more pleasing visual results.

Traditional Lambertian Diffuse Shading

  • Based on the cosine law: illumination ∝ cos θ = L·N.
  • Uses max(0, L·N) to clamp negative values.
  • Physically plausible for perfectly matte surfaces.
  • Produces hard black edges when the angle exceeds 90°.

The model’s simplicity makes it a staple in real‑time rendering, but its binary nature (light or no light) is rarely ideal for artistic control. When rendering volumetric phenomena like clouds, the abrupt transition creates visible seams that betray the underlying geometry.

Remapping the Dot Product: A Simple Linear Fix

The first step toward a smoother diffuse term is to linearly remap the dot product from the [-1, 1] interval to [0, 1]:

float remapped = 0.5 + 0.5 * dot(L, N); // (1 + L·N) / 2

This eliminates the hard black region by giving every surface a minimum illumination of 0.5. The result is brighter overall, which may be acceptable for stylized scenes but often looks unrealistic for physically‑based rendering.

Squaring the Remapped Term for a Softer Fall‑off

To temper the excessive brightness, we square the linear remap:

float smoother = pow(0.5 + 0.5 * dot(L, N), 2.0); // ((1 + L·N)/2)^2

The quadratic curve gently eases the transition from full illumination to the minimum value, preserving detail in shadowed areas while keeping the overall lighting plausible. This simple one‑liner is surprisingly effective for cloud rendering, where subtle gradients are essential.

Why the Squared Formula Is Actually Optimal: Hermite Interpolation

The squared variant isn’t just a hack; it’s the exact solution to a Hermite interpolation problem. Hermite interpolation asks for a polynomial that matches both function values and first derivatives at specific points. For the Lambertian function f(x)=max(0,x), we require:

  • Value at x = -1 → 0
  • Value at x = 1 → 1
  • Derivative at x = -1 → 0
  • Derivative at x = 1 → 1

Solving this system yields a quadratic polynomial:

h(x) = ((1 + x) / 2)^2

In other words, the squared remap is the unique quadratic that satisfies the Hermite constraints, making it mathematically optimal for a smooth approximation of the Lambertian term while preserving the original endpoints and slopes.

Real‑World Impact: Rendering Volumetric Clouds

Clouds are essentially collections of semi‑transparent particles that scatter light from all directions. Using the classic Lambertian term often leaves the underside of clouds unnaturally dark, especially when a single directional light (e.g., the sun) dominates the scene. By swapping to the Hermite‑derived quadratic diffuse term, artists gain:

  • Soft, natural gradients across cloud volumes.
  • Elimination of hard black silhouettes on the cloud base.
  • Better integration with environment lighting without extra passes.

Below is an illustration of a cloud rendered with the Hermite‑optimized diffuse model versus the classic Lambertian approach. Notice the smoother transition and the absence of harsh shadows.

Comparison of Lambertian vs Hermite diffuse shading on clouds

Further Reading

For a deeper dive into the original discussion and additional visual examples, see the original article that first presented this shading trick.

Boost Your Shading Workflow with UBOS AI Tools

If you’re looking to prototype this technique quickly, the UBOS homepage offers a cloud‑based development environment where you can spin up a WebGL sandbox in seconds. The UBOS platform overview explains how its modular architecture lets you integrate custom shaders without worrying about build pipelines.

Want to automate the generation of shader code or test variations across multiple lighting setups? The Workflow automation studio can orchestrate batch renders, while the Web app editor on UBOS provides live preview of your GLSL changes.

For teams focused on AI‑enhanced graphics, explore the AI marketing agents that can automatically generate documentation and tutorials for your shading pipelines. Startups can benefit from the UBOS for startups program, while SMBs may find the UBOS solutions for SMBs especially cost‑effective.

Enterprises looking for a robust, scalable solution can evaluate the Enterprise AI platform by UBOS. To see real‑world implementations, browse the UBOS portfolio examples and discover how other developers have leveraged AI to accelerate graphics pipelines.

Need a head start? The UBOS templates for quick start include a “AI Article Copywriter” template that can auto‑generate technical write‑ups for your shader libraries, or the “AI Video Generator” to create demo reels of your new cloud rendering technique.

For a more creative spin, try the “AI Image Generator” to produce concept art of atmospheric scenes, or the “AI SEO Analyzer” to ensure your documentation ranks as well as this article.

Explore More UBOS Templates for Graphics & AI

Conclusion

By replacing the binary Lambertian term with the Hermite‑derived quadratic ((1 + L·N)/2)^2, developers gain a single‑line, physically‑inspired diffuse model that eliminates harsh shadows, improves cloud rendering, and remains trivial to implement. This approach exemplifies how a modest mathematical insight can unlock noticeable visual gains without sacrificing performance.

Ready to experiment? Jump into the UBOS pricing plans to get instant access to a cloud‑based IDE, then try the formula in the Web app editor on UBOS. Share your results on social media, tag us, and let the community see how a simple quadratic can transform your skies.

Start building brighter, smoother scenes today – the clouds are waiting!


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.