Browse Source

Nodes: Add SepiaNode (#28961)

* add SepiaNode

* add node to export

* fix

* condense sepia into tslFn

* remove SepiaNode from Node.js

* Update SepiaNode.js

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Christian Helgeson 1 year ago
parent
commit
76920df0a8
2 changed files with 22 additions and 0 deletions
  1. 1 0
      src/nodes/Nodes.js
  2. 21 0
      src/nodes/display/SepiaNode.js

+ 1 - 0
src/nodes/Nodes.js

@@ -141,6 +141,7 @@ export { default as BloomNode, bloom } from './display/BloomNode.js';
 export { default as TransitionNode, transition } from './display/TransitionNode.js';
 export { default as TransitionNode, transition } from './display/TransitionNode.js';
 export { default as RenderOutputNode, renderOutput } from './display/RenderOutputNode.js';
 export { default as RenderOutputNode, renderOutput } from './display/RenderOutputNode.js';
 export { default as PixelationPassNode, pixelationPass } from './display/PixelationPassNode.js';
 export { default as PixelationPassNode, pixelationPass } from './display/PixelationPassNode.js';
+export { sepia } from './display/SepiaNode.js';
 
 
 export { default as PassNode, pass, passTexture, depthPass } from './display/PassNode.js';
 export { default as PassNode, pass, passTexture, depthPass } from './display/PassNode.js';
 
 

+ 21 - 0
src/nodes/display/SepiaNode.js

@@ -0,0 +1,21 @@
+import { addNodeElement, tslFn, vec3, vec4 } from '../shadernode/ShaderNode.js';
+import { min } from '../math/MathNode.js';
+import { dot } from '../math/MathNode.js';
+
+import { property } from '../core/PropertyNode.js';
+
+export const sepia = /*@__PURE__*/ tslFn( ( { color } ) => {
+
+	const c = property( 'vec3', 'c' ).assign( color.rgb );
+
+	// https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/sepia.js
+
+	color.r = dot( c, vec3( 0.393, 0.769, 0.189 ) );
+	color.g = dot( c, vec3( 0.349, 0.686, 0.168 ) );
+	color.b = dot( c, vec3( 0.272, 0.534, 0.131 ) );
+
+	return vec4( min( vec3( 1.0 ), color.rgb ), 1.0 );
+
+} );
+
+addNodeElement( 'sepia', sepia );

粤ICP备19079148号