<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01" -->

---
title: Implementing Depth Pre-Pass Optimization for Three.JS
description: A depth pre-pass optimization for Three.JS scenes with expensive fragment shaders is implemented using WebGL&#x27;s built-in depth testing. By rendering all meshes...
canonical: https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Implementing Depth Pre-Pass Optimization for Three.JS | daily.dev
og:description: A depth pre-pass optimization for Three.JS scenes with expensive fragment shaders is implemented using WebGL&#x27;s built-in depth testing. By rendering all meshes...
og:url: https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01
og:image: https://api.daily.dev/og/posts/I6n09OZ01.png
og:image:alt: Implementing Depth Pre-Pass Optimization for Three.JS
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Implementing Depth Pre-Pass Optimization for Three.JS

**[Casey Primozic](https://daily.dev/sources/cprimozic)** · 5 min read · 0 upvotes · 0 comments

## Summary

A depth pre-pass optimization for Three.JS scenes with expensive fragment shaders is implemented using WebGL's built-in depth testing. By rendering all meshes first with a cheap material to populate the depth buffer, then switching the depth function from LEQUAL to EQUAL for the main render pass, fragments hidden behind closer geometry are automatically discarded without running the expensive shader. The implementation uses the postprocessing library's EffectComposer with custom RenderPass subclasses, requiring careful framebuffer management to share the depth buffer between passes. This approach yielded 30%+ performance improvement and outperformed a manual depth texture comparison method by an additional 10-15%.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://cprimozic.net/blog/threejs-depth-pre-pass-optimization/>

## Similar posts on daily.dev

- [Composite Rendering: The Brilliance Behind Inspiring WebGL Transitions](https://daily.dev/posts/composite-rendering-the-brilliance-behind-inspiring-webgl-transitions-mniabxfyu) · Codrops · 0 upvotes · 0 comments
- [Relighting Images with Depth Maps and Three.js](https://daily.dev/posts/relighting-images-with-depth-maps-and-three-js-jgklhsfbz) · Codrops · 1 upvotes · 0 comments

---

Tags: [#threejs](https://daily.dev/tags/threejs), [#webdev](https://daily.dev/tags/webdev)

[View this post on daily.dev](https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Implementing Depth Pre-Pass Optimization for Three.JS","url":"https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01"},"datePublished":"2026-03-31T12:29:45.783Z","dateModified":"2026-04-02T02:17:24.903Z","description":"A depth pre-pass optimization for Three.JS scenes with expensive fragment shaders is implemented using WebGL's built-in depth testing. By rendering all meshes...","image":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","thumbnailUrl":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","isAccessibleForFree":true,"articleSection":"Casey Primozic","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Casey Primozic","logo":"https://media.daily.dev/image/upload/s--LrHsyt2T--/f_auto/v1692632054/squad_placeholder_sfwkmj","url":"https://daily.dev/sources/cprimozic"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/implementing-depth-pre-pass-optimization-for-three-js-i6n09oz01","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"threejs,webdev","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Casey Primozic","item":"https://daily.dev/sources/cprimozic"},{"@type":"ListItem","position":3,"name":"Implementing Depth Pre-Pass Optimization for Three.JS"}]}
```

