unsigned int seed = tea<16>(screen.x*launch_index.y+launch_index.x, frame_number);

do {

unsigned int x = samples_per_pixel%sqrt_num_samples;

unsigned int y = samples_per_pixel/sqrt_num_samples;

float2 jitter = make_float2(x-rnd(seed), y-rnd(seed));

float2 d = pixel + jitter*jitter_scale;

float3 ray_origin = eye;

float3 ray_direction = normalize(d.x*U + d.y*V + W);

//1st Step : Eye-Path

unsigned int eyeDepth=0u;

float3 tmpres = pathtrace_camera(ray_origin,ray_direction,seed,eyeDepth);

//2nd Step : Light-Path

unsigned int lightDepth=0u;

tmpres = pathtrace_light(seed,lightDepth);

//3rd Step : Combination

float3 tmpColor=make_float3(0.0,0.0,0.0);

for(int light=0;light<lightDepth;light++)

{

for(int eye=0;eye<eyeDepth;eye++)

{

contrib=make_float3(1.0,1.0,1.0);

for(int i=0;i<light;i++)

{

uint3 lightIndex =make_uint3(launch_index,i);

contrib *= BDpathLight[lightIndex].contribution*BDpathLight[lightIndex].cosin*2.0*M_PIf;

}

contrib *= (BDconnection(light ,eye)*2.0*M_PIf*2.0*M_PIf);

for(int j=0;j<eye;j++)

{

uint3 eyeIndex =make_uint3(launch_index,j);

contrib *= BDpathEye[eyeIndex].contribution*BDpathEye[eyeIndex].cosin*2.0*M_PIf;

}

tmpColor+=contrib;

}

}

tmpColor/=(float)(lightDepth*eyeDepth);

color += tmpColor;

} while (--samples_per_pixel);

//combination

float3 pixel_color = color/(float)(sqrt_num_samples*sqrt_num_samples);

_______________________________________________________________________________