forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPosterizeNode.js
65 lines (49 loc) · 1.41 KB
/
PosterizeNode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import TempNode from '../core/TempNode.js';
import { nodeProxy } from '../tsl/TSLBase.js';
/**
* Represents a posterize effect which reduces the number of colors
* in an image, resulting in a more blocky and stylized appearance.
*
* @augments TempNode
*/
class PosterizeNode extends TempNode {
static get type() {
return 'PosterizeNode';
}
/**
* Constructs a new posterize node.
*
* @param {Node} sourceNode - The input color.
* @param {Node} stepsNode - Controls the intensity of the posterization effect. A lower number results in a more blocky appearance.
*/
constructor( sourceNode, stepsNode ) {
super();
/**
* The input color.
*
* @type {Node}
*/
this.sourceNode = sourceNode;
/**
* Controls the intensity of the posterization effect. A lower number results in a more blocky appearance.
*
* @type {Node}
*/
this.stepsNode = stepsNode;
}
setup() {
const { sourceNode, stepsNode } = this;
return sourceNode.mul( stepsNode ).floor().div( stepsNode );
}
}
export default PosterizeNode;
/**
* TSL function for creating a posterize node.
*
* @tsl
* @function
* @param {Node} sourceNode - The input color.
* @param {Node} stepsNode - Controls the intensity of the posterization effect. A lower number results in a more blocky appearance.
* @returns {PosterizeNode}
*/
export const posterize = /*@__PURE__*/ nodeProxy( PosterizeNode ).setParameterLength( 2 );