# "Cavity" shader effect like Blender 2.8 viewport for Babylon.js?

**URL:** <https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789>\
**Category:** Questions\
**Tags:** material, shader, nme\
**Created:** [June 18, 2020, 12:00am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789 "2020-06-18T00:00:12Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 9, 2020, 12:49pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/21 "2020-07-09T12:49:32Z")

</div>

Adding @RaananW for the XR part

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 20, 2020, 11:50pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/22 "2020-07-20T23:50:05Z")

</div>

The post process is in (ScreenSpaceCurvaturePostProcess) and will be available in the next nightly in the PG with:

[https://playground.babylonjs.com/#YF8D42#4](https://playground.babylonjs.com/#YF8D42#4)

The post process has both ridge and valley properties:

> <https://github.com/BabylonJS/Babylon.js/pull/8562>

Do not hesitate to change adapt enhance. It is a direct copy of @Evgeni_Popov code 🙂

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [July 21, 2020, 12:05am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/23 "2020-07-21T00:05:30Z")

</div>

Thanks everyone. I’m kind of amazed my little suggestion generated so much activity in such a short space of time. Awesome outcome!

---

<div class="post-metadata">

**Author:** ![Browork](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/browork/32/13350_2.png) [@Browork](https://forum.babylonjs.com/u/Browork)\
**Post date:** [July 21, 2020, 4:22pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/25 "2020-07-21T16:22:19Z")

</div>

When will it be possible to test in playground? 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [July 21, 2020, 4:31pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/26 "2020-07-21T16:31:36Z")

</div>

It’s already in:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/8/854a2fc133368e8ada3c1e0d15fd87de88c47b3a.jpeg)

Clear the cache of your browser if it does not work for you.

---

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [May 13, 2022, 7:45am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/27 "2022-05-13T07:45:25Z")

</div>

Hi there.

For my scene I want both SSAO and SSC.

It works perfectly by employing the BJS’ original SSAO implementation. Please see see [this PG](https://playground.babylonjs.com/#N96NXC#80).

The case is that, when I implement the same strategy with SSAO2 (in orther to gather a best performance and aesthetic, and byt the way a much less aliases) SSC is not shown, as you can check visiting [this other PG](https://playground.babylonjs.com/#N96NXC#81).

Any help on it?

Thanks in advance for your time!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 13, 2022, 9:30am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/28 "2022-05-13T09:30:29Z")

</div>

The SSAO2 implementation is using the pre-pass renderer by default, and it seems it is not compatible with SSC which is using the geometry buffer renderer to perform its computations.

I don’t know if it’s expected, maybe @CraigFeldspar will know.

A workaround is to force using the geometry buffer renderer with SSAO2 (5ith parameter of the SSAO2 constructor):

> **[Babylon.js Playground](https://playground.babylonjs.com/#N96NXC%2384)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [May 13, 2022, 12:53pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/29 "2022-05-13T12:53:14Z")

</div>

Thanks @Evgeni_Popov.

I see an even higher performance hit with this approach, but maybe I can live with it as my app doesn´t need a specially big FPS number.

Certainly, SSAO + SSC are the way to go in technical-look developments.

---

<div class="post-metadata">

**Author:** ![CraigFeldspar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/craigfeldspar/32/45631_2.png) [@CraigFeldspar](https://forum.babylonjs.com/u/CraigFeldspar)\
**Post date:** [May 14, 2022, 4:19pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/30 "2022-05-14T16:19:27Z")

</div>

Maybe SSC should use prepass also for the 2 to be compatible, but for now @Evgeni_Popov’s workaround is definitely the way to go

---

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [May 24, 2022, 6:07pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/31 "2022-05-24T18:07:59Z")

</div>

Hi there @CraigFeldspar and @Evgeni_Popov:

By the way, any advice about trying to make this SSC buffer renderer work with an animated camera imported from a GLB file. It throws the error: “TypeError: can’t access property “createDrawContext”, e is undefined”

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 24, 2022, 6:45pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/32 "2022-05-24T18:45:02Z")

</div>

Can you create a repro in the playground ? it sounds hard to troubleshoot without it.

---

<div class="post-metadata">

**Author:** ![paleRider](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/palerider/32/7774_2.png) [@paleRider](https://forum.babylonjs.com/u/paleRider)\
**Post date:** [May 25, 2022, 12:41pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/33 "2022-05-25T12:41:57Z")

</div>

Hi there, @sebavan.

It must be other the cause of crashing my scene, as I’m prepared a fast and dirt PG and all seem to work OK there.

I’ll let you know as soon as I can dig a little more on it.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [May 7, 2023, 2:23pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/35 "2023-05-07T14:23:58Z")

</div>

Hi all - just trying this out in a pg, but it seems to crash everything. Any other way to achieve it or special settings?

I just added this one line:  
var cavity = new BABYLON.ScreenSpaceCurvaturePostProcess(“cavity”, scene, 1, camera);

And the PG will crash.  
Here’s a PG without the line: [https://playground.babylonjs.com/#WF3VKZ#288](https://playground.babylonjs.com/#WF3VKZ#288)

And here’s the PG with the line:[https://playground.babylonjs.com/#WF3VKZ#321](https://playground.babylonjs.com/#WF3VKZ#321) (with enough reloading it eventually does something, but mostly crashes)

Weird - actually it seems to work sometimes, but then slows down chrome until it crashes - even if you close the browser window.

That said, it works a little weird. The effect is very pronounced - versus light bevel edges.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 7, 2023, 11:41pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/36 "2023-05-07T23:41:16Z")

</div>

It works all the time for me, I tried reloading the page + clicking on the “Play” button several times and it always worked.

What I see:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/d/ed499186c48b477a42f9ace633c15b5bab78e4b3.jpeg)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 9, 2023, 5:38pm UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/37 "2023-05-09T17:38:23Z")

</div>

same for me

---

<div class="post-metadata">

**Author:** ![educa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/educa/32/7730_2.png) [@educa](https://forum.babylonjs.com/u/educa)\
**Post date:** [April 13, 2025, 10:02am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/38 "2025-04-13T10:02:45Z")

</div>

> [@JCPalmer](#):
>
> rom above, directed down. Parts of a mesh that are underneath are darker when turned on, while parts on top are lighter.
> 
> I do not think this can be done by adding a directional light, since it adds its light equally to all faces, I think. Therefore, cannot be implemented in STD Materials.
> 
> An environment texture would work for PBR materials though. As you are using Blender, you can make a custom environment textures with it. Generate a `cavity.hdr` file from a scene, then use the new tool to turn it into `c`

Did this make it as a postprocess in the engine ?

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 13, 2025, 10:18am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/39 "2025-04-13T10:18:12Z")

</div>

Yes it’s here [ScreenSpaceCurvaturePostProcess](https://doc.babylonjs.com/typedoc/classes/BABYLON.ScreenSpaceCurvaturePostProcess)

---

<div class="post-metadata">

**Author:** ![educa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/educa/32/7730_2.png) [@educa](https://forum.babylonjs.com/u/educa)\
**Post date:** [April 13, 2025, 10:30am UTC](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789/40 "2025-04-13T10:30:05Z")

</div>

Ow wow nice.

I combined it with the Imphenzia Pixpal material and now it does perfectly recreate the intended visuals bij Imphenzia. Never thought this would be so easy to do (well, after some people here did a huge work on making the effect available of course 😉 )

```
var cavity= new BABYLON.ScreenSpaceCurvaturePostProcess("Cavity", scene, 1, scene.activeCamera);
cavity.ridge=0.5;
cavity.valley=0.5;

```

[Previous page](https://forum.babylonjs.com/t/cavity-shader-effect-like-blender-2-8-viewport-for-babylon-js/11789.md?page=1)
