Skip to content
🎉 Angular Three v4 is here! Read the announcement

fbo

fbo creates a WebGLRenderTarget (Frame Buffer Object) for off-screen rendering. The FBO is automatically sized to the canvas dimensions if width/height are not specified, and is disposed on component destroy.

Usage

import { fbo } from 'angular-three-soba/misc';
import { beforeRender } from 'angular-three';
@Component({...})
class MyComponent {
// Basic usage - sized to canvas
renderTarget = fbo();
// Custom size with multisampling
target = fbo(() => ({
width: 512,
height: 512,
settings: { samples: 4 }
}));
constructor() {
// Render to FBO
beforeRender(({ gl, scene, camera }) => {
gl.setRenderTarget(this.target);
gl.render(scene, camera);
gl.setRenderTarget(null);
});
}
}

NgtsFBOParams

PropertyTypeDescription
widthnumberWidth in pixels. Defaults to canvas width × device pixel ratio
heightnumberHeight in pixels. Defaults to canvas height × device pixel ratio
settingsRenderTargetOptionsTHREE.js render target options

Settings Options

PropertyTypeDefaultDescription
samplesnumber0Samples for MSAA
depthbooleanfalseRender scene depth into buffer.depthTexture
depthBufferbooleantrueInclude a depth buffer
stencilBufferbooleanfalseInclude a stencil buffer

injectFBO is deprecated. Use fbo instead.

Arguments

name type description required
params () => NgtsFBOParams Signal returning FBO configuration with width, height, and settings no
options { injector?: Injector } Optional configuration object with injector no

Returns

typedescription
THREE.WebGLRenderTargetA WebGLRenderTarget for off-screen rendering

Creates a WebGLRenderTarget (Frame Buffer Object) for off-screen rendering. The FBO is automatically sized to the canvas dimensions if width/height are not specified, and is disposed on component destroy.

import { fbo } from 'angular-three-soba/misc';
import { beforeRender } from 'angular-three';
@Component({...})
class MyComponent {
// Basic usage - sized to canvas
renderTarget = fbo();
// Custom size with multisampling
target = fbo(() => ({
width: 512,
height: 512,
settings: { samples: 4 },
}));
constructor() {
// Render to FBO
beforeRender(({ gl, scene, camera }) => {
gl.setRenderTarget(this.target);
gl.render(scene, camera);
gl.setRenderTarget(null);
});
}
}
function fbo(
params: () => NgtsFBOParams = () => ({}),
{ injector }: { injector?: Injector } = {},
): THREE.WebGLRenderTarget;
ParameterTypeDescription
params() => NgtsFBOParamsSignal of FBO configuration
injectorInjector (optional)Custom injector for dependency injection
PropertyTypeDescription
widthnumberWidth in pixels. Defaults to canvas width × device pixel ratio
heightnumberHeight in pixels. Defaults to canvas height × device pixel ratio
settingsRenderTargetOptionsTHREE.js render target options (see below)
PropertyTypeDefaultDescription
samplesnumber0Samples for MSAA. Set to 0 to disable
depthbooleanfalseRender scene depth into buffer.depthTexture
depthBufferbooleantrueInclude a depth buffer
stencilBufferbooleanfalseInclude a stencil buffer
generateMipmapsbooleantrueGenerate mipmaps for the FBO texture
wrapSWrapping-Wrapping mode for s-coordinate
wrapTWrapping-Wrapping mode for t-coordinate
magFilterTextureFilter-Magnification filter
minFilterTextureFilter-Minification filter
formatPixelFormat-Internal format of the color buffer
typeTextureDataType-Data type of the color buffer
anisotropynumber-Anisotropic filtering level
depthTextureDepthTexture-Custom DepthTexture instance
colorSpaceColorSpace-Color space of the FBO texture

Returns a THREE.WebGLRenderTarget that can be used for off-screen rendering.


A structural directive that renders a part of your scene into an FBO using ng-template. Provides the created WebGLRenderTarget as implicit context to the template.

<ng-template [fbo]="{ width: 512, height: 512 }" let-target>
<!-- target is the WebGLRenderTarget -->
<ngt-mesh>
<ngt-plane-geometry />
<ngt-mesh-basic-material [map]="target.texture" />
</ngt-mesh>
</ng-template>
<ng-template [fbo]="{ width: 1024, height: 1024, samples: 4 }" let-target>
<ngt-mesh>
<ngt-box-geometry />
<ngt-mesh-standard-material [map]="target.texture" />
</ngt-mesh>
</ng-template>