Exemple #1
0
static void
trace_pixel(ri_vector_t *radiance, int x, int y)
{
	unsigned char     type;
	double            bsdf[3];
	ri_ray_t          ray;
	ri_intersection_state_t state;
	pathnode_t        node;
	ri_vector_t       Le;
 
	/* first check a ray hits scene object through pixel (x, y) */
	ri_vector_copy(&ray.org, cam_pos);
	sample_pixel(&ray.dir, x, y);

	ray.thread_num = 0;

	if (!ri_raytrace(ri_render_get(), &ray, &state)) {
		/* hits background */
		ri_texture_ibl_fetch(radiance, light->texture, ray.dir);
		return;
	}

	node.depth = 2;
	node.G[0] = 1.0; node.G[1] = 1.0; node.G[2] = 1.0;
	ri_mem_copy(&node.state, &state, sizeof(ri_intersection_state_t));
	ri_vector_copy(&node.indir, ray.dir);
	// assume that the camera is not located in the transparent object
	node.interior = 0;

	trace_path(&node);

	/* connect the path to the IBL light source */
	type = sample_reflection_type(node.state.geom->material);

	//if (node.interior) printf("???\n");

	sample_outdir(&ray.dir, &type,
		      node.interior,
		      node.state.geom->material,
		      node.indir, node.state.Ng);

	brdf(bsdf,
	     type, &node.state,
	     node.indir, ray.dir, node.state.Ng);
	node.G[0] *= bsdf[0];
	node.G[1] *= bsdf[1];
	node.G[2] *= bsdf[2];

	ri_vector_copy(&ray.org, node.state.P);

	light_sample(&Le, ray.org, ray.dir);

	radiance->f[0] = Le.f[0] * node.G[0];
	radiance->f[1] = Le.f[1] * node.G[1];
	radiance->f[2] = Le.f[2] * node.G[2];
}
/**
 * Samples a snapshot from the camera to retrieve the line following error
 *
 * @param white_count The number of white pixels detected, updated by reference.
 * @return The line-following error in the image
 */
inline int sample_image(LineInfo &line)
{
    line = {false, false, false, false, 0, 0};

    int error = 0;
    take_picture();

    // Get pixels from across the entire image, not just one line
    for (int x = 0; x < IMAGE_SIZE_X; x += SAMPLE_STEPS) {
        for (int y = 0; y < IMAGE_SIZE_Y; y += SAMPLE_STEPS)
        {
            error += sample_pixel(line, x, y);
        }
    }
    return error;
}