Rendering Camera Feed as Texture on a Plane

Hi

I am trying to Render Camera Feed as Texture on a Plane, similar to the example project - https://playcanvas.com/project/528262/overview/render-to-texture-test

But when i try to fork this project or try to create a new project on similar lines, I am getting a getting blank plane with no camera feed.

Also, i wanted to do this in AR, any more directions will be a great help.

Thanks

Hi @parul_bansal,

That example is a bit old, written before the Playcanvas Layers system was introduced. Now the way to do that would be to create a new Layer in the editor, assign it to your active camera and objects you would like to render on and in code make the following change:

//     // Set the render target on an entity's camera component
//     this.entity.camera.renderTarget = renderTarget;
    
    // added a new Layer named Render
    var layer = this.app.scene.layers.getLayerByName('Render');
    layer.renderTarget = renderTarget;

If you would like to render to texture the whole Layers composition including the skybox etc, take a look at the following project by @yaustar :

https://playcanvas.com/project/605131/overview/capturing-screenshot-from-camera

Hey Thanks for the reply I used the layers and the code suggested above.

  1. I am able to get the 3d object, but i am unable to get the skybox.
  2. Also, I am able to get the model wrapped ona a cylinder like shown in this example - https://playcanvas.com/project/560797/overview/tutorial-render-to-texture
    but i want it to get wrapped only the curved surface. My project is about wrapping a watch around a cylinder in AR, with cylinder having camera feed texture.

As the 3d models always load on top of the marker, I was just trying to experiement, if i can mimic it getting wrapped aroung hand with this.

Thanks
Parul

Hi @parul_bansal,

  1. Good point, let me check and will get back to you what’s the best way to get the full camera feed and not just a camera layer.

  2. To do that you need to prepare a cylinder model in your modelling app, to have the right texture coordinates for your use case (unwap UVW).

Hi @Leonidas

Gr8, I will try to modify the cylinder object with blender.

Also, do let me know incase you find a solution for point 1. I will also look and share if i find something

Thanks :slight_smile:

1 Like

Hi @parul_bansal,

Here is an example that renders a full camera view on a plane, it’s an engine based example.

http://playcanvas.github.io/#graphics/render-to-texture.html

Hope it helps! The full source code:

Edit: About the Skybox though, since that is rendered on its own layer I think still it will not be included on the rendered texture. There is a quick and dirty solution to grab a texture from the Application texture, but that will kill performance.

Will research further on what is the optimal way :wink: Most likely using a pc.PostEffect to copy the colorBuffer to a render texture.

Hey

Apologies for late reply.

Thanks for the suggestion. I will try this example and get back to you with the results…
Thanks again for your help.

1 Like