Jump to content

Passing Video to a Shader?


igitz
 Share

Recommended Posts

Is there a way to pass a video texture to a shader using a similar way as the one used to pass an image texture?

shaderMaterial.setTexture("textureSampler", new BABYLON.Texture(imgTexture, scene));

i'm wondering if there are more ways to use video textures in babylon, i have seen that i can set a BABYLON.VideoTexture as a diffuseTexture of a material, but that seems limiting. What if i want to manipulate an object which has a material with a video texture, in the vertex + fragment shaders?

Link to comment
Share on other sites

Hi @igitz,

You could do what the video texture is doing - create a video-element, read the next frame and send it to a self-created shader. You could also use the videotexture itself, as it creates a webgl texture (using the following function - https://github.com/BabylonJS/Babylon.js/blob/master/src/Engine/babylon.engine.ts#L3366), which you can use wherever you want.

Link to comment
Share on other sites

thanks for the replies,

i might be doing something wrong, but passing the video texture instead of a texture is something i tried and got a red/black grid instead. so i thought that either my method or the videotexture constructor is not correct.

example:

var shaderMaterial = new BABYLON.ShaderMaterial("material", scene, "./shaders/s00", { attributes: ["position", "uv"], uniforms: ["worldViewProjection"] });

 

var texImage = new BABYLON.Texture("textures/img00.jpg");

shaderMaterial.setTexture("textureSampler", new BABYLON.Texture(texImage, scene));

works, but

var texVideo = new BABYLON.VideoTexture("video", ["textures/video00.mp4"], scene);

shaderMaterial.setTexture("textureSampler", new BABYLON.Texture(texVideo, scene));

doesn't.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...