Hi, anyone have any clue how I could possibly add real time ambient occlusion? …and if one exists somewhere would it work on mobile?
Cheers
Hi, anyone have any clue how I could possibly add real time ambient occlusion? …and if one exists somewhere would it work on mobile?
Cheers
Hi @Grimmy,
In the PlayCanvas engine repo you can find a very good SSAO implementation (copy/paste your script in your project, parse it and the ssao effect to your active camera):
Here you can see it run live, among other effects: PlayCanvas Examples
But I wouldn’t use such a heavy post effect on mobile. Usually I would bake ambient occlusion offline and use it as a texture on the material on the Ambient channel.
Great. Is that a javascript or a shader? I tried dragging on to the camera as a regular script component but its doesnt seem to work.
It’s JavaScript, it should work if you parse it first. Try adding a script component and find the ssao script and add it.

I know this is an old thread but I found a different ssao here which to me looks better and has far more control. How would I implement that example in the editor?
It looks like it use something here: /static/scripts/posteffects/posteffect-ssao.js but where can I get that script?
Cheers
You cannot use it in the Editor yet, it’s coming with the engine 2. We’re aiming to add support for engine 2 in the editor in about a month, it’s in the works.
In saying that, if you need it urgently, you could find the implementation here:
which also uses these for blurs:
and port it to the current SSAO script:
but that’d need some non-trivial changes.
Is the ‘official’ version of the new ssao shader for engine v2 anywhere I can get it yet?
(Asset store version was last updated 4/18/2023)
It’s this script you need to add on your camera:
Great. Thanks! ![]()
But what is a .mjs script and how do I make that compile in PLaycanvas …and then attach it to the camera?
It doesn’t seem to appear in the dropdown where all the other.js scripts appear. Renaming doesn’t seem to affect it either.
??
Cheers
It works as other scripts. Just click on Parse button on it to parse it.
Thanks. All done but I get the following error:
Writing to the “pc” global is not supported in projects containing ESM Scripts.
To fix this, remove the assignment and import directly from ‘playcanvas’ wherever you need to reference “pc”.
I realize that it tells me the ‘solution’ as part of the error, but it makes no sense to me. Could you clarify? Thanks
This is likely because one of your scripts is attempting to store something on the global pc object ie. ‘pc.something = true’. This is not supported in ESM scripts (scripts ending in .mjs). You’ll need to hunt that down in your code and refactor it.
I tried it again in another project (with no other other scripts) and I just get this error:
A uSceneColorMap texture is used by the shader but a scene color texture is not available. Use CameraComponent.requestSceneColorMap / enable Color Grabpass on the Camera Component to enable it. Rendering [Pass:RenderPassCompose RT:WebglFramebuffer | Camera: Player_Camera, Layer: World(TRANSP) | Node: passengerside_window2, Material: Glass]
It seems very fragile
Tick the box on the camera for Color Grabpass
The error refers to a missing colour grabpass on the Camera Component
Use CameraComponent.requestSceneColorMap / enable Color Grabpass on the Camera Component
Thanks. Although that removed one error, the addition of this script also seemed to affect my other scripts which previously had no issues. (notably one of my external script urls started to get wierd random errors that had never happened before). Even after disabling this script the error didn’t go away until I fully deleted this new camera script from the project.
In the end I have decided to use the old ssao effect as this one seems way too much hassle to implement.
@Mark_Lundin Should you be able to mix .mjs and .js scripting systems into the same project?
yes mixing .js and .mjs is supported and should work
could you post the errors you’re getting please