forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatcap.osl
57 lines (54 loc) · 2.19 KB
/
Matcap.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
48
49
50
51
52
53
54
55
56
57
// Matcap shader for Redshift 3d by Darby Edelen
// This file is licensed under Apache 2.0 license
shader Matcap
[[ string help = "Matcap NPR Shader",
string label = "Matcap" ]]
(
string fileName="" [[string label="Texture", string widget="filename"]],
float gamma=2.2 [[string label="Gamma", float slidercenter=2.2, float min=0.1, float max=10]],
int mapSpace=0 [[string label="Space",
string widget="mapper",
string options="Screen:0|Camera:1|World:2"]],
float scale=1 [[string label="Scale",
string page="Transform",
int slider=1,
int digits=3,
float slidermin=0,
float slidermax=2]],
float scaleU=1 [[string label="Scale U",
string page="Transform",
int slider=1,
int digits=3,
float slidermin=0,
float slidermax=2]],
float scaleV=1 [[string label="Scale V",
string page="Transform",
int slider=1,
int digits=3,
float slidermin=0,
float slidermax=2]],
float rot=0 [[string label="Rotation",
string page="Transform",
int slider=1,
int digits=5,
float slidermin=0,
float slidermax=360,
string units="degrees"]],
output color outColor=0
)
{
float rsin = 0;
float rcos = 1;
sincos(radians(rot), rsin, rcos);
vector svec = max(vector(scale*scaleU,scale*scaleV,1), vector(0.001));
normal uvOut = transform("camera", N);
if(mapSpace==2) uvOut = N;
uvOut = vector(uvOut.x * rcos - uvOut.y * rsin, uvOut.x * rsin + uvOut.y * rcos, uvOut.z);
if(mapSpace==0){
normal v = transform("camera", I);
uvOut = normalize(vector(dot(vector(-v.z,v.y,v.x), -uvOut), dot(vector(v.x,-v.z,v.y), -uvOut), dot(v, uvOut)));
}
uvOut = (uvOut/svec + 1.0) / 2.0;
color Cout = texture(fileName, uvOut.x, -uvOut.y);
outColor = pow(Cout, gamma);
}