PHP 7.4.33
Preview: PostProcessing.js Size: 4.27 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/three/src/renderers/common/PostProcessing.js
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
import { vec4, renderOutput } from '../../nodes/TSL.js';
import { LinearSRGBColorSpace, NoToneMapping } from '../../constants.js';
import QuadMesh from '../../renderers/common/QuadMesh.js';

/**
 * This module is responsible to manage the post processing setups in apps.
 * You usually create a single instance of this class and use it to define
 * the output of your post processing effect chain.
 * ```js
 * const postProcessing = new PostProcessing( renderer );
 *
 * const scenePass = pass( scene, camera );
 *
 * postProcessing.outputNode = scenePass;
 * ```
 */
class PostProcessing {

	/**
	 * Constructs a new post processing management module.
	 *
	 * @param {Renderer} renderer - A reference to the renderer.
	 * @param {Node<vec4>} outputNode - An optional output node.
	 */
	constructor( renderer, outputNode = vec4( 0, 0, 1, 1 ) ) {

		/**
		 * A reference to the renderer.
		 *
		 * @type {Renderer}
		 */
		this.renderer = renderer;

		/**
		 * A node which defines the final output of the post
		 * processing. This is usually the last node in a chain
		 * of effect nodes.
		 *
		 * @type {Node<vec4>}
		 */
		this.outputNode = outputNode;

		/**
		 * Whether the default output tone mapping and color
		 * space transformation should be enabled or not.
		 *
		 * It is enabled by default by it must be disabled when
		 * effects must be executed after tone mapping and color
		 * space conversion. A typical example is FXAA which
		 * requires sRGB input.
		 *
		 * When set to `false`, the app must control the output
		 * transformation with `RenderOutputNode`.
		 *
		 * ```js
		 * const outputPass = renderOutput( scenePass );
		 * ```
		 *
		 * @type {boolean}
		 */
		this.outputColorTransform = true;

		/**
		 * Must be set to `true` when the output node changes.
		 *
		 * @type {Node<vec4>}
		 */
		this.needsUpdate = true;

		const material = new NodeMaterial();
		material.name = 'PostProcessing';

		/**
		 * The full screen quad that is used to render
		 * the effects.
		 *
		 * @private
		 * @type {QuadMesh}
		 */
		this._quadMesh = new QuadMesh( material );

	}

	/**
	 * When `PostProcessing` is used to apply post processing effects,
	 * the application must use this version of `render()` inside
	 * its animation loop (not the one from the renderer).
	 */
	render() {

		this._update();

		const renderer = this.renderer;

		const toneMapping = renderer.toneMapping;
		const outputColorSpace = renderer.outputColorSpace;

		renderer.toneMapping = NoToneMapping;
		renderer.outputColorSpace = LinearSRGBColorSpace;

		//

		const currentXR = renderer.xr.enabled;
		renderer.xr.enabled = false;

		this._quadMesh.render( renderer );

		renderer.xr.enabled = currentXR;

		//

		renderer.toneMapping = toneMapping;
		renderer.outputColorSpace = outputColorSpace;

	}

	/**
	 * Frees internal resources.
	 */
	dispose() {

		this._quadMesh.material.dispose();

	}

	/**
	 * Updates the state of the module.
	 *
	 * @private
	 */
	_update() {

		if ( this.needsUpdate === true ) {

			const renderer = this.renderer;

			const toneMapping = renderer.toneMapping;
			const outputColorSpace = renderer.outputColorSpace;

			this._quadMesh.material.fragmentNode = this.outputColorTransform === true ? renderOutput( this.outputNode, toneMapping, outputColorSpace ) : this.outputNode.context( { toneMapping, outputColorSpace } );
			this._quadMesh.material.needsUpdate = true;

			this.needsUpdate = false;

		}

	}

	/**
	 * When `PostProcessing` is used to apply post processing effects,
	 * the application must use this version of `renderAsync()` inside
	 * its animation loop (not the one from the renderer).
	 *
	 * @async
	 * @return {Promise} A Promise that resolves when the render has been finished.
	 */
	async renderAsync() {

		this._update();

		const renderer = this.renderer;

		const toneMapping = renderer.toneMapping;
		const outputColorSpace = renderer.outputColorSpace;

		renderer.toneMapping = NoToneMapping;
		renderer.outputColorSpace = LinearSRGBColorSpace;

		//

		const currentXR = renderer.xr.enabled;
		renderer.xr.enabled = false;

		await this._quadMesh.renderAsync( renderer );

		renderer.xr.enabled = currentXR;

		//

		renderer.toneMapping = toneMapping;
		renderer.outputColorSpace = outputColorSpace;

	}

}

export default PostProcessing;

Directory Contents

Dirs: 2 × Files: 50
Name Size Perms Modified Actions
extras DIR
- drwxr-xr-x 2025-03-28 11:04:39
Edit Download
nodes DIR
- drwxr-xr-x 2025-03-28 11:04:38
Edit Download
2.48 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.39 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
15.92 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
5.20 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.11 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.01 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.81 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.26 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.50 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.71 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.74 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
5.46 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.53 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
740 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
283 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
2.61 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.28 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
7.19 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
998 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
3.73 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.34 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
484 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
11.50 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
4.27 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.72 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.33 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
458 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.13 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.86 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.53 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
74.32 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.37 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.09 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.27 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
17.04 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.19 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
806 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.65 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
769 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
718 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.44 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.52 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.26 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.13 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.61 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.83 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
561 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.22 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
27.59 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.72 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).