[SOLVED] Camera viewport to a plane

Hi!

I have already seen some examples to get several cameras and It’s nice. In my case I need to project camera view to a plane. Imagine a car’s rear-view mirror. Is it possible?

Thanks a lot for your time.

Hi @JTARGUI,

You can use a render target to do that, here is a code example:

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

Hi @Leonidas

It’s was a simple idea but I couldn’t solve within your help. Thanks a lot!

Just add a “plane” with “material” and it’s working. I’ve to solve the text "
Trying to bind current color buffer as a texture" and improve with layers but it’s a nice starting point.

var Test = pc.createScript('test');

Test.attributes.add('targetPlane', { type: 'entity' });


// initialize code called once per entity
Test.prototype.initialize = function() {
   var texture = new pc.Texture(this.app.graphicsDevice, {
        width: 512,
        height: 256,
        format: pc.PIXELFORMAT_R8_G8_B8,
        mipmaps: true,
        minFilter: pc.FILTER_LINEAR,
        magFilter: pc.FILTER_LINEAR,
        addressU: pc.ADDRESS_CLAMP_TO_EDGE,
        addressV: pc.ADDRESS_CLAMP_TO_EDGE,
    });

     var renderTarget = new pc.RenderTarget({
        colorBuffer: texture,
        depth: true,
        flipY: true,
    });

    this.entity.camera.priority=-1;
    this.entity.camera.renderTarget = renderTarget;

    this.targetPlane.render.meshInstances[0].emissiveMap = texture;
};

// update code called every frame
Test.prototype.update = function(dt) {

};```
1 Like

I don’t mean to come across as trolling, but I think you meant, “without,” not, “with.”

In this case grammar would make a major difference on how your thankful reply is interpreted by others or the person that you’re replying to. :slightly_smiling_face:

2 Likes

Hi @RPaladin

Thanks for your comment. You are right, my English is very poor and I am always happy to learn :slightly_smiling_face:

2 Likes