# Enable KHR settings (transmission) in runtime

**URL:** <https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686>\
**Category:** Questions\
**Tags:** material\
**Created:** [August 30, 2023, 8:15am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686 "2023-08-30T08:15:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Forsaken](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/forsaken/32/21296_2.png) [@Forsaken](https://forum.babylonjs.com/u/Forsaken)\
**Post date:** [August 30, 2023, 8:15am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/1 "2023-08-30T08:15:00Z")

</div>

Hello everyone,

I’m trying to enable the extension KHR\_materials\_transmission for a material in runtime.  
I have a model that has among other things KHR\_materials\_transmission enabled, but I can’t manage to enable this manually:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/e/7eb40dd71cd936c84eb240b6062d41789edd6a84.png)

I have created this simple playground with 2 example models:

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

You can un/comment the model URL to compare. Is it possible at all to enable this manually or is it (currently) only possible by setting it in the model file itself? Where within babylon is it generally stored which extensions are enabled/applied to materials in the first place?

---

<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:** [August 30, 2023, 9:22am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/2 "2023-08-30T09:22:19Z")

</div>

You can’t manually do what the transmission extension does because it’s currently not possible to access the transmission helper class from a user code, see these posts for context:

- [Refraction of other objects - #8 by Evgeni\_Popov](https://forum.babylonjs.com/t/refraction-of-other-objects/42896/8)
- [Transmission Helper Optimisation - #3 by Evgeni\_Popov](https://forum.babylonjs.com/t/transmission-helper-optimisation/21037/3)

There is a bounty for obtaining a texture of the opaque objects in the scene:

> <https://github.com/BitReelCo/BJS-PR-Bounty-Pool/issues/4>
>
> You will have to create a helper function to copy the current framebuffer into a… texture (this will have to work in WebGPU too!).
> 
> In addition, a new class simplifying the copying of opaque objects should be designed. It will have to register on the \`RenderingGroup.onBeforeTransparentRendering\` observable to copy the current framebuffer into a texture that will be available to the user. 
> 
> This class will probably need to be configured with some image processing post processes, as requested by the user (details will be discussed at implementation time). 
> 
> To facilitate the use of this texture as a refraction texture for standard / PBR materials, you will add a global scene.refractionTexture property (in the same way we have scene.environmentTexture for the case of reflection) which will be used by default by the materials if no specific refraction texture has been defined at the material level.
> 
> A visualization test and according doc should be added to the framework.

Once this texture has been obtained, simply use it as a refraction texture to simulate transmission.

Someone tried to make a PR out of it, but it didn’t work out:

> <https://github.com/BabylonJS/Babylon.js/pull/13492>
>
> https://github.com/BitReelCo/BJS-PR-Bounty-Pool/issues/4

---

<div class="post-metadata">

**Author:** ![Forsaken](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/forsaken/32/21296_2.png) [@Forsaken](https://forum.babylonjs.com/u/Forsaken)\
**Post date:** [August 30, 2023, 9:47am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/3 "2023-08-30T09:47:13Z")

</div>

I see, so from what I can gather it’s currently not possible to enable/add the extension after loading the model, mostly due to the current flow of the babylon.js engine? Like we can’t add the material to whatever list keeps track of where this extension logic should be applied?

And we can’t replicate the behavior either because we currently have no (good) way to get the texture the extension generates (a RenderTargetTexture of all opaque objects in the screen). I suppose we can’t replicate whatever the extension does internally because there’s no good “hook” or “observer” point to attach to where we could replicate and insert this?

---

<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:** [August 30, 2023, 10:40am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/4 "2023-08-30T10:40:27Z")

</div>

> [@Forsaken](#):
>
> I see, so from what I can gather it’s currently not possible to enable/add the extension after loading the model

No, the extension is parsed at loading time, and the transmission helper is created only if this extension exists.

Maybe you could “inject” this extension yourself during load, if we have a way to do it… Let’s ask @bghgary if it’s possible (be patient, he will be back next week).

> [@Forsaken](#):
>
> And we can’t replicate the behavior either because we currently have no (good) way to get the texture the extension generates

You can’t replicate it because the `TransmissionHelper` class (which is used to implement the feature) is not available to user code. Actually, you can replicate it if you copy/paste the class in your own project :). It’s implemented here:

> <https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_transmission.ts#L19-L303>

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [September 5, 2023, 11:42pm UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/5 "2023-09-05T23:42:42Z")

</div>

> [@Evgeni\_Popov](#):
>
> Maybe you could “inject” this extension yourself during load, if we have a way to do it… Let’s ask @bghgary if it’s possible

Yes, this is possible. If you use the [onParsedObservable](https://doc.babylonjs.com/typedoc/classes/BABYLON.GLTFFileLoader#onParsedObservable) of the glTF loader, you can modify the glTF JSON before it loads. This is quite hacky though.

---

<div class="post-metadata">

**Author:** ![Forsaken](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/forsaken/32/21296_2.png) [@Forsaken](https://forum.babylonjs.com/u/Forsaken)\
**Post date:** [September 8, 2023, 7:40am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/6 "2023-09-08T07:40:58Z")

</div>

Thanks, with this I managed to create a working example:

[https://playground.babylonjs.com/#592X04#7](https://playground.babylonjs.com/#592X04#7)

I don’t image I can change any of the settings after I’ve enabled them?  
e.g: changing the transmissionFactor of a material

---

<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:** [September 8, 2023, 8:59am UTC](https://forum.babylonjs.com/t/enable-khr-settings-transmission-in-runtime/43686/7 "2023-09-08T08:59:37Z")

</div>

You can change the parameters on the material. For eg, `transmissionFactor` is the intensity of the refraction effect:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/1/3117613271caf677f67cacb4be1d3a819cf3bdc9.png)

Programmatically:

```javascript
scene.getMaterialByName("Without KHR").subSurface.refractionIntensity = 0.5;

```
