                     result += radiance_prd.result;
                 }
             }
+            nx = sqrt_num_samples;
         }
         result *= (Kd) / ((float)(M_PIf * sqrt_num_samples * sqrt_num_samples));
     }

        int nx = sqrt_num_samples;
        int ny = sqrt_num_samples;

        while(nx--){
            while(ny--){
                float u1 = (float(nx) + rnd(seed)) * inv_sqrt_samples;
                float u2 = (float(ny) + rnd(seed)) * inv_sqrt_samples;


}


RT_PROGRAM void vertex_camera(){
    float3 vertex_pos = vertices[launch_index.x].vertex;
    float3 vertex_normal = vertices[launch_index.x].normal;
    vertex_normal = normalize(vertex_normal);
    float3 result = make_float3(0);

    const float inv_sqrt_samples = 1.0f / (sqrt_num_samples);
    int nx = sqrt_num_samples;
    int ny = sqrt_num_samples;
    unsigned int seed = rot_seed( rnd_seeds[ launch_index ], frame );

    optix::Onb onb(vertex_normal);
    float3 Kd = make_float3(1.0, 1.0, 1.0);
    while(ny--){
        while(nx--){
            float u1 = (float(nx) + rnd( seed ) )*inv_sqrt_samples;
            float u2 = (float(ny) + rnd( seed ) )*inv_sqrt_samples;

            float3 dir;
            optix::cosine_sample_hemisphere(u1, u2, dir);
            onb.inverse_transform(dir);

            PerRayData_radiance radiance_prd;
            radiance_prd.importance = optix::luminance(Kd);
            radiance_prd.depth = 0;
            if(radiance_prd.importance > 0.001f) {
                optix::Ray radiance_ray = optix::make_Ray(hit_point, dir, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
                rtTrace(top_object, radiance_ray, radiance_prd);

                result += radiance_prd.result;
            }
            nx = sqrt_num_samples;
        }
    }

    result *= (Kd)/((float)(M_PIf*sqrt_diffuse_samples*sqrt_diffuse_samples));

    output_buffer[launch_index] = make_float4(result, 0.0f);
}





