Browse Source

Nodes: Rename invert() -> oneMinus() (#25725)

sunag 2 years ago
parent
commit
25ef6adba4

+ 1 - 1
examples/jsm/nodes/Nodes.js

@@ -34,7 +34,7 @@ export { default as VaryingNode, varying } from './core/VaryingNode.js';
 export * as NodeUtils from './core/NodeUtils.js';
 
 // math
-export { default as MathNode, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, negate, invert, dFdx, dFdy, round, reciprocal, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward } from './math/MathNode.js';
+export { default as MathNode, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, negate, oneMinus, dFdx, dFdy, round, reciprocal, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward } from './math/MathNode.js';
 export { default as OperatorNode, add, sub, mul, div, remainder, equal, assign, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, xor, bitAnd, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
 export { default as CondNode, cond } from './math/CondNode.js';
 

+ 4 - 4
examples/jsm/nodes/display/BlendModeNode.js

@@ -5,7 +5,7 @@ import { addNodeElement, ShaderNode, nodeProxy, vec3 } from '../shadernode/Shade
 
 export const BurnNode = new ShaderNode( ( { base, blend } ) => {
 
-	const fn = ( c ) => blend[ c ].lessThan( EPSILON ).cond( blend[ c ], base[ c ].invert().div( blend[ c ] ).invert().max( 0 ) );
+	const fn = ( c ) => blend[ c ].lessThan( EPSILON ).cond( blend[ c ], base[ c ].oneMinus().div( blend[ c ] ).oneMinus().max( 0 ) );
 
 	return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );
 
@@ -13,7 +13,7 @@ export const BurnNode = new ShaderNode( ( { base, blend } ) => {
 
 export const DodgeNode = new ShaderNode( ( { base, blend } ) => {
 
-	const fn = ( c ) => blend[ c ].equal( 1.0 ).cond( blend[ c ], base[ c ].div( blend[ c ].invert() ).max( 0 ) );
+	const fn = ( c ) => blend[ c ].equal( 1.0 ).cond( blend[ c ], base[ c ].div( blend[ c ].oneMinus() ).max( 0 ) );
 
 	return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );
 
@@ -21,7 +21,7 @@ export const DodgeNode = new ShaderNode( ( { base, blend } ) => {
 
 export const ScreenNode = new ShaderNode( ( { base, blend } ) => {
 
-	const fn = ( c ) => base[ c ].invert().mul( blend[ c ].invert() ).invert();
+	const fn = ( c ) => base[ c ].oneMinus().mul( blend[ c ].oneMinus() ).oneMinus();
 
 	return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );
 
@@ -29,7 +29,7 @@ export const ScreenNode = new ShaderNode( ( { base, blend } ) => {
 
 export const OverlayNode = new ShaderNode( ( { base, blend } ) => {
 
-	const fn = ( c ) => base[ c ].lessThan( 0.5 ).cond( base[ c ].mul( blend[ c ], 2.0 ), base[ c ].invert().mul( blend[ c ].invert() ).invert() );
+	const fn = ( c ) => base[ c ].lessThan( 0.5 ).cond( base[ c ].mul( blend[ c ], 2.0 ), base[ c ].oneMinus().mul( blend[ c ].oneMinus() ).oneMinus() );
 
 	return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );
 

+ 3 - 3
examples/jsm/nodes/display/ViewportNode.js

@@ -69,10 +69,10 @@ class ViewportNode extends Node {
 			let outX = output.x;
 			let outY = output.y;
 
-			if ( /top/i.test( scope ) && builder.isFlipY() ) outY = outY.invert();
-			else if ( /bottom/i.test( scope ) && builder.isFlipY() === false ) outY = outY.invert();
+			if ( /top/i.test( scope ) && builder.isFlipY() ) outY = outY.oneMinus();
+			else if ( /bottom/i.test( scope ) && builder.isFlipY() === false ) outY = outY.oneMinus();
 
-			if ( /right/i.test( scope ) ) outX = outX.invert();
+			if ( /right/i.test( scope ) ) outX = outX.oneMinus();
 
 			output = vec2( outX, outY );
 

+ 1 - 1
examples/jsm/nodes/fog/FogExp2Node.js

@@ -20,7 +20,7 @@ class FogExp2Node extends FogNode {
 		const depthNode = positionView.z.negate();
 		const densityNode = this.densityNode;
 
-		this.factorNode = densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().invert();
+		this.factorNode = densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();
 
 	}
 

+ 1 - 1
examples/jsm/nodes/functions/BSDF/D_GGX.js

@@ -9,7 +9,7 @@ const D_GGX = new ShaderNode( ( inputs ) => {
 
 	const a2 = alpha.pow2();
 
-	const denom = dotNH.pow2().mul( a2.invert() ).invert(); // avoid alpha = 0 with dotNH = 1
+	const denom = dotNH.pow2().mul( a2.oneMinus() ).oneMinus(); // avoid alpha = 0 with dotNH = 1
 
 	return a2.div( denom.pow2() ).mul( 1 / Math.PI );
 

+ 1 - 1
examples/jsm/nodes/functions/BSDF/F_Schlick.js

@@ -11,7 +11,7 @@ const F_Schlick = new ShaderNode( ( inputs ) => {
 	// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
 	const fresnel = dotVH.mul( - 5.55473 ).sub( 6.98316 ).mul( dotVH ).exp2();
 
-	return f0.mul( fresnel.invert() ).add( f90.mul( fresnel ) );
+	return f0.mul( fresnel.oneMinus() ).add( f90.mul( fresnel ) );
 
 } ); // validated
 

+ 2 - 2
examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js

@@ -10,8 +10,8 @@ const V_GGX_SmithCorrelated = new ShaderNode( ( inputs ) => {
 
 	const a2 = alpha.pow2();
 
-	const gv = dotNL.mul( a2.add( a2.invert().mul( dotNV.pow2() ) ).sqrt() );
-	const gl = dotNV.mul( a2.add( a2.invert().mul( dotNL.pow2() ) ).sqrt() );
+	const gv = dotNL.mul( a2.add( a2.oneMinus().mul( dotNV.pow2() ) ).sqrt() );
+	const gl = dotNV.mul( a2.add( a2.oneMinus().mul( dotNL.pow2() ) ).sqrt() );
 
 	return div( 0.5, gv.add( gl ).max( EPSILON ) );
 

+ 6 - 6
examples/jsm/nodes/functions/PhysicalLightingModel.js

@@ -18,10 +18,10 @@ const computeMultiscattering = ( singleScatter, multiScatter, specularF90 = floa
 	const FssEss = specularColor.mul( fab.x ).add( specularF90.mul( fab.y ) );
 
 	const Ess = fab.x.add( fab.y );
-	const Ems = Ess.invert();
+	const Ems = Ess.oneMinus();
 
-	const Favg = specularColor.add( specularColor.invert().mul( 0.047619 ) ); // 1/21
-	const Fms = FssEss.mul( Favg ).div( Ems.mul( Favg ).invert() );
+	const Favg = specularColor.add( specularColor.oneMinus().mul( 0.047619 ) ); // 1/21
+	const Fms = FssEss.mul( Favg ).div( Ems.mul( Favg ).oneMinus() );
 
 	singleScatter.addAssign( FssEss );
 	multiScatter.addAssign( Fms.mul( Ems ) );
@@ -40,7 +40,7 @@ const RE_IndirectSpecular_Physical = new ShaderNode( ( inputs ) => {
 
 	computeMultiscattering( singleScattering, multiScattering );
 
-	const diffuse = diffuseColor.mul( singleScattering.add( multiScattering ).invert() );
+	const diffuse = diffuseColor.mul( singleScattering.add( multiScattering ).oneMinus() );
 
 	reflectedLight.indirectSpecular.addAssign( radiance.mul( singleScattering ) );
 	reflectedLight.indirectSpecular.addAssign( multiScattering.mul( cosineWeightedIrradiance ) );
@@ -75,9 +75,9 @@ const RE_AmbientOcclusion_Physical = new ShaderNode( ( { ambientOcclusion, refle
 	const dotNV = transformedNormalView.dot( positionViewDirection ).clamp();
 
 	const aoNV = dotNV.add( ambientOcclusion );
-	const aoExp = roughness.mul( - 16.0 ).invert().negate().exp2();
+	const aoExp = roughness.mul( - 16.0 ).oneMinus().negate().exp2();
 
-	const aoNode = ambientOcclusion.sub( aoNV.pow( aoExp ).invert() ).clamp();
+	const aoNode = ambientOcclusion.sub( aoNV.pow( aoExp ).oneMinus() ).clamp();
 
 	reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );
 

+ 1 - 1
examples/jsm/nodes/functions/light/getDistanceAttenuation.js

@@ -10,7 +10,7 @@ const getDistanceAttenuation = new ShaderNode( ( inputs ) => {
 	const distanceFalloff = lightDistance.pow( decayExponent ).max( 0.01 ).reciprocal();
 
 	return cutoffDistance.greaterThan( 0 ).cond(
-		distanceFalloff.mul( lightDistance.div( cutoffDistance ).pow4().invert().clamp().pow2() ),
+		distanceFalloff.mul( lightDistance.div( cutoffDistance ).pow4().oneMinus().clamp().pow2() ),
 		distanceFalloff
 	);
 

+ 2 - 2
examples/jsm/nodes/lighting/EnvironmentNode.js

@@ -53,7 +53,7 @@ class EnvironmentNode extends LightingNode {
 						// @TODO: Needed PMREM
 
 						radianceTextureUVNode = equirectUV( reflectVec );
-						radianceTextureUVNode = vec2( radianceTextureUVNode.x, radianceTextureUVNode.y.invert() );
+						radianceTextureUVNode = vec2( radianceTextureUVNode.x, radianceTextureUVNode.y.oneMinus() );
 
 					}
 
@@ -92,7 +92,7 @@ class EnvironmentNode extends LightingNode {
 						// @TODO: Needed PMREM
 
 						irradianceTextureUVNode = equirectUV( transformedNormalWorld );
-						irradianceTextureUVNode = vec2( irradianceTextureUVNode.x, irradianceTextureUVNode.y.invert() );
+						irradianceTextureUVNode = vec2( irradianceTextureUVNode.x, irradianceTextureUVNode.y.oneMinus() );
 
 					}
 

+ 1 - 1
examples/jsm/nodes/materials/MeshStandardNodeMaterial.js

@@ -71,7 +71,7 @@ class MeshStandardNodeMaterial extends NodeMaterial {
 
 		// DIFFUSE COLOR
 
-		stack.assign( diffuseColor, vec4( diffuseColor.rgb.mul( metalnessNode.invert() ), diffuseColor.a ) );
+		stack.assign( diffuseColor, vec4( diffuseColor.rgb.mul( metalnessNode.oneMinus() ), diffuseColor.a ) );
 
 	}
 

+ 4 - 4
examples/jsm/nodes/math/MathNode.js

@@ -104,7 +104,7 @@ class MathNode extends TempNode {
 
 			return builder.format( '-' + a.build( builder, inputType ), type, output );
 
-		} else if ( method === MathNode.INVERT ) {
+		} else if ( method === MathNode.ONE_MINUS ) {
 
 			return sub( 1.0, a ).build( builder, output );
 
@@ -213,7 +213,7 @@ MathNode.ABS = 'abs';
 MathNode.SIGN = 'sign';
 MathNode.LENGTH = 'length';
 MathNode.NEGATE = 'negate';
-MathNode.INVERT = 'invert';
+MathNode.ONE_MINUS = 'oneMinus';
 MathNode.DFDX = 'dFdx';
 MathNode.DFDY = 'dFdy';
 MathNode.ROUND = 'round';
@@ -269,7 +269,7 @@ export const abs = nodeProxy( MathNode, MathNode.ABS );
 export const sign = nodeProxy( MathNode, MathNode.SIGN );
 export const length = nodeProxy( MathNode, MathNode.LENGTH );
 export const negate = nodeProxy( MathNode, MathNode.NEGATE );
-export const invert = nodeProxy( MathNode, MathNode.INVERT );
+export const oneMinus = nodeProxy( MathNode, MathNode.ONE_MINUS );
 export const dFdx = nodeProxy( MathNode, MathNode.DFDX );
 export const dFdy = nodeProxy( MathNode, MathNode.DFDY );
 export const round = nodeProxy( MathNode, MathNode.ROUND );
@@ -323,7 +323,7 @@ addNodeElement( 'abs', abs );
 addNodeElement( 'sign', sign );
 addNodeElement( 'length', length );
 addNodeElement( 'negate', negate );
-addNodeElement( 'invert', invert );
+addNodeElement( 'oneMinus', oneMinus );
 addNodeElement( 'dFdx', dFdx );
 addNodeElement( 'dFdy', dFdy );
 addNodeElement( 'round', round );

+ 2 - 2
examples/jsm/renderers/webgpu/WebGPUBackground.js

@@ -1,6 +1,6 @@
 import { GPULoadOp, GPUStoreOp } from './constants.js';
 import { Color, Mesh, BoxGeometry, BackSide, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from 'three';
-import { context, vec2, invert, texture, cubeTexture, transformDirection, positionWorld, modelWorldMatrix, viewportBottomLeft, equirectUV, MeshBasicNodeMaterial } from 'three/nodes';
+import { context, vec2, oneMinus, texture, cubeTexture, transformDirection, positionWorld, modelWorldMatrix, viewportBottomLeft, equirectUV, MeshBasicNodeMaterial } from 'three/nodes';
 
 let _clearAlpha;
 const _clearColor = new Color();
@@ -69,7 +69,7 @@ class WebGPUBackground {
 						const dirNode = transformDirection( positionWorld, modelWorldMatrix );
 
 						nodeUV = equirectUV( dirNode );
-						nodeUV = vec2( nodeUV.x, invert( nodeUV.y ) );
+						nodeUV = vec2( nodeUV.x, oneMinus( nodeUV.y ) );
 
 					} else {
 

+ 1 - 1
examples/webgpu_depth_texture.html

@@ -61,7 +61,7 @@
 				// depth material
 
 				const material = new MeshBasicNodeMaterial();
-				material.colorNode = smoothstep( camera.near, camera.far, positionView.z.negate() ).invert();
+				material.colorNode = smoothstep( camera.near, camera.far, positionView.z.negate() ).oneMinus();
 
 				//
 

+ 2 - 2
examples/webgpu_particles.html

@@ -76,11 +76,11 @@
 
 				const life = lifeTime.div( lifeRange );
 
-				const fakeLightEffect = positionWorld.y.invert().max( 0.2 );
+				const fakeLightEffect = positionWorld.y.oneMinus().max( 0.2 );
 
 				const textureNode = texture( map, uv().rotateUV( timer.mul( rotateRange ) ) );
 
-				const opacityNode = textureNode.a.mul( life.invert() );
+				const opacityNode = textureNode.a.mul( life.oneMinus() );
 
 				const smokeColor = mix( color( 0x2c1501 ), color( 0x222222 ), positionWorld.y.mul( 3 ).clamp() );