# Depth texture shows pure red when using CameraFrame / RenderPassDepthGrab

**URL:** <https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086>\
**Category:** Help & Support\
**Tags:** textures\
**Created:** [October 23, 2025, 8:49am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086 "2025-10-23T08:49:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ijon\_h](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ijon_h/32/35346_2.png) [@Ijon\_h](https://forum.playcanvas.com/u/Ijon_h)\
**Post date:** [October 23, 2025, 8:49am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/1 "2025-10-23T08:49:27Z")

</div>

Following [this older discussion](https://forum.playcanvas.com/t/how-to-guarantee-access-to-the-depth-texture/40444/6), I’ve been trying to access the scene depth texture (will be used later).

I tested both approaches:

- `RenderPassDepthGrab`
- `CameraFrame.rendering.sceneDepthMap = true`

However, in both cases, the resulting texture appears pure red when drawn.

 ![Screenshot 2025-10-23 at 4.47.37 PM](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/b/1/b1b9ea8b5751feaca97aac0aa27666574e2f8264.png)

Here’s the snippet I used:

```javascript
// init()
this.entity.camera.requestSceneDepthMap(true);

// update()
const renderPassDepthGrab = this.entity.camera.camera.renderPassDepthGrab;
if (!renderPassDepthGrab) return;

const depthRenderTarget = renderPassDepthGrab.depthRenderTarget;
if (!depthRenderTarget) return;

const depthTexture = this.app.graphicsDevice.isWebGL2
    ? depthRenderTarget.depthBuffer
    : depthRenderTarget.colorBuffer; // Why colorBuffer here?

console.log('depth texture:', depthTexture);
this.app.drawTexture(0.7, -0.7, 0.5, 0.5, depthTexture);

```

Is this expected, or is there a correct way to sample it?

Any guidance or confirmation from others who’ve tried this recently would be appreciated!  
Project Link: [https://playcanvas.com/editor/scene/2346401](https://playcanvas.com/editor/scene/2346401)

---

<div class="post-metadata">

**Author:** ![Wagner](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/wagner/32/36162_2.png) [@Wagner](https://forum.playcanvas.com/u/Wagner)\
**Post date:** [October 24, 2025, 8:49am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/2 "2025-10-24T08:49:30Z")

</div>

A depth texture is quite a specific type of data. It’s important to understand that depth textures come in different formats, and not all of them can be displayed directly on the screen. To visualize such a texture in PlayCanvas, you should use the dedicated function provided in the following link:

> <https://github.com/playcanvas/engine/blob/f47fcb64e3218d767ced084d55cce36a1fc8db6e/src/framework/app-base.js#L1806>

```javascript
this.app.drawDepthTexture(0.7, -0.7, 0.5, 0.5)

```

---

<div class="post-metadata">

**Author:** ![Ijon\_h](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ijon_h/32/35346_2.png) [@Ijon\_h](https://forum.playcanvas.com/u/Ijon_h)\
**Post date:** [October 27, 2025, 2:30am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/3 "2025-10-27T02:30:07Z")

</div>

Hi @Wagner , thanks for the reply. For my use-case I’m not trying to display the depth (it’s only for debugging). I need it for compute shader. Concretely, I’m looking for a reliable way to obtain a depth resource that I can bind as `texture_2d<f32>`, ideally linear depth in R32F.

---

<div class="post-metadata">

**Author:** ![Wagner](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/wagner/32/36162_2.png) [@Wagner](https://forum.playcanvas.com/u/Wagner)\
**Post date:** [October 27, 2025, 4:22am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/4 "2025-10-27T04:22:31Z")

</div>

Very few mobile devices support r32f texture, you are better off using rgba8 texture into which you encode float.

GLSL:

```javascript

    precision highp float;

    #include "floatAsUintPS"

    uniform highp sampler2D uSceneDepthMap;

    #ifdef WEBGPU

        #ifdef SCENE_DEPTHMAP_FLOAT
            #define getDepth(xy, offset, level) texelFetch(uSceneDepthMap, xy + offset, level).r
        #else
            #define getDepth(xy, offset, level) uint2float(texelFetch(uSceneDepthMap, xy + offset, level))
        #endif

    #else

        #ifdef SCENE_DEPTHMAP_FLOAT
            #define getDepth(xy, offset, level) texelFetchOffset(uSceneDepthMap, xy, level, offset).r
        #else
            #define getDepth(xy, offset, level) uint2float(texelFetchOffset(uSceneDepthMap, xy, level, offset))
        #endif
    
    #endif

```

```javascript
    precision highp float;

    uniform highp sampler2D uDepthMip;

    void main() {

        ivec2 xy = ivec2(gl_FragCoord.xy);
        float depth = getDepth(uDepthMip, xy, 0);

        #ifdef WRITE_DEPTH
            gl_FragDepth = depth ;
        #elifdef WRITE_FLOAT
            gl_FragColor = vec4(vec3(depth), 1.0);
        #else
            gl_FragColor = float2uint(depth);
        #endif
    }

```

---

<div class="post-metadata">

**Author:** ![sniffles](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/sniffles/32/24987_2.png) [@sniffles](https://forum.playcanvas.com/u/sniffles)\
**Post date:** [December 13, 2025, 3:40pm UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/5 "2025-12-13T15:40:34Z")

</div>

I’m also working through grabbing the scene depth texture. Did you figure this out?

I feel like the depthtexture you grabbed was actually valid, just not rendering on-screen properly(?)

I’ve just been doing a custom RT render pipeline to get access to the scene depth texture, and then doing a final render pass RT → render to scene, but its a huge performance hit. Personally I’m hoping I can bypass the step of rendering the RT to the scene by grabbing the depth directly from scene somehow

---

<div class="post-metadata">

**Author:** ![sniffles](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/sniffles/32/24987_2.png) [@sniffles](https://forum.playcanvas.com/u/sniffles)\
**Post date:** [December 24, 2025, 3:49pm UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/6 "2025-12-24T15:49:05Z")

</div>

Ended up figuring it out for the most part. Doing a custom / extended render pass using scene depth by using the linked methods (checking for any warnings) for grabbing depth worked great. For some reason RenderPassGrabDepth or whatever it’s called worked great but I couldn’t reference it in the engine, so I just copied the script and hooked it in my render passes.

Turns out grabbing depth was a bit more expensive than what I would have liked anyway (20ms → 28ms frametime on our lower end target) so I moved on from grabbing depth for now.

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [December 24, 2025, 3:51pm UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/7 "2025-12-24T15:51:56Z")

</div>

that’s strange, I have not see cost like that before (on desktop anyways).

---

<div class="post-metadata">

**Author:** ![sniffles](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/sniffles/32/24987_2.png) [@sniffles](https://forum.playcanvas.com/u/sniffles)\
**Post date:** [January 5, 2026, 6:58am UTC](https://forum.playcanvas.com/t/depth-texture-shows-pure-red-when-using-cameraframe-renderpassdepthgrab/41086/8 "2026-01-05T06:58:58Z")

</div>

This was on a 2014 iPad Air, performance seemed relatively negligible on my desktop as well so I’m sure it’s fine depending on what you want. Maybe bandwidth related?

Otherwise open to suggestions for a more accurate low end device for the current mobile market 🙂
