forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArri_Lut_Grain.dctl
122 lines (96 loc) · 3.2 KB
/
Arri_Lut_Grain.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Arri to Rec709 plus Grain DCTL
#define ADD_GRAIN
//#define RGB_GRAIN
#define INTENSITY 12
__CONSTANT__ float3 AWG_Rec709[3] = { {1.617523f, -0.537287f, -0.080237f},
{-0.070573f, 1.334613f, -0.26404f},
{-0.021102f, -0.226954f, 1.248056f} };
__CONSTANT__ float3 AWG_T_Rec709[3] = { {1.485007f, -0.401216f, -0.083791f},
{-0.033732f, 1.282887f, -0.249155f},
{0.010776f, -0.122018f, 1.111242f } };
__DEVICE__ float fract(float A)
{
float B;
B = A - _floor(A);
return B;
}
__DEVICE__ float3 multi(float3 In, float3 A[3])
{
float3 out;
out.x = In.x * A[0].x + In.y * A[0].y + In.z * A[0].z;
out.y = In.x * A[1].x + In.y * A[1].y + In.z * A[1].z;
out.z = In.x * A[2].x + In.y * A[2].y + In.z * A[2].z;
return out;
}
__DEVICE__ float logcLin(float logVal)
{
return logVal > 0.1496582f ? (_powf(10.0f, (logVal - 0.385537f) / 0.2471896f) - 0.052272f) / 5.555556f : (logVal - 0.092809f) / 5.367655f;
}
__DEVICE__ float3 logcLin(float3 logVal)
{
return make_float3(logcLin(logVal.x), logcLin(logVal.y), logcLin(logVal.z));
}
__DEVICE__ float linLogc(float linVal)
{
return linVal > 0.010591f ? 0.247190f * _log10f(5.555556f * linVal + 0.052272f) + 0.385537f : 5.367655f * linVal + 0.092809f;
}
__DEVICE__ float3 linLogc(float3 linVal)
{
return make_float3(linLogc(linVal.x), linLogc(linVal.y), linLogc(linVal.z));
}
__DEVICE__ float arriLut(float logVal)
{
return -0.00028934f + 0.6892 * logVal - 4.6071f * _powf(logVal, 2.0f) + 27.4005f * _powf(logVal, 3.0f) -
44.5964f * _powf(logVal, 4.0f) + 27.6967f * _powf(logVal, 5.0f) - 5.5825f * _powf(logVal, 6.0f);
}
__DEVICE__ float3 arriLut(float3 logVal)
{
return make_float3(arriLut(logVal.x), arriLut(logVal.y), arriLut(logVal.z));
}
__DEVICE__ float softLight(float col, float grain)
{
return grain < 0.5f ? 2.0f * col * grain + (col * col) * (1.0f - 2.0f * grain) : 2.0f * col * (1.0f - grain) + _sqrtf(col) * (2.0f * grain - 1.0f);
}
__DEVICE__ float rand(float x)
{
return fract(_sinf(x) * 100000.0f);
}
__DEVICE__ float intensity(float grain, float contrast)
{
return (grain - 0.5f) * contrast + 0.5f;
}
__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 col = make_float3(_tex2D(p_TexR, p_X, p_Y), _tex2D(p_TexG, p_X, p_Y), _tex2D(p_TexB, p_X, p_Y));
col = logcLin(col);
col = multi(col, AWG_Rec709);
col = linLogc(col);
#ifdef ADD_GRAIN
float contrast = (float)INTENSITY * 0.01f;
float iTime = _tex2D(p_TexR, 500, 500) * 20.0f;
float X = (float)p_X + 1.0f;
float Y = (float)(p_Height - p_Y) + 1.0f;
float2 resolution = make_float2((float)p_Width, (float)p_Height);
float2 position = make_float2(X/resolution.x, Y/resolution.y);
float x = position.x * position.y * 100000.0f + iTime;
float f = fract(x);
float i = _floor(x);
x *= 100.0f;
float3 grain;
grain.x = rand(x);
grain.x = intensity(grain.x, contrast);
#ifdef RGB_GRAIN
grain.y = rand(x * iTime);
grain.y = intensity(grain.y, contrast);
grain.z = rand(x + iTime);
grain.z = intensity(grain.z, contrast);
#else
grain.z = grain.y = grain.x;
#endif
col.x = softLight(col.x, grain.x);
col.y = softLight(col.y, grain.y);
col.z = softLight(col.z, grain.z);
#endif
col = arriLut(col);
return col;
}