-
Notifications
You must be signed in to change notification settings - Fork 1
/
CK_01_Rolloff.dctl
69 lines (64 loc) · 2.1 KB
/
CK_01_Rolloff.dctl
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
66
67
68
69
/*
Smooth rolloff
*/
DEFINE_UI_PARAMS(p_max, Max, DCTLUI_SLIDER_FLOAT, 1.0f, 1.3f, 0.6f, 0.01f)
DEFINE_UI_PARAMS(p_max_r, Max Range, DCTLUI_SLIDER_FLOAT, 0.2f, 0.0f, 0.4f, 0.01f)
DEFINE_UI_PARAMS(p_min, Min, DCTLUI_SLIDER_FLOAT, 0.0f, -0.3f, 0.4f, 0.01f)
DEFINE_UI_PARAMS(p_min_r, Min Range, DCTLUI_SLIDER_FLOAT, 0.2f, 0.0f, 0.4f, 0.01f)
DEFINE_UI_PARAMS(p_depth, Depth, DCTLUI_SLIDER_FLOAT, 1.0f, 0.1f, 2.0f, 0.01f)
DEFINE_UI_PARAMS(p_bend, Tilt, DCTLUI_SLIDER_FLOAT, 0.0f, -0.5f, 0.5f, 0.01f)
__DEVICE__ inline float depth (float p, float t)
{
if (t != 1.0f)
return _powf(p, t);
else
return p;
}
__DEVICE__ inline float bend (float p, float t)
{
float adjust = 0.5f - 0.5f/_powf(1.5f, t);
if (t != 0.0f)
return p * 1.0f/_powf(p + 1.0f, t) + adjust;
else
return p;
}
__DEVICE__ inline float rolloff (float p, float max, float max_r)
{
if (p <= max - max_r)
return p;
else if (p >= max + max_r)
return max;
else
return -1/(4*max_r)*(p*p - 2*(max + max_r)*p + (max - max_r)*(max - max_r));
}
__DEVICE__ inline float split (float p, float max, float max_r, float min, float min_r, float t, float b)
{
float p2;
if (p >= 0.5f)
{
p2 = bend(p, b);
p2 = depth(p2, 1.0f/t);
p2 = rolloff(p2, max, max_r);
p2 = depth(p2, t);
}
else
{
p2 = bend(1.0f - p, b);
p2 = depth(p2, 1.0f/t);
p2 = rolloff(p2, 1.0f - min, min_r);
p2 = depth(p2, t);
p2 = 1.0f - p2;
}
return p2;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
float3 p = make_float3(
_tex2D(p_TexR, p_X, p_Y),
_tex2D(p_TexG, p_X, p_Y),
_tex2D(p_TexB, p_X, p_Y));
p.x = split(p.x, p_max, p_max_r, p_min, p_min_r, p_depth, p_bend);
p.y = split(p.y, p_max, p_max_r, p_min, p_min_r, p_depth, p_bend);
p.z = split(p.z, p_max, p_max_r, p_min, p_min_r, p_depth, p_bend);
return p;
}