forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonochromatic_Noise.dctl
77 lines (64 loc) · 1.81 KB
/
Monochromatic_Noise.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
// Monochromatic Noise DCTL
__CONSTANT__ int NOISE = 10; // 1 to 20 (rough to ultra-fine)
__CONSTANT__ int INTENSITY = 10; // Adjust contrast of noise (0 to 100)
__DEVICE__ float2 add(float2 A, float B)
{
float2 C;
C.x = A.x + B;
C.y = A.y + B;
return C;
}
__DEVICE__ float dot(float2 A, float2 B)
{
float C = A.x * B.x + A.y * B.y;
return C;
}
__DEVICE__ float fract(float A)
{
float B;
B = A - floor(A);
return B;
}
__DEVICE__ float nrand( float2 n )
{
return fract(_sinf(dot(n, make_float2(12.9898f, 78.233f))) * 43758.5453f);
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
float iTime = _tex2D(p_TexR, 500, 500);
p_Y = p_Height - p_Y;
float contrast = (float)INTENSITY * 0.1f;
float2 uv;
uv.x = (float)p_X / p_Width;
uv.y = (float)p_Y / p_Height;
float t = fract( iTime );
float nrnd[20];
nrnd[0] = nrand( add(uv, 0.07f * t) );
nrnd[1] = nrand( add(uv, 0.11f * t) );
nrnd[2] = nrand( add(uv, 0.13f * t) );
nrnd[3] = nrand( add(uv, 0.17f * t) );
nrnd[4] = nrand( add(uv, 0.19f * t) );
nrnd[5] = nrand( add(uv, 0.23f * t) );
nrnd[6] = nrand( add(uv, 0.29f * t) );
nrnd[7] = nrand( add(uv, 0.31f * t) );
nrnd[8] = nrand( add(uv, 0.37f * t) );
nrnd[9] = nrand( add(uv, 0.41f * t) );
nrnd[10] = nrand( add(uv, 0.43f * t) );
nrnd[11] = nrand( add(uv, 0.47f * t) );
nrnd[12] = nrand( add(uv, 0.53f * t) );
nrnd[13] = nrand( add(uv, 0.59f * t) );
nrnd[14] = nrand( add(uv, 0.61f * t) );
nrnd[15] = nrand( add(uv, 0.67f * t) );
nrnd[16] = nrand( add(uv, 0.71f * t) );
nrnd[17] = nrand( add(uv, 0.73f * t) );
nrnd[18] = nrand( add(uv, 0.79f * t) );
nrnd[19] = nrand( add(uv, 0.83f * t) );
float yo = 0.0f;
for(int N = 0; N < NOISE; N++)
{
yo += nrnd[N];
}
yo /= (float)NOISE;
yo = (yo - 0.5f) * contrast + 0.5f;
return make_float3(yo, yo, yo);
}