# Clamp video texture

**URL:** <https://forum.babylonjs.com/t/clamp-video-texture/41608>\
**Category:** Questions\
**Tags:** texture\
**Created:** [June 14, 2023, 11:23am UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608 "2023-06-14T11:23:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yunus\_Tencere](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yunus_tencere/32/12100_2.png) [@Yunus\_Tencere](https://forum.babylonjs.com/u/Yunus_Tencere)\
**Post date:** [June 14, 2023, 11:23am UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/1 "2023-06-14T11:23:04Z")

</div>

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

I want to preserve the video aspect ratio and video mesh size. So i want video texture to stop repeating and see black stripes at the bottom and top. How can i do it?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 14, 2023, 11:38am UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/2 "2023-06-14T11:38:14Z")

</div>

You can set the clamp mode after the video has loaded:

[clamping video | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#ZMCFYA#568)

---

<div class="post-metadata">

**Author:** ![Yunus\_Tencere](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yunus_tencere/32/12100_2.png) [@Yunus\_Tencere](https://forum.babylonjs.com/u/Yunus_Tencere)\
**Post date:** [June 14, 2023, 12:15pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/3 "2023-06-14T12:15:24Z")

</div>

Thank you. How about black stripes?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 14, 2023, 1:04pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/4 "2023-06-14T13:04:58Z")

</div>

I hope people will correct me if I am wrong, but I can’t think of a possibility to have black stripes with texture properties alone.  
Since you have the properties (you are setting the vscale and voffset, for example, and the size of the plane) you can also calculate the size of the required black stripes, or resize the plane on which the texture is displayed to avoid the need of black stripes altogether

---

<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:** [June 14, 2023, 6:11pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/5 "2023-06-14T18:11:01Z")

</div>

Indeed, clamp to border and border color are not supported in WebGL, see for eg:

> [@Support Texture-Wrap mode CLAMP\_TO\_BORDER?](https://forum.babylonjs.com/t/support-texture-wrap-mode-clamp-to-border/6926):
>
> According to [OpenGL - Textures](https://open.gl/textures) threre are 4 modes, but Babylon does not support #define GL\_CLAMP\_TO\_BORDER 0x812D \<==== what I need #define GL\_CLAMP\_TO\_EDGE 0x812F #define GL\_MIRRORED\_REPEAT 0x8370 #define GL\_REPEAT 0x2901 On my OSM streeds are direction arrows. The right one goes to the border and causes side effekts according to GL\_CLAMP\_TO\_EDGE (The left one needed a transparent 32 pixel border to be ok) So I “manipulated” babylon.max.js, added TEXTURE\_BORDER\_ADDRESSMODE = 4 …

---

<div class="post-metadata">

**Author:** ![Yunus\_Tencere](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yunus_tencere/32/12100_2.png) [@Yunus\_Tencere](https://forum.babylonjs.com/u/Yunus_Tencere)\
**Post date:** [June 14, 2023, 6:36pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/6 "2023-06-14T18:36:55Z")

</div>

Thank you. So do i need a custom shader for this? And i dont know how to write a custom shader, can you show me a way to learn it ?

---

<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:** [June 14, 2023, 7:32pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/7 "2023-06-14T19:32:22Z")

</div>

I think the suggestion from @RaananW would be the best thing to do:

> [@RaananW](#):
>
> or resize the plane on which the texture is displayed to avoid the need of black stripes altogether

---

<div class="post-metadata">

**Author:** ![Yunus\_Tencere](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yunus_tencere/32/12100_2.png) [@Yunus\_Tencere](https://forum.babylonjs.com/u/Yunus_Tencere)\
**Post date:** [June 14, 2023, 8:20pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/8 "2023-06-14T20:20:46Z")

</div>

That is not a good solution in my case

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [June 14, 2023, 9:38pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/9 "2023-06-14T21:38:07Z")

</div>

babylonjs has a great visual node material system.

I tried to make an example, he can set the actual video width and height to display, while the rest is black.

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

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [June 14, 2023, 9:41pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/10 "2023-06-14T21:41:01Z")

</div>

This is the address of the material just used.  
[Babylon.js Node Material Editor (babylonjs.com)](https://nme.babylonjs.com/#67WCC6)

Here is the documentation for this material system.  
[Node Material | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/materials/node_material/nodeMaterial)

It’s very similar to unreal engine’s blueprint or blender’s node material system, if you have similar experience, I believe you can get started quickly.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [June 14, 2023, 10:30pm UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/11 "2023-06-14T22:30:37Z")

</div>

Here are some examples of Node materials.  
Centring a video texture - [https://playground.babylonjs.com/#8S19ZC#29](https://playground.babylonjs.com/#8S19ZC#29)  
Video texture fills available space - [https://playground.babylonjs.com/#8S19ZC#38](https://playground.babylonjs.com/#8S19ZC#38)

---

<div class="post-metadata">

**Author:** ![Yunus\_Tencere](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yunus_tencere/32/12100_2.png) [@Yunus\_Tencere](https://forum.babylonjs.com/u/Yunus_Tencere)\
**Post date:** [June 15, 2023, 9:44am UTC](https://forum.babylonjs.com/t/clamp-video-texture/41608/12 "2023-06-15T09:44:32Z")

</div>

Second pg is the one i am looking for. Thank you! Thanks for all the answers.
