Game Development Reference
In-Depth Information
inline __device__
float3 st_integrate_rk2( float2 p0, float sigma,
unsigned w, unsigned h,
float step_size, bool adaptive )
{
float radius = 2 * sigma;
float twoSigma2 = 2 * sigma * sigma;
float3 c= make_float3 ( tex2D (texSRC, p0.x, p0.y));
float sum = 1;
float2 v0 = st_minor_ev( tex2D (texST, p0.x, p0.y));
float sign = -1;
float dr = radius / CUDART_PI_F;
do {
float2 v = v0 * sign;
float2 p=p0;
float u=0;
for (;;) {
float2 t = st_minor_ev( tex2D (texST, p.x, p.y));
if ( dot (v,t)<0)t=-t;
float2 ph = p + 0.5f * step_size * t;
t = st_minor_ev( tex2D (texST, ph.x, ph.y));
float vt = dot (v, t);
if (vt < 0) {
t=-t;
vt = -vt;
}
v=t;
p += step_size * t;
if (adaptive) {
float delta_r = dr * acosf(fminf(vt,1));
u+= fmaxf (delta_r, step_size);
} else
u += step_size;
if ((u >= radius) || (p.x < 0) || (p.x >= w) ||
(p.y < 0) || (p.y >= h)) break ;
float k = __expf(-u*u/twoSigma2);
c+=k* make_float3 ( tex2D (texSRC, p.x, p.y));
sum += k;
}
sign *= -1;
} while (sign > 0);
return c / sum;
}
Listing 5.5. Implementation of the flow-guided smoothing using second-order Runge-
Kutta stream line integration.
comparatively noisy. In both cases, further extending it in the current direction
is undesirable. However, simply stopping the tracing process corresponds to
truncating the filtering operation and may introduce sampling artifacts. Instead,
 
 
Search Nedrilad ::




Custom Search