# Multi Camera Color Grabpass

**URL:** <https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796>\
**Category:** Help & Support\
**Tags:** shaders\
**Created:** [April 26, 2023, 5:00pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796 "2023-04-26T17:00:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dabo](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@dabo](https://forum.playcanvas.com/u/dabo)\
**Post date:** [April 26, 2023, 5:00pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/1 "2023-04-26T17:00:22Z")

</div>

Hello, I’ve been trying to get a distortion effect working by using the [grab pass example](https://playcanvas.github.io/#/graphics/grab-pass).  
It seems to work on for anything rendered by the main scene camera, but I am unable to distort anything rendered by a second layer. If I add the distortion renderer layer to the second camera, it seems to discard the other element being rendered by that camera. In this example, the plane is on the main cam, and the sphere on the second.

 ![image](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/3/3/332c7c4db73fe64fff6bec5c9a1231f7753e9ab0.jpeg)

Here’s the example project:  
[https://playcanvas.com/project/1064680/overview/multicamcolorgrabpass](https://playcanvas.com/project/1064680/overview/multicamcolorgrabpass)

I’ve been shuffling camera& material properties, layers, and sort orders around while troubleshooting… so it may be a setup issue. For the shader, I’m really just overriding basePS and endPS with the grab pass related fragment code. I see mention of a `CameraComponent.requestSceneColorMap` on the web, but not sure if that applies to this situation.

Thanks for your time!

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [April 26, 2023, 5:13pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/2 "2023-04-26T17:13:28Z")

</div>

Is this what you are looking for? [https://playcanvas.com/project/1067089/overview/f-multicamcolorgrabpass](https://playcanvas.com/project/1067089/overview/f-multicamcolorgrabpass)

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [April 26, 2023, 5:16pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/3 "2023-04-26T17:16:10Z")

</div>

For reference, in the example there is this comment:

```javascript
// Depth layer is where the framebuffer is copied to a texture to be used in the following layers.
// Move the depth layer to take place after World and Skydome layers, to capture both of them.
const depthLayer = app.scene.layers.getLayerById(pc.LAYERID_DEPTH);
app.scene.layers.remove(depthLayer);
app.scene.layers.insertOpaque(depthLayer, 2);

```

So I’m assuming that when the depth layer is rendered, that’s when it captures the color buffer too?

---

<div class="post-metadata">

**Author:** ![dabo](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@dabo](https://forum.playcanvas.com/u/dabo)\
**Post date:** [April 26, 2023, 5:27pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/4 "2023-04-26T17:27:16Z")

</div>

> Is this what you are looking for? [PlayCanvas 3D HTML5 Game Engine](https://playcanvas.com/project/1067089/overview/f-multicamcolorgrabpass)

Hey, I’m having trouble spotting the distortion on the sphere. Is it being affected? My goal is to have both the plane and sphere distorted by the shader.

> So I’m assuming that when the depth layer is rendered, that’s when it captures the color buffer too?

That’s what it sounds like to me, but when I tried inserting the depthLayer code, it seemed to make the distortion render black. (I think I left it commented out in my example).

---

<div class="post-metadata">

**Author:** ![dabo](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@dabo](https://forum.playcanvas.com/u/dabo)\
**Post date:** [April 26, 2023, 5:59pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/5 "2023-04-26T17:59:24Z")

</div>

I did some more messing around with it, and am getting better results with the following:

- setting the depthLayer further down ( in my case7)
- setting the layers on the second cam to as shown  
 ![image](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/3/d/3ddad2a9577d0126112a2bfe4f967ea7c93a2e95.jpeg)
- keeping the distortion mesh on it’s own distortion layer.

 ![image](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/2/5/25f53ed51d0dc6d9c0fac140f5d7c438cee439e5.jpeg)

I’m not totally sure these are all the variables… but it’s promising!

---

<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:** [April 26, 2023, 7:13pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/6 "2023-04-26T19:13:42Z")

</div>

I’m not sure you need two cameras? One should be enough, to avoid the cost of double copying the framebuffer.

You render all normal meshes first (in World Layer). Then grab what is rendered by adding a Depth layer to be rendered after the World layer. And then you need another layer that renders after depth, which uses the grabbed texture and renders on top. If that mesh is transparent, you can use World layer for this one too, just set up the transparent part of it to render after the Depth layer.

---

<div class="post-metadata">

**Author:** ![dabo](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@dabo](https://forum.playcanvas.com/u/dabo)\
**Post date:** [April 26, 2023, 9:07pm UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/7 "2023-04-26T21:07:18Z")

</div>

> [@mvaligursky](#):
>
> You render all normal meshes first (in World Layer). Then grab what is rendered by adding a Depth layer to be rendered after the World layer. And then you need another layer that renders after depth, which uses the grabbed texture and renders on top. If that mesh is transparent, you can use World layer for this one too, just set up the transparent part of it to render after the Depth layer.

Ah interesting, thanks for the follow up! I _think_ the actual project is using the second camera to setup a totally independent sorting layer of meshes in that scene, but I will poke at it and see if it’s really needed.

It sounds like I can still apply this feedback though 👏 … I’ve been using an opaque material in a “distortion” layer, but maybe I can piggy back on an existing layer as long as it’s after depth (and its contents don’t need distorting?).

If I may ask: How does this manual layer setup you describe relate to the scripted approach above (_layers.insertOpaque())_ ? Are they doing the same thing, or am I confusing two different functions? I am still wrapping my head around this system… so feel free to tell me to rtfm 😛

---

<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:** [April 27, 2023, 7:43am UTC](https://forum.playcanvas.com/t/multi-camera-color-grabpass/30796/8 "2023-04-27T07:43:05Z")

</div>

in the engine code you use _layers.insertOpaque()_ while in the Editor code you can do that too, but typically use Settings → Layers to do this using UI.

 ![Screenshot 2023-04-27 at 08.42.03](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/7/a/7aca47fa9793e7b023a070e01429bcea4f84a920.png)

It’s also handy to install Spector JS (Chrome plugin for example), capture a frame and inspect what takes place … you can see when layers render, when the grab pass takes place and similar.
