/
Clone_Stamp_FS_OFX.dctl
247 lines (195 loc) · 7.72 KB
/
Clone_Stamp_FS_OFX.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Clone Stamp Frequency Separation OFX DCTL
DEFINE_UI_PARAMS(size, Size, DCTLUI_SLIDER_FLOAT, 0.3, 0, 1, 0.001)
DEFINE_UI_PARAMS(softness, Softness, DCTLUI_SLIDER_FLOAT, 0, 0, 1, 0.001)
DEFINE_UI_PARAMS(interpolation, Interpolation, DCTLUI_SLIDER_INT, 0, 0, 2, 1)
DEFINE_UI_PARAMS(srcPosX, Source Position X, DCTLUI_SLIDER_FLOAT, 0.5, 0, 1, 0.001)
DEFINE_UI_PARAMS(srcPosY, Source Position Y, DCTLUI_SLIDER_FLOAT, 0.5, 0, 1, 0.001)
DEFINE_UI_PARAMS(aspectRatio, AspectRatio, DCTLUI_SLIDER_FLOAT, 1, 0, 2, 0.001)
DEFINE_UI_PARAMS(destPosX, Destination Position X, DCTLUI_SLIDER_FLOAT, 0.5, 0, 1, 0.001)
DEFINE_UI_PARAMS(destPosY, Destination Position Y, DCTLUI_SLIDER_FLOAT, 0.5, 0, 1, 0.001)
DEFINE_UI_PARAMS(blendOpacity, FS Blend, DCTLUI_SLIDER_FLOAT, 1, 0, 1, 0.001)
DEFINE_UI_PARAMS(SHARPEN, Sharpen, DCTLUI_SLIDER_FLOAT, 0, 0, 1, 0.001)
DEFINE_UI_PARAMS(BLUR, Blur, DCTLUI_SLIDER_FLOAT, 0, 0, 1, 0.001)
DEFINE_UI_PARAMS(SCALE, Gain, DCTLUI_SLIDER_FLOAT, 1, 0, 2, 0.001)
DEFINE_UI_PARAMS(shape, Rectangle, DCTLUI_CHECK_BOX, 0)
#define PI 3.14159265f
#define PI_AREA 1.27323954f
__DEVICE__ float Size = 0;
__DEVICE__ float Softness = 0;
__DEVICE__ int Interpolation = 0; // 0 = Linear, 1 = Square, 2 = Sinusoidal
__DEVICE__ float SrcPosX = 0;
__DEVICE__ float SrcPosY = 0;
__DEVICE__ float AspectRatio = 0;
__DEVICE__ float DestPosX = 0;
__DEVICE__ float DestPosY = 0;
__DEVICE__ float BlendOpacity = 0;
__DEVICE__ float Sharpen = 0;
__DEVICE__ float Blur = 0;
__DEVICE__ float Scale = 0;
__DEVICE__ bool Shape = true; // true = Rectangle, false = Ellipse
__DEVICE__ float mean(float p_Table[], int m)
{
float temp = 0.0f;
for(int i = 0; i < m; ++i) {
temp += p_Table[i]; }
return (temp / m);
}
__DEVICE__ float3 mean3(__TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB, int p_X, int p_Y)
{
const int length = 3;
const int area = length * length;
float colRGB[3];
float TableR[area], TableG[area], TableB[area];
for (int i = 0; i < area; ++i) {
int offset = (length - 1) / 2;
int xx = (i >= length ? _fmod(i, length/1.0f) : i) - offset;
int yy = _floor(i / (length/1.0f)) - offset;
TableR[i] = _tex2D(p_TexR, p_X + xx, p_Y + yy);
TableG[i] = _tex2D(p_TexG, p_X + xx, p_Y + yy);
TableB[i] = _tex2D(p_TexB, p_X + xx, p_Y + yy);
}
for (int c = 0; c < 3; ++c) {
colRGB[c] = c == 0 ? mean(TableR, area) : c == 1 ? mean(TableG, area) : mean(TableB, area);
}
return make_float3(colRGB[0], colRGB[1], colRGB[2]);
}
__DEVICE__ float3 mean5(__TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB, int p_X, int p_Y)
{
const int length = 5;
const int area = length * length;
float colRGB[3];
float TableR[area], TableG[area], TableB[area];
for (int i = 0; i < area; ++i) {
int offset = (length - 1) / 2;
int xx = (i >= length ? _fmod(i, length/1.0f) : i) - offset;
int yy = _floor(i / (length/1.0f)) - offset;
TableR[i] = _tex2D(p_TexR, p_X + xx, p_Y + yy);
TableG[i] = _tex2D(p_TexG, p_X + xx, p_Y + yy);
TableB[i] = _tex2D(p_TexB, p_X + xx, p_Y + yy);
}
for (int c = 0; c < 3; ++c) {
colRGB[c] = c == 0 ? mean(TableR, area) : c == 1 ? mean(TableG, area) : mean(TableB, area);
}
return make_float3(colRGB[0], colRGB[1], colRGB[2]);
}
__DEVICE__ float3 mean9(__TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB, int p_X, int p_Y)
{
const int length = 9;
const int area = length * length;
float colRGB[3];
float TableR[area], TableG[area], TableB[area];
for (int i = 0; i < area; ++i) {
int offset = (length - 1) / 2;
int xx = (i >= length ? _fmod(i, length/1.0f) : i) - offset;
int yy = _floor(i / (length/1.0f)) - offset;
TableR[i] = _tex2D(p_TexR, p_X + xx, p_Y + yy);
TableG[i] = _tex2D(p_TexG, p_X + xx, p_Y + yy);
TableB[i] = _tex2D(p_TexB, p_X + xx, p_Y + yy);
}
for (int c = 0; c < 3; ++c) {
colRGB[c] = c == 0 ? mean(TableR, area) : c == 1 ? mean(TableG, area) : mean(TableB, area);
}
return make_float3(colRGB[0], colRGB[1], colRGB[2]);
}
__DEVICE__ float distance(float2 AB, float2 CD)
{
float square_difference_x = (CD.x - AB.x) * (CD.x - AB.x);
float square_difference_y = (CD.y - AB.y) * (CD.y - AB.y);
float sum = square_difference_x + square_difference_y;
float value = _sqrtf(sum);
return value;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
Size = size;
Softness = softness;
Interpolation = interpolation;
SrcPosX = srcPosX;
SrcPosY = srcPosY;;
AspectRatio = aspectRatio;
DestPosX = destPosX;
DestPosY = destPosY;
BlendOpacity = blendOpacity;
Sharpen = SHARPEN + 1.0f;
Blur = BLUR;
Scale = SCALE;
Shape = shape;
float r = _tex2D(p_TexR, p_X, p_Y);
float g = _tex2D(p_TexG, p_X, p_Y);
float b = _tex2D(p_TexB, p_X, p_Y);
float3 Src = make_float3(r, g, b);
float width = (float)p_Width;
float height = (float)p_Height;
float2 uv = make_float2(p_X/width, p_Y/height);
float _OutputAspectRatio = width/height;
float CircleSize = Size * PI_AREA;
float2 DestPos = make_float2(DestPosX, 1.0f - DestPosY);
float2 DestAspectAdjustedPos = ((uv - DestPos) / (make_float2(AspectRatio, _OutputAspectRatio) * CircleSize)) + DestPos;
float2 DestSize = make_float2(AspectRatio, _OutputAspectRatio) * Size;
float DestDelta = distance(DestAspectAdjustedPos, DestPos);
float Soft = 0.0f;
if(Shape)
{
float2 SoftSize = DestSize * (1.0 - Softness);
float2 BoxMin = DestPos - DestSize / 2.0f;
float2 BoxMax = BoxMin + DestSize;
if ( ((uv.x - BoxMin.x < 0) || (uv.y - BoxMin.y < 0)) || ((uv.x - BoxMax.x > 0) || (uv.y - BoxMax.y > 0)) ) return Src;
float2 SoftMin = DestPos - SoftSize / 2.0f;
float2 SoftMax = SoftMin + SoftSize;
float2 RangeMin = (uv - SoftMin) / (BoxMin - SoftMin);
float2 RangeMax = (uv - SoftMax) / (BoxMax - SoftMax);
if (Interpolation == 1) {
RangeMin.x = 1.0f - _powf((1.0f - _powf(RangeMin.x, 2.0f)), 0.5f);
RangeMin.y = 1.0f - _powf((1.0f - _powf(RangeMin.y, 2.0f)), 0.5f);
RangeMax.x = 1.0f - _powf((1.0f - _powf(RangeMax.x, 2.0f)), 0.5f);
RangeMax.y = 1.0f - _powf((1.0f - _powf(RangeMax.y, 2.0f)), 0.5f);
}
else if (Interpolation == 2) {
RangeMin.x = 0.5f - (_cosf(RangeMin.x * PI) / 2.0f);
RangeMin.y = 0.5f - (_cosf(RangeMin.y * PI) / 2.0f);
RangeMax.x = 0.5f - (_cosf(RangeMax.x * PI) / 2.0f);
RangeMax.y = 0.5f - (_cosf(RangeMax.y * PI) / 2.0f);
}
RangeMin = 1.0f - RangeMin;
RangeMax = 1.0f - RangeMax;
float Soft_1 = ((uv.x >= BoxMin.x) && (uv.x <= SoftMin.x)) ? RangeMin.x : 1.0f;
float Soft_2 = ((uv.y >= BoxMin.y) && (uv.y <= SoftMin.y)) ? RangeMin.y : 1.0f;
if ((uv.x <= BoxMax.x) && (uv.x >= SoftMax.x)) Soft_1 = _fminf(Soft_1, RangeMax.x);
if ((uv.y <= BoxMax.y) && (uv.y >= SoftMax.y)) Soft_2 = _fminf(Soft_2, RangeMax.y);
Soft = 1.0f - _saturatef(_fminf(Soft_1, Soft_2) * Soft_1 * Soft_2);
} else {
if (CircleSize <= DestDelta) return Src;
float SoftRadius = CircleSize * (1.0f - Softness);
float SoftRing = DestDelta - SoftRadius;
if (SoftRing >= 0.0f) {
SoftRing /= (CircleSize - SoftRadius);
Soft = (Interpolation == 0) ? SoftRing
: (Interpolation == 1) ? 1.0f - _powf(1.0f - _powf(SoftRing, 2.0f), 0.5f)
: 0.5f - (_cosf(SoftRing * PI) / 2.0f);
}
}
float2 xy = uv + make_float2(SrcPosX, DestPosY) - make_float2(DestPosX, SrcPosY);
int XX = (int)(xy.x * width);
int YY = (int)(xy.y * height);
float3 Dest;
Dest.x = _tex2D(p_TexR, XX, YY);
Dest.y = _tex2D(p_TexG, XX, YY);
Dest.z = _tex2D(p_TexB, XX, YY);
if(Blur > 0 || Sharpen > 1)
{
float3 preFS = Dest;
float3 blurA = mean5(p_TexR, p_TexG, p_TexB, XX, YY);
Dest = Dest - blurA;
if(Sharpen > 1) Dest = Dest * Sharpen;
if(Blur > 0)
{
float3 blurB = mean9(p_TexR, p_TexG, p_TexB, XX, YY);
blurA = blurB * Blur + blurA * (1.0f - Blur);
}
Dest = Dest + blurA;
Dest = lerp(preFS, Dest, BlendOpacity);
}
Dest = Dest * Scale;
Dest = lerp(Dest, Src, Soft);
return Dest;
}