Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 175 additions & 171 deletions build/three.cjs

Large diffs are not rendered by default.

325 changes: 163 additions & 162 deletions build/three.core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.core.min.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions build/three.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2739,8 +2739,9 @@ class PMREMGenerator {

/**
* Generates a PMREM from an equirectangular texture, which can be either LDR
* or HDR. The ideal input image size is 1k (1024 x 512),
* as this matches best with the 256 x 256 cubemap output.
* or HDR. The ideal input image size is 1k (1024 x 512), as this matches best
* with the 256 x 256 cubemap output. The minimum supported input image size
* is 64 x 32.
*
* @param {Texture} equirectangular - The equirectangular texture to be converted.
* @param {?WebGLRenderTarget} [renderTarget=null] - The render target to use.
Expand All @@ -2754,8 +2755,9 @@ class PMREMGenerator {

/**
* Generates a PMREM from an cubemap texture, which can be either LDR
* or HDR. The ideal input cube size is 256 x 256,
* as this matches best with the 256 x 256 cubemap output.
* or HDR. The ideal input cube size is 256 x 256, as this matches best
* with the 256 x 256 cubemap output. The minimum supported input cube
* size is 16 x 16 per face.
*
* @param {Texture} cubemap - The cubemap texture to be converted.
* @param {?WebGLRenderTarget} [renderTarget=null] - The render target to use.
Expand Down Expand Up @@ -4793,13 +4795,14 @@ const toneMappingMap = {
[ CustomToneMapping ]: 'CUSTOM_TONE_MAPPING'
};

function WebGLOutput( type, width, height, depth, stencil ) {
function WebGLOutput( type, width, height, antialias, depth, stencil ) {

// render targets for scene and post-processing
const targetA = new WebGLRenderTarget( width, height, {
type: type,
depthBuffer: depth,
stencilBuffer: stencil,
samples: antialias ? 4 : 0,
depthTexture: depth ? new DepthTexture( width, height ) : undefined
} );

Expand Down Expand Up @@ -7119,7 +7122,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );

error(
'THREE.WebGLProgram: Shader Error ' + gl.getError() + ' - ' +
'WebGLProgram: Shader Error ' + gl.getError() + ' - ' +
'VALIDATE_STATUS ' + gl.getProgramParameter( program, gl.VALIDATE_STATUS ) + '\n\n' +
'Material Name: ' + self.name + '\n' +
'Material Type: ' + self.type + '\n\n' +
Expand Down Expand Up @@ -16484,7 +16487,7 @@ class WebGLRenderer {

if ( _outputBufferType !== UnsignedByteType ) {

output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, depth, stencil );
output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, antialias, depth, stencil );

}

Expand Down Expand Up @@ -16668,7 +16671,7 @@ class WebGLRenderer {

if ( _outputBufferType === UnsignedByteType ) {

error( 'THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.' );
error( 'WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.' );
return;

}
Expand All @@ -16679,7 +16682,7 @@ class WebGLRenderer {

if ( effects[ i ].isOutputPass === true ) {

warn( 'THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.' );
warn( 'WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.' );
break;

}
Expand Down
2 changes: 1 addition & 1 deletion build/three.module.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion build/three.tsl.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.tsl.min.js

Large diffs are not rendered by default.

883 changes: 595 additions & 288 deletions build/three.webgpu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.webgpu.min.js

Large diffs are not rendered by default.

883 changes: 595 additions & 288 deletions build/three.webgpu.nodes.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.webgpu.nodes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import NodeMaterialObserver from './manager/NodeMaterialObserver.js';
import getAlphaHashThreshold from '../../nodes/functions/material/getAlphaHashThreshold.js';
import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
import { vertexColor } from '../../nodes/accessors/VertexColorNode.js';
import { premultiplyAlpha } from '../../nodes/display/BlendModes.js';
import { premultiplyAlpha } from '../../nodes/display/PremultiplyAlphaFunctions.js';
import { subBuild } from '../../nodes/core/SubBuildNode.js';

/**
Expand Down
1 change: 1 addition & 0 deletions src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export * from './display/ColorAdjustment.js';
export * from './display/ColorSpaceNode.js';
export * from './display/FrontFacingNode.js';
export * from './display/NormalMapNode.js';
export * from './display/PremultiplyAlphaFunctions.js';
export * from './display/ToneMappingNode.js';
export * from './display/ScreenNode.js';
export * from './display/ViewportTextureNode.js';
Expand Down
42 changes: 1 addition & 41 deletions src/nodes/display/BlendModes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fn, If, vec4 } from '../tsl/TSLBase.js';
import { Fn, vec4 } from '../tsl/TSLCore.js';
import { mix, min, step } from '../math/MathNode.js';

/**
Expand Down Expand Up @@ -129,43 +129,3 @@ export const blendColor = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {
{ name: 'blend', type: 'vec4' }
]
} );

/**
* Premultiplies the RGB channels of a color by its alpha channel.
*
* This function is useful for converting a non-premultiplied alpha color
* into a premultiplied alpha format, where the RGB values are scaled
* by the alpha value. Premultiplied alpha is often used in graphics
* rendering for certain operations, such as compositing and image processing.
*
* @tsl
* @function
* @param {Node<vec4>} color - The input color with non-premultiplied alpha.
* @return {Node<vec4>} The color with premultiplied alpha.
*/
export const premultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {

return vec4( color.rgb.mul( color.a ), color.a );

}, { color: 'vec4', return: 'vec4' } );

