Hey hey
I’m currently trying to set up an ui element, that displays everything that is being rendered by a specific camera. I used this Example as a general guideline, I’m setting the texture on an element component instead of a material and it works great so far.
Everything above the yellow line is just one ui element that shows what is being rendered by a camera
The issue I’m facing now is that the ui element is responsive to the width of the screen. If I change the resolution, it will become stretched or compressed.
On resizing the screen, I would like to adjust the resolution of the texture that camera renders into. But I don’t see a way of resizing a texture? Both camera.renderTarget.width
and camera.renderTarget.colorBuffer.width
are read-only properties. camera.renderTarget.colorBuffer
is read-only as well. Is the only way to achieve this to create a new texture and a new renderTarget and switch them on the camera?
Here is a bit of the code I’m currently using:
private setupRenderTarget(): void
{
const colorBuffer = new pc.Texture(this.app.graphicsDevice, {
width: this.elementComponent.width,
height: this.elementComponent.height,
format: pc.PIXELFORMAT_R8_G8_B8_A8,
minFilter: pc.FILTER_LINEAR,
magFilter: pc.FILTER_LINEAR,
});
const renderTarget = new pc.RenderTarget({
colorBuffer: colorBuffer,
depth: true,
flipY: true,
});
this.camera.renderTarget = renderTarget;
this.elementComponent.texture = renderTarget.colorBuffer;
this.elementComponent.color = pc.Color.WHITE;
this.elementComponent.opacity = 1;
}