Skip to content

Commit

Permalink
BlendModes: Added blend* prefix (#29897)
Browse files Browse the repository at this point in the history
* Rename `BlendMode` -> `BlendModes`

* Added `blend` prefix

* update examples

* improve warning message

* rename `blendNormal` -> `blendColor`

* move 'blendColor' to Porter Duff formula
  • Loading branch information
sunag authored Nov 19, 2024
1 parent e0a7471 commit 405ad7b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 74 deletions.
4 changes: 2 additions & 2 deletions examples/webgpu_backdrop.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { float, vec3, color, viewportSharedTexture, hue, overlay, posterize, grayscale, saturation, viewportSafeUV, screenUV, checker, uv, time, oscSine, output } from 'three/tsl';
import { float, vec3, color, viewportSharedTexture, hue, blendOverlay, posterize, grayscale, saturation, viewportSafeUV, screenUV, checker, uv, time, oscSine, output } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand Down Expand Up @@ -106,7 +106,7 @@
addBackdropSphere( viewportSharedTexture().rgb.oneMinus() );
addBackdropSphere( grayscale( viewportSharedTexture().rgb ) );
addBackdropSphere( saturation( viewportSharedTexture().rgb, 10 ), oscSine() );
addBackdropSphere( overlay( viewportSharedTexture().rgb, checker( uv().mul( 10 ) ) ) );
addBackdropSphere( blendOverlay( viewportSharedTexture().rgb, checker( uv().mul( 10 ) ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( screenUV.mul( 40 ).floor().div( 40 ) ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( screenUV.mul( 80 ).floor().div( 80 ) ) ).add( color( 0x0033ff ) ) );
addBackdropSphere( vec3( 0, 0, viewportSharedTexture().b ) );
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_parallax_uv.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script type="module">

import * as THREE from 'three';
import { texture, parallaxUV, overlay, uv } from 'three/tsl';
import { texture, parallaxUV, blendOverlay, uv } from 'three/tsl';

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

Expand Down Expand Up @@ -89,7 +89,7 @@
const parallaxUVOffset = parallaxUV( uv(), offsetUV );
const parallaxResult = texture( bottomTexture, parallaxUVOffset );

const iceNode = overlay( texture( topTexture ), parallaxResult );
const iceNode = blendOverlay( texture( topTexture ), parallaxResult );

// material

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<script type="module">
import * as THREE from 'three';
import { pass, mrt, output, transformedNormalView, metalness, blendNormal, screenUV, color } from 'three/tsl';
import { pass, mrt, output, transformedNormalView, metalness, blendColor, screenUV, color } from 'three/tsl';
import { ssr } from 'three/addons/tsl/display/SSRNode.js';

import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
Expand Down Expand Up @@ -107,7 +107,7 @@

// blend SSR over beauty

const outputNode = blendNormal( scenePassColor, ssrPass );
const outputNode = blendColor( scenePassColor, ssrPass );

postProcessing.outputNode = outputNode;

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export * from './accessors/UserDataNode.js';
export * from './accessors/VelocityNode.js';

// display
export * from './display/BlendMode.js';
export * from './display/BlendModes.js';
export * from './display/BumpMapNode.js';
export * from './display/ColorAdjustment.js';
export * from './display/ColorSpaceNode.js';
Expand Down
67 changes: 0 additions & 67 deletions src/nodes/display/BlendMode.js

This file was deleted.

99 changes: 99 additions & 0 deletions src/nodes/display/BlendModes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Fn, vec4 } from '../tsl/TSLBase.js';
import { mix, min, step } from '../math/MathNode.js';

export const blendBurn = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {

return min( 1.0, base.oneMinus().div( blend ) ).oneMinus();

} ).setLayout( {
name: 'blendBurn',
type: 'vec3',
inputs: [
{ name: 'base', type: 'vec3' },
{ name: 'blend', type: 'vec3' }
]
} );

export const blendDodge = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {

return min( base.div( blend.oneMinus() ), 1.0 );

} ).setLayout( {
name: 'blendDodge',
type: 'vec3',
inputs: [
{ name: 'base', type: 'vec3' },
{ name: 'blend', type: 'vec3' }
]
} );

export const blendScreen = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {

return base.oneMinus().mul( blend.oneMinus() ).oneMinus();

} ).setLayout( {
name: 'blendScreen',
type: 'vec3',
inputs: [
{ name: 'base', type: 'vec3' },
{ name: 'blend', type: 'vec3' }
]
} );

export const blendOverlay = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {

return mix( base.mul( 2.0 ).mul( blend ), base.oneMinus().mul( 2.0 ).mul( blend.oneMinus() ).oneMinus(), step( 0.5, base ) );

} ).setLayout( {
name: 'blendOverlay',
type: 'vec3',
inputs: [
{ name: 'base', type: 'vec3' },
{ name: 'blend', type: 'vec3' }
]
} );

export const blendColor = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {

const outAlpha = blend.a.add( base.a.mul( blend.a.oneMinus() ) );

return vec4( blend.rgb.mul( blend.a ).add( base.rgb.mul( base.a ).mul( blend.a.oneMinus() ) ).div( outAlpha ), outAlpha );

} ).setLayout( {
name: 'blendColor',
type: 'vec4',
inputs: [
{ name: 'base', type: 'vec4' },
{ name: 'blend', type: 'vec4' }
]
} );

// deprecated

export const burn = ( ...params ) => { // @deprecated, r171

console.warn( 'THREE.TSL: "burn" has been renamed. Use "blendBurn" instead.' );
return blendBurn( params );

};

export const dodge = ( ...params ) => { // @deprecated, r171

console.warn( 'THREE.TSL: "dodge" has been renamed. Use "blendDodge" instead.' );
return blendDodge( params );

};

export const screen = ( ...params ) => { // @deprecated, r171

console.warn( 'THREE.TSL: "screen" has been renamed. Use "blendScreen" instead.' );
return blendScreen( params );

};

export const overlay = ( ...params ) => { // @deprecated, r171

console.warn( 'THREE.TSL: "overlay" has been renamed. Use "blendOverlay" instead.' );
return blendOverlay( params );

};

0 comments on commit 405ad7b

Please sign in to comment.