Ejemplo n.º 1
0
void Camera::RenderPath(Scene &scn, int n) {
    RayTrace rayTrace(scn);
    
    for (int y = 0; y < _img.YRes; y++) {
        for (int x = 0; x < _img.XRes; x++) {
            
            // compute the primary ray
            Vector3 cy;
            cy.Cross(_worldMatrix.c, _worldMatrix.b);
            Vector3 cx = cy / pow(cy.Magnitude(), 2);
            cy.Cross(cx, _worldMatrix.c);
            
            float hfov = 2.f * atanf(_aspect * tanf(_verticalFOV / 2.f));
            float cw = 2.f * tanf(hfov/2.f);
            float ch = cw / _aspect;
            
            Ray ray;
            ray.Origin = _worldMatrix.d;
            
            ray.Direction =
            _worldMatrix.c + ((float)(x + 0.5f) / (float)_img.XRes - 0.5f) * cw * cx +
            ((float)(y + 0.5f)/(float)_img.YRes - 0.5f) * ch * cy;
            
            ray.type = Ray::PRIMARY;
            
            // shoot the primary ray
            Intersection hit;
            if (x > 124 && x <= 140 && y == _img.YRes - 495 ) {
//                Color white = Color::WHITE;
//                std::cout << "debug pixel" << std::endl;
//                _img.SetPixel(x, y, white.ToInt());
//                continue;
            }
            
            rayTrace.TraceRay(ray, hit);
            
            if (n != -1) {
                Color c;
                c.FromInt(_img.GetPixel(x, y));
                
                Color avg = Color::BLACK;
                avg.AddScaled(c, n - 1);
                avg.Add(hit.Shade);
                avg.Scale(1.0f / n);
                _img.SetPixel(x, y, avg.ToInt());
            }
            else _img.SetPixel(x, y, hit.Shade.ToInt());
        }
    }
    
}
Ejemplo n.º 2
0
int main(int argc,char **argv) {
    if (FILE_SEP == 0) fSEP = "\\";
    APP_PATH = argv[0];
    
    string::size_type i = APP_PATH.find_last_of(fSEP);
    if (i != string::npos) APP_PATH.erase(i+1);
    
    if (argc < 2 || argc > 5) {
        usage();
    }
    
    // Create scene
    int color;
    int xSize = 80;
    int ySize = 60;
    Scene scn;
    
    // used photoshop color spectrum to select colors
    Color c = Color::BLACK;
    
    if (strcmp(argv[1], "cloud") == 0) {
        CloudTexture cloud = CloudTexture();
        c.FromInt(0xCCE5FF);
        scn.setTexture(&cloud);
    } else if (strcmp(argv[1], "wood") == 0) {
        c.FromInt(0x7906131);
        WoodTexture wood = WoodTexture();
        scn.setTexture(&wood);
    } else if (strcmp(argv[1], "marble") == 0) {
        c.FromInt(0xb2daed);
        MarbleTexture marble = MarbleTexture(40.0f);
        scn.setTexture(&marble);
    } else if (strcmp(argv[1], "lava") == 0) {
        c.FromInt(0x8e1b1b);
        CellTexture latex = CellTexture(10.0f, 5550, WorleyNoise::MANHATTAN, WorleyNoise::D3);
        scn.setTexture(&latex);
    } else if (strcmp(argv[1], "cell") == 0) {
        c.FromInt(0xc99968);
        CellTexture gro = CellTexture(1.0f, 1305, WorleyNoise::EUCLIDIAN, WorleyNoise::D1);
        scn.setTexture(&gro);
    } else {
        usage();
    }
    
    if (argc == 3) {
        color = checkColor(argv[2]);
        c.FromInt( color );
    } else if (argc == 4) {
        xSize = checkSize(argv[2]);
        ySize = checkSize(argv[3]);
    } else if (argc == 5) {
        color = checkColor(argv[2]);
        c.FromInt( color );
        xSize = checkSize(argv[3]);
        ySize = checkSize(argv[4]);
    }
    scn.setColor(c);
    
    //Render image
    scn.SetResolution(xSize,ySize);
    scn.Render();
    concat = APP_PATH + "texture.bmp";
    scn.SaveBitmap(concat.c_str());
    
}