yes, we need as an image.
It’s possible to capture with transparency directly using the method we are apply?, what we are doing is
creating a texture from the camera viewport, I will explain it here:,
var colorBuffer = new pc.Texture(this.app.graphicsDevice, {
width: 1024,
height: 1024,
format: pc.PIXELFORMAT_R8_G8_B8,
autoMipmap: true
});
colorBuffer.minFilter = pc.FILTER_LINEAR;
colorBuffer.magFilter = pc.FILTER_LINEAR;
this.renderTarget = new pc.RenderTarget(this.app.graphicsDevice, colorBuffer, {
depth: true,
flipY: true
});
var layer = this.app.scene.layers.getLayerByName(this.layerName); //our layer to capture
layer.renderTarget = this.renderTarget;
this.framebuffer = this.app.graphicsDevice.gl.createFramebuffer();
this.pixels = new Uint8Array(colorBuffer.width * colorBuffer.height * 4);
var cb = this.renderTarget.colorBuffer;
this.canvas = window.document.createElement('canvas');
this.context = this.canvas.getContext('2d');
this.canvas.width = cb.width;
this.canvas.height = cb.height;
// then we take the screenshot
takeScreenshot = function () {
var colorBuffer = this.renderTarget.colorBuffer;
var gl = this.app.graphicsDevice.gl;
var fb = this.framebuffer;
var pixels = this.pixels;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorBuffer._glTexture, 0);
gl.readPixels(0, 0, colorBuffer.width, colorBuffer.height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
var imgData = this.context.createImageData(colorBuffer.width, colorBuffer.height);
var data = imgData.data;
var palette = this.context.getImageData(0, 0, colorBuffer.width, colorBuffer.height);
palette.data.set(new Uint8ClampedArray(pixels));
this.context.putImageData(palette, 0, 0);
this.context.drawImage(this.canvas, 0,0);
this.b64 = this.canvas.toDataURL('image/jpeg', 0.5);
//console.log(b64); // finally our base64 image!
};
we use this and set different sizes and layers, and every works ok, but the problem is the texture didn’t get transparency, even if we use a camera with clear color, transparent canvas, camera color with alpha = 0,
maybe there’s some parameters to config the new texture, to allow to detect the transparency from the captured camera view?
thanks!!!