
426 GPGPU Programming for Games and Science
Texture3D<float> poisson ;
RWTexture3D<float> outPoisson ;
[ numthreads (NUM
X THREADS , NUM Y THREADS , NUM Z THREADS ) ]
void CSMai n ( u int 3 c : S V
DispatchThreadID)
{
uint3 dim;
d i v e r g e nc e . G et Di m en s io n s ( dim . x , dim . y , dim . z ) ;
int x=int(c.x);
int y=int(c.y);
int z=int(c.z);
int xm = max ( x −1, 0 ) ;
int xp = min ( x +1, dim .x −1);
int ym = max ( y −1, 0 ) ;
int yp = min ( y +1, dim .y −1);
int zm = max ( z −1, 0 ) ;
int zp = min ( z +1, dim . z −1);
// Sa mple t h e d iv e r g e n ce a t ( x , y , z ) .
float div = divergence [ int3(x, y , z )];
// Sample Poisson values at (x ,y)