Hi,
I am trying to render the output of a camera to a material. I have tried reviewing some old examples(https://playcanvas.com/project/335444/overview/tutorial-render-to-texture). However nothing seems to work. The object using the material still appears empty.
Here is my implementation of the script, i am not sure why it doesnt work:
var CameraRenderTarget = pc.createScript('cameraRenderTarget');
CameraRenderTarget.attributes.add("RenderTargetMaterial",{type:"asset",assetType:"material"});
// initialize code called once per entity
CameraRenderTarget.prototype.initialize = function() {
var colorBuffer = new pc.Texture(this.app.graphicsDevice, {
width: 512,
height: 512,
format: pc.PIXELFORMAT_R8_G8_B8,
autoMipmap: true
});
colorBuffer.minFilter = pc.FILTER_LINEAR;
colorBuffer.magFilter = pc.FILTER_LINEAR;
var renderTarget = new pc.RenderTarget(this.app.graphicsDevice, colorBuffer, {
depth: true
});
this.renderTarget = renderTarget;
this.entity.camera.renderTarget = renderTarget;
this.RenderTargetMaterial.diffuseMap = renderTarget;
};
// update code called every frame
CameraRenderTarget.prototype.update = function(dt) {
};
thanks