/**
* Unpremultiplies the RGB channels of a color by its alpha channel.
*
* This function is useful for converting a premultiplied alpha color
* back into a non-premultiplied alpha format, where the RGB values are
* divided by the alpha value. Unpremultiplied alpha is often used in graphics
* rendering for certain operations, such as compositing and image processing.
*
* @tsl
* @function
* @param {Node<vec4>} color - The input color with premultiplied alpha.
* @return {Node<vec4>} The color with non-premultiplied alpha.
*/
export const unpremultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {

If( color.a.equal( 0.0 ), () => vec4( 0.0 ) );

return vec4( color.rgb.div( color.a ), color.a );

}, { color: 'vec4', return: 'vec4' } );
39 changes: 39 additions & 0 deletions src/nodes/display/PremultiplyAlphaFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Fn, vec4 } from '../tsl/TSLCore.js';

/**
* Premultiplies the RGB channels of a color by its alpha channel.
*
* This function is useful for converting a non-premultiplied alpha color
* into a premultiplied alpha format, where the RGB values are scaled
* by the alpha value. Premultiplied alpha is often used in graphics
* rendering for certain operations, such as compositing and image processing.
*
* @tsl
* @function
* @param {Node<vec4>} color - The input color with non-premultiplied alpha.
* @return {Node<vec4>} The color with premultiplied alpha.
*/
export const premultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {

return vec4( color.rgb.mul( color.a ), color.a );

}, { color: 'vec4', return: 'vec4' } );

/**
* Unpremultiplies the RGB channels of a color by its alpha channel.
*
* This function is useful for converting a premultiplied alpha color
* back into a non-premultiplied alpha format, where the RGB values are
* divided by the alpha value. Unpremultiplied alpha is often used in graphics
* rendering for certain operations, such as compositing and image processing.
*
* @tsl
* @function
* @param {Node<vec4>} color - The input color with premultiplied alpha.
* @return {Node<vec4>} The color with non-premultiplied alpha.
*/
export const unpremultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {

return color.a.equal( 0 ).select( vec4( 0 ), vec4( color.rgb.div( color.a ), color.a ) );

}, { color: 'vec4', return: 'vec4' } );
15 changes: 12 additions & 3 deletions src/nodes/display/RenderOutputNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TempNode from '../core/TempNode.js';
import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';
import { addMethodChaining, nodeObject, vec4 } from '../tsl/TSLCore.js';
import { premultiplyAlpha, unpremultiplyAlpha } from './PremultiplyAlphaFunctions.js';

import { NoColorSpace, NoToneMapping } from '../../constants.js';
import { ColorManagement } from '../../math/ColorManagement.js';
Expand Down Expand Up @@ -108,9 +109,15 @@ class RenderOutputNode extends TempNode {

let outputNode = this.colorNode || context.color;

// tone mapping
// clamp alpha
outputNode = vec4( outputNode.rgb, outputNode.a.clamp( 0.0, 1.0 ) );

// unpremultiply
outputNode = unpremultiplyAlpha( outputNode );

// tone mapping
const toneMapping = ( this._toneMapping !== null ? this._toneMapping : context.toneMapping ) || NoToneMapping;

const outputColorSpace = ( this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace ) || NoColorSpace;

if ( toneMapping !== NoToneMapping ) {
Expand All @@ -120,13 +127,15 @@ class RenderOutputNode extends TempNode {
}

// working to output color space

if ( outputColorSpace !== NoColorSpace && outputColorSpace !== ColorManagement.workingColorSpace ) {

outputNode = outputNode.workingToColorSpace( outputColorSpace );

}

// premultiply in output color space
outputNode = premultiplyAlpha( outputNode );

return outputNode;

}
Expand Down
Loading