Exemplo n.º 1
0
Radiance3 Raytracer::backwardTrace(const Ray& ray, int backwardBouncesLeft) const
{
	Color3 pixelColor;
	Tri::Intersector intersector;
	float distance = inf();

	// use tri tree
	if (_settings._useTriTree)
	{
		if (_triTree.intersectRay(ray, intersector, distance))
		{
			pixelColor = shadePixel(intersector, ray, backwardBouncesLeft);
		}
	}
	// or just go through array
	else
	{
		distance = inf();
		for (int i = 0; i < _triTree.size(); ++i)
		{
			intersector(ray, _triTree[i], distance);
			if (distance < inf())
			{
				pixelColor = shadePixel(intersector, ray, backwardBouncesLeft);
			}
		}
	}
	return pixelColor;
}
Exemplo n.º 2
0
void
RefRenderer::render() {

    // render all circles
    for (int circleIndex=0; circleIndex<numCircles; circleIndex++) {

        int index3 = 3 * circleIndex;

        float px = position[index3];
        float py = position[index3+1];
        float pz = position[index3+2];
        float rad = radius[circleIndex];

        // compute the bounding box of the circle.  This bounding box
        // is in normalized coordinates
        float minX = px - rad;
        float maxX = px + rad;
        float minY = py - rad;
        float maxY = py + rad;

        // convert normalized coordinate bounds to integer screen
        // pixel bounds.  Clamp to the edges of the screen.
        int screenMinX = CLAMP(static_cast<int>(minX * image->width), 0, image->width);
        int screenMaxX = CLAMP(static_cast<int>(maxX * image->width)+1, 0, image->width);
        int screenMinY = CLAMP(static_cast<int>(minY * image->height), 0, image->height);
        int screenMaxY = CLAMP(static_cast<int>(maxY * image->height)+1, 0, image->height);

        float invWidth = 1.f / image->width;
        float invHeight = 1.f / image->height;

        // for each pixel in the bounding box, determine the circle's
        // contribution to the pixel.  The contribution is computed in
        // the function shadePixel.  Since the circle does not fill
        // the bounding box entirely, not every pixel in the box will
        // receive contribution.
        for (int pixelY=screenMinY; pixelY<screenMaxY; pixelY++) {

            // pointer to pixel data
            float* imgPtr = &image->data[4 * (pixelY * image->width + screenMinX)];

            for (int pixelX=screenMinX; pixelX<screenMaxX; pixelX++) {

                // When "shading" the pixel ("shading" = computing the
                // circle's color and opacity at the pixel), we treat
                // the pixel as a point at the center of the pixel.
                // We'll compute the color of the circle at this
                // point.  Note that shading math will occur in the
                // normalized [0,1]^2 coordinate space, so we convert
                // the pixel center into this coordinate space prior
                // to calling shadePixel.
                float pixelCenterNormX = invWidth * (static_cast<float>(pixelX) + 0.5f);
                float pixelCenterNormY = invHeight * (static_cast<float>(pixelY) + 0.5f);
                shadePixel(circleIndex, pixelCenterNormX, pixelCenterNormY, px, py, pz, imgPtr);
                imgPtr += 4;
            }
        }
    }
}
Exemplo n.º 3
0
/*
  Loop through every pixel in the display and call shadePixel with its
  coordinates, its index and the current time vector.
*/
void run_shader(void){

    struct timeval tv;
    double t;
    while(1){
        gettimeofday(&tv, NULL);
        t = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
        for(y=0; y<8; y++){
            for(x=0; x<8; x++){
                int pixel = getPixelPosition(x,y);
                shadePixel(t, pixel, x/7.0, y/7.0);
            }
        }
        show();
        usleep(1);
    }

}