forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnvironmentGradient.osl
60 lines (54 loc) · 1.64 KB
/
EnvironmentGradient.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
58
59
60
// environment_gradient - Various ways to drive an environment gradient ramp
// Michael Abrahams, 3/23/2021
// MIT license
shader env_gradient
[[ string help = "Spherical Gradient for Redshift Environment Mapping",
string label = "Environment Gradient" ]]
(
int gradient_type = 0
[[ string label= "Gradient type",
string widget = "mapper",
string options = "World (Linear):0|World (Polar Angle):1|Camera Space:2" ]],
int out_dimension = 0
[[ string label= "Output coordinate",
string widget = "mapper",
string options = "V:0|U:1" ]],
int zUpAxis = 0 [[ string widget = "checkBox", string label = "Z is Up" ]],
output float out = 0.0,
output vector outUV = 0.0
)
{
float outU;
float outV;
float incline;
float azimuth;
vector shadingI = I;
if (zUpAxis) {
shadingI = vector(I.x,I.z,I.y);
}
// World (linear/cylindrical)
if (gradient_type == 0) {
outUV.y = shadingI.y / 2.0 + 0.5;
azimuth = atan(shadingI.z / shadingI.x);
outUV.x = azimuth / M_PI + 0.5;
}
// World (Polar angle)
if (gradient_type == 1) {
incline = acos(shadingI.y);
outUV.y = 1.0 - incline / M_PI;
azimuth = atan(shadingI.z / shadingI.x);
outUV.x = azimuth / M_PI + 0.5;
}
// Screen space
if (gradient_type == 2) {
vector shadingP = transform("NDC", P);
outUV.x = shadingP.x;
outUV.y = shadingP.y;
}
if (out_dimension == 0) {
out = outUV.y;
}
else {
out = outUV.x;
}
}