# \[SOLVED\] Need help with alpha channels

**URL:** <https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158>\
**Category:** Help & Support\
**Tags:** learning, scripting\
**Created:** [September 26, 2023, 7:59pm UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158 "2023-09-26T19:59:44Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 26, 2023, 7:59pm UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/1 "2023-09-26T19:59:44Z")

</div>

Hey guys, so i’m running an engine only project and i’m probably missing something regarding alphas

STACK:  
a css3 renderer  
and theres two walls  
normal one  
and one with alpha  
inside the alpha, there’s text inside that is invisible also

```javascript
diffuse = new pc.Color().fromString('#755a5a');
blendType = pc.BLEND_NORMAL;
opacity = 0.5;

```

what am i missing?

…

alpha one makes css3 rendered to be visible, also makes text to be invisible

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [September 27, 2023, 6:16am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/2 "2023-09-27T06:16:06Z")

</div>

Hi @Newbie_Coder,

To better understand the issue, if you disable the CSS3D string does your alpha blended material render?

CSS3D isn’t really officially supported in PlayCanvas.

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 6:48am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/3 "2023-09-27T06:48:48Z")

</div>

Yes, it does render.  
I’m experimenting with different blend types and seems like “Premultiplied Alpha” solves the issue for 3D renderer, but not the text

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 6:55am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/4 "2023-09-27T06:55:46Z")

</div>

Got the text showing up also, under alphas, any ideas how to set this sequence in engine-only?  
 ![Capture](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/7/1/718f836261ab95bb73dfc83d8854cf788dadeaac.png)

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [September 27, 2023, 7:00am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/5 "2023-09-27T07:00:01Z")

</div>

For that you need to work with the main layer composition under the scene object:

```javascript
this.app.scene.layers;

```

The relevant methods to remove and insert a layer at a specified index are here: [LayerComposition | PlayCanvas API Reference](https://developer.playcanvas.com/en/api/pc.LayerComposition.html)

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 7:49am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/6 "2023-09-27T07:49:16Z")

</div>

```javascript
      // get the world layer index
        const SkyboxLayer = pc.app.scene.layers.getLayerByName("Skybox");
        const UiLayer = pc.app.scene.layers.getLayerByName("UI");
        const idx = pc.app.scene.layers.getOpaqueIndex(SkyboxLayer);

        pc.app.scene.layers.insert(UiLayer, idx + 1);

```

Based on public engine examples, nothing happens 🤔 no errors  
 ![Capture](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/9/4/94741e29a6b55d33dd5d429fb12839ec75f6557e.png)  
the IDs getting messed up

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [September 27, 2023, 7:49am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/7 "2023-09-27T07:49:58Z")

</div>

@mvaligursky when working with engine examples, what’s the proposed way of setting the scene layers render order?

---

<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:** [September 27, 2023, 8:36am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/8 "2023-09-27T08:36:18Z")

</div>

Multiple examples do this, I think that’s the currently best way:

```javascript
const excludedLayer = new pc.Layer({ name: "Excluded" });
app.scene.layers.insert(excludedLayer, app.scene.layers.getTransparentIndex(worldLayer) + 1);

```

There are few different functions to add a layer:

> **[LayerComposition | PlayCanvas API Reference](https://api.playcanvas.com/classes/Engine.LayerComposition.html)**
>
> Combined API reference manual for PlayCanvas

---

<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:** [September 27, 2023, 8:39am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/9 "2023-09-27T08:39:16Z")

</div>

> [@Newbie\_Coder](#):
>
> the IDs getting messed up

Each layer has a unique ID, and each layer can be added in the list twice, one time to render opaque objects, one time to render transparent objects.

Have a look at subLayerList array on the same objects as layerList, True means transparent objects are rendered, and false means opaque.

I agree this is not ideal set up to understand, and there is also another array with enabled flags called subLayerEnabled. I was looking at replacing this by a single array of objects, but did get to that yet.

---

<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:** [September 27, 2023, 8:41am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/10 "2023-09-27T08:41:29Z")

</div>

If you run this somewhere at startup:

```javascript
pc.Tracing.set(pc.TRACEID_RENDER_ACTION, true);

```

it will log a list of layers that get rendered for each camera … along with transparent / opaque flag, that should be easier to read.

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 8:42am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/11 "2023-09-27T08:42:15Z")

</div>

But how do I actually change the existing (default) order? I’m not trying to add new layer, just want to change the order  
This is default:  
 ![Capture](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/d/a/daed7520033bfb3b1f9083978c074417ee41bde2.png)  
And I need UI to come right after Skybox

---

<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:** [September 27, 2023, 8:44am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/12 "2023-09-27T08:44:07Z")

</div>

remove a layer, and then add it back to a different place using the API that is linked above.

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 9:04am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/13 "2023-09-27T09:04:27Z")

