Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlendModes: Added blend* prefix #29897

Merged
merged 6 commits into from
Nov 19, 2024
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
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 @@ -83,7 +83,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 );

};