forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Posterize.osl
47 lines (39 loc) · 900 Bytes
/
Posterize.osl
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
/*
* Posterise.osl by Charlie (c)2012
* from https://github.com/sambler/osl-shaders
*
* license: public domain
*
* original script from -
* http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness/page5
* Modified 1/4/2020 by Saul Espinosa for Redshift 3D
*/
shader posterise
[[ string help = "Posterize Filter Effect",
string label = "Posterize" ]]
(
int Range = 8
[[
int min = 0, int max = 50
]],
color Color = 1
[[
string label = "Input"
]],
output color Output = 0 )
{
float posterise(float Value){
if( Range > 1 ) {
return floor(Value * Range) / (Range-1);
}
else if(Range == 1) {
return 0;
}
else {
return Value;
}
}
Output[0] = posterise(Color[0]);
Output[1] = posterise(Color[1]);
Output[2] = posterise(Color[2]);
}