</div>

Apparently this case won’t work:

```javascript

const uilayer = pc.app.scene.layers.getLayerByName("UI");
const cloned = Object.assign({}, uilayer);

pc.app.scene.layers.remove(uilayer);

const SkyboxLayer = pc.app.scene.layers.getLayerByName("Skybox");
const idx = pc.app.scene.layers.getOpaqueIndex(SkyboxLayer);

pc.app.scene.layers.insert(cloned, idx + 1);

Uncaught TypeError: e.addMeshInstances is not a function

```

Even if I managed to clone or recreate original “UI” I’d still need to re-add layers for each entity that was using “UI” or it would automatically re-apply?

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 9:10am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/14 "2023-09-27T09:10:42Z")

</div>

Okay so this is final:

```javascript
const uilayer = pc.app.scene.layers.getLayerByName("UI");
pc.app.scene.layers.remove(uilayer);

const layer = new pc.Layer({
	name: "UI",
});

const SkyboxLayer = pc.app.scene.layers.getLayerByName("Skybox");
const idx = pc.app.scene.layers.getOpaqueIndex(SkyboxLayer);

pc.app.scene.layers.insertTransparent(layer, idx + 1);

```

![Capture](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/9/6/963b974217b26c68895ad47da25c596b87a1881e.png)  
This is also correct

But the text does not appear, probably the new “UI” is not the same as old original “UI” in terms of entities.

---

<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:** [September 27, 2023, 9:19am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/15 "2023-09-27T09:19:08Z")

</div>

Don’t clone a layer. Remove the layer, and add the same layer to a new spot, not the one you “clone”.

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 9:20am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/16 "2023-09-27T09:20:15Z")

</div>

Did that already, even if its identical to how its set in editor, text doesnt re-appear after running that piece of code

> [@\[SOLVED\] Need help with alpha channels](https://forum.playcanvas.com/t/need-help-with-alpha-channels/33158/14):
>
> Okay so this is final: const uilayer = pc.app.scene.layers.getLayerByName("UI"); pc.app.scene.layers.remove(uilayer); const layer = new pc.Layer({ name: "UI", }); const SkyboxLayer = pc.app.scene.layers.getLayerByName("Skybox"); const idx = pc.app.scene.layers.getOpaqueIndex(SkyboxLayer); pc.app.scene.layers.insertTransparent(layer, idx + 1); [Capture] This is also correct But the text does not appear, probably the new “UI” is not the same as old original “UI” in terms of entities.

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 10:31am UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/17 "2023-09-27T10:31:36Z")

</div>

Yep, as I thought, the new “UI” layer is not the same as original “UI” layer in the “eyes” of entity.  
Once layer is removed and added to other index

pc.app.root.findByName(“Text”).element.layers still outputs the original array of index ID

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [September 27, 2023, 12:27pm UTC](https://forum.playcanvas.com/t/solved-need-help-with-alpha-channels/33158/18 "2023-09-27T12:27:02Z")

</div>

Okay…

had to look at source code to make it work, thanks guys.

```javascript
const layer = new pc.Layer({
	name: "UI",
    id: pc.LAYERID_UI,
	transparentSortMode: pc.SORTMODE_MANUAL,
	passThrough: false
});

```
