-
Notifications
You must be signed in to change notification settings - Fork 1
/
FP_Flood.cg
141 lines (133 loc) · 3.55 KB
/
FP_Flood.cg
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
/*
Guodong Rong
FP_Flood.cg
The fragment program for JFA
Copyright (c) 2005-2006
School of Computing
National University of Singapore
All Rights Reserved.
*/
void main(float4 position : WPOS,
float4 neighborCoord01 : TEXCOORD0,
float4 neighborCoord23 : TEXCOORD1,
float4 neighborCoord56 : TEXCOORD2,
float4 neighborCoord78 : TEXCOORD3,
out float4 oColor :COLOR,
uniform samplerRECT processedTex : TEXUNIT0)
{
float3 stored_coord, NearestCoord;
float2 vector;
float dist_2, min_dist_2;
min_dist_2 = 10000000;
// Compute a criterion value using the information of itself
stored_coord = texRECT(processedTex, position.xy).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor0
stored_coord = texRECT(processedTex, neighborCoord01.xy).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor1
stored_coord = texRECT(processedTex, neighborCoord01.zw).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor2
stored_coord = texRECT(processedTex, neighborCoord23.xy).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor3
stored_coord = texRECT(processedTex, neighborCoord23.zw).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor5
stored_coord = texRECT(processedTex, neighborCoord56.xy).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor6
stored_coord = texRECT(processedTex, neighborCoord56.zw).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor7
stored_coord = texRECT(processedTex, neighborCoord78.xy).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
// Compute a criterion value using the information of neighbor8
stored_coord = texRECT(processedTex, neighborCoord78.zw).rgb;
if (stored_coord.x>-1)
{
vector = position.xy-stored_coord.xy;
dist_2 = dot(vector, vector);
if (dist_2<min_dist_2)
{
min_dist_2 = dist_2;
NearestCoord = stored_coord;
}
}
if (min_dist_2==10000000)
discard;
oColor.rgb = NearestCoord;
} // main