0,引入
想象这么一个场景:
海边有一个古老的凉亭。雕刻着古时壁画的屋檐;砂岩的地板;亭内摆放着一个木质的茶桌;茶桌上摆着大理石的茶杯和茶壶;紧挨着茶桌有一个圆形的坐垫;小白兔和小灰兔静静地蹲坐在地板上;凉亭向外是一个大理石的台阶;台阶向外是一个铺着被海水侵蚀过的青石“广场”;马驹在广场上悠然漫步;广场向外就是淡蓝色的大海;海面上飘着一艘木船;大海无际,视线最远处的海面和天空相接;早晨或者傍晚,天空的云映在海面上……
贴图如下:
1,测试代码
接下来,贴出World::build()的代码,完整代码参考后面的下载链接。
#include "World.h"
#include "Ambient.h"
#include "Pinhole.h"
#include "Directional.h"
#include "PointLight.h"
#include "RayCast.h"
#include "Whitted.h"
#include "Matte.h"
#include "Plane.h"
#include "Phong.h"
#include "MultiJittered.h"
#include "AmbientOccluder.h"
#include "Emissive.h"
#include "AreaLight.h"
#include "Rectangle.h"
#include "AreaLighting.h"
#include "Instance.h"
#include "Disk.h"
#include "Grid.h"
#include "CubicNoise.h"
#include "Image.h"
#include "FBmTextureRamp.h"
#include "InstanceTexture.h"
#include "SV_Matte.h"
#include "SV_Phong.h"
#include "Wood.h"
#include "Checker3D.h"
#include "Dielectric.h"
#include "Annulus.h"
#include "TorusPartConvex.h"
#include "SphericalMap.h"
#include "Image.h"
#include "ImageTexture.h"
#include "OpenCylinder.h"
#include "Reflective.h"
#include "SolidCylinder.h"
#include "SolidCylinderChecker.h"
#include "PlaneChecker.h"
#include "SV_Reflective.h"
#include "SV_GlossyReflector.h"
#include "SpherePartConcave.h"
#include "SpherePartConvex.h"
#include "FBmTextureWrapped.h"
#include <iostream>
#include <fstream>
using namespace std;
void
World::build(void){
int num_samples = 100;
int a = 1;
vp.set_hres(600/a); // 600*500
vp.set_vres(500/a);
vp.set_samples(num_samples);
vp.set_max_depth(4);
// tracer_ptr = new RayCast(this);
tracer_ptr = new Whitted(this);
Pinhole* pinhole_ptr = new Pinhole;
pinhole_ptr->set_eye(0, 1.2, -1.7);
pinhole_ptr->set_lookat(0, 0.5, -20);
pinhole_ptr->set_view_distance(300/a); // 3600
pinhole_ptr->compute_uvw();
set_camera(pinhole_ptr);
PointLight* point_light_ptr1 = new PointLight;
point_light_ptr1->set_location(0, 3, 0);
point_light_ptr1->scale_radiance(3.0);
point_light_ptr1->set_cast_shadow(true);
add_light(point_light_ptr1);
////////////////////////////////////////sky, SpherePartConcave///////////////////////////////////////
SpherePartConcave* spc_sky_ptr = new SpherePartConcave(Point3D(0, 0, 0), 1, 0, 360, 0, 90);
// image:
Image* image_sky_ptr = new Image;
// image_sky_ptr->read_ppm_file(".\\TextureFiles\\ppm\\MorningSky.ppm");
image_sky_ptr->read_ppm_file(".\\TextureFiles\\ppm\\EveningSky.ppm");
// image based texture:
ImageTexture* texture_image_sky_ptr = new ImageTexture;
texture_image_sky_ptr->set_image(image_sky_ptr);
// material:
SV_Phong* sv_phong_sky_ptr = new SV_Phong;
sv_phong_sky_ptr->set_ka(0.1);
sv_phong_sky_ptr->set_kd(0.25);
sv_phong_sky_ptr->set_cd(texture_image_sky_ptr);
sv_phong_sky_ptr->set_ks(0.1);
sv_phong_sky_ptr->set_exp(20.0);
Instance* instance_spc_sky_ptr = new Instance(spc_sky_ptr);
instance_spc_sky_ptr->scale(1000000);
instance_spc_sky_ptr->rotate_x(-5);
// instance_spc_sky_ptr->translate(0, -1000, 0);
instance_spc_sky_ptr->set_material(sv_phong_sky_ptr);
add_object(instance_spc_sky_ptr);
////////////////////////////////////////roof, SpherePartConcave///////////////////////////////////////
SpherePartConcave* spc_roof_ptr = new SpherePartConcave(Point3D(0, 0, 0), 1, 0, 360, 0, 60);
// image:
Image* image_roof_ptr = new Image;
image_roof_ptr->read_ppm_file(".\\TextureFiles\\ppm\\fresco3.ppm");
// image based texture:
ImageTexture* texture_image_roof_ptr = new ImageTexture;
texture_image_roof_ptr->set_image(image_roof_ptr);
// material:
SV_Phong* sv_phong_roof_ptr = new SV_Phong;
sv_phong_roof_ptr->set_ka(0.25);
sv_phong_roof_ptr->set_kd(0.75);
sv_phong_roof_ptr->set_cd(texture_image_roof_ptr);
sv_phong_roof_ptr->set_ks(0.1);
sv_phong_roof_ptr->set_exp(20.0);
Instance* instance_spc_roof_ptr = new Instance(spc_roof_ptr);
instance_spc_roof_ptr->scale(4);
instance_spc_roof_ptr->set_material(sv_phong_roof_ptr);
add_object(instance_spc_roof_ptr);
////////////////////////////////////////floor, SolidCylinder////////////////////////////////////////////////
SolidCylinder* sc_floor_ptr = new SolidCylinder();
// noise:
CubicNoise* noise_floor_ptr = new CubicNoise;
noise_floor_ptr->set_num_octaves(6);
noise_floor_ptr->set_gain(0.5);
noise_floor_ptr->set_lacunarity(2.0);
// ramp image:
Image* image_floor_ptr = new Image;
image_floor_ptr->read_ppm_file(".\\TextureFiles\\ppm\\sandstone_ramp4.ppm");
// marble texture:
FBmTextureRamp* texture_floor_ptr = new FBmTextureRamp(image_floor_ptr);
texture_floor_ptr->set_noise(noise_floor_ptr);
texture_floor_ptr->set_perturbation(4.0);
InstanceTexture* it_floor_ptr = new InstanceTexture(texture_floor_ptr);
it_floor_ptr->scale(0.5);
it_floor_ptr->rotate_z(60);
// it_floor_ptr->translate(1.0, 4.0, 0.0);
// textured material:
float exp_floor = 250.0;
SV_GlossyReflector* sv_glossy_floor_ptr = new SV_GlossyReflector;
sv_glossy_floor_ptr->set_samples(num_samples, exp_floor);
sv_glossy_floor_ptr->set_ka(0.1);
sv_glossy_floor_ptr->set_kd(0.25);
sv_glossy_floor_ptr->set_ks(0.1);
sv_glossy_floor_ptr->set_exp(exp_floor);
sv_glossy_floor_ptr->set_cd(it_floor_ptr);
sv_glossy_floor_ptr->set_kr(0.75);
sv_glossy_floor_ptr->set_exponent(exp_floor);
sv_glossy_floor_ptr->set_cr(new ConstantColor(white));
Instance* instance_sc_floor_ptr = new Instance(sc_floor_ptr);
instance_sc_floor_ptr->scale(3.6, 0.1, 3.6);
// instance_sc_floor_ptr->translate(0, 0.2, 0);
instance_sc_floor_ptr->set_material(sv_glossy_floor_ptr);
add_object(instance_sc_floor_ptr);
////////////////////////////////////////step, SolidCylinder////////////////////////////////////////////////
SolidCylinder* sc_step_ptr = new SolidCylinder();
// noise:
CubicNoise* noise_step_ptr = new CubicNoise;
noise_step_ptr->set_num_octaves(6);
noise_step_ptr->set_gain(0.5);
noise_step_ptr->set_lacunarity(2.0);
// ramp image:
Image* image_step_ptr = new Image;
image_step_ptr->read_ppm_file(".\\TextureFiles\\ppm\\BlueMarbleRamp.ppm");
// marble texture:
FBmTextureRamp* texture_step_ptr = new FBmTextureRamp(image_step_ptr);
texture_step_ptr->set_noise(noise_step_ptr);
texture_step_ptr->set_perturbation(4.0);
InstanceTexture* it_step_ptr = new InstanceTexture(texture_step_ptr);
it_step_ptr->scale(0.05);
it_step_ptr->rotate_z(110);
// it_step_ptr->translate(1.0, 4.0, 0.0);
// textured material:
float exp_step = 500.0;
SV_GlossyReflector* sv_glossy_step_ptr = new SV_GlossyReflector;
sv_glossy_step_ptr->set_samples(num_samples, exp_step);
sv_glossy_step_ptr->set_ka(0.1);
sv_glossy_step_ptr->set_kd(0.25);
sv_glossy_step_ptr->set_ks(0.1);
sv_glossy_step_ptr->set_exp(exp_step);
sv_glossy_step_ptr->set_cd(it_step_ptr);
sv_glossy_step_ptr->set_kr(0.75);
sv_glossy_step_ptr->set_exponent(exp_step);
sv_glossy_step_ptr->set_cr(new ConstantColor(white));
Instance* instance_sc_step_ptr = new Instance(sc_step_ptr);
instance_sc_step_ptr->scale(4.6, 0.1, 4.6);
instance_sc_step_ptr->translate(0, -0.2, 0);
instance_sc_step_ptr->set_material(sv_glossy_step_ptr);
add_object(instance_sc_step_ptr);
////////////////////////////////////////square, SolidCylinder////////////////////////////////////////////////
SolidCylinder* sc_square_ptr = new SolidCylinder();
// noise:
CubicNoise* noise_square_ptr = new CubicNoise;
noise_square_ptr->set_num_octaves(8);
noise_square_ptr->set_gain(0.5);
noise_square_ptr->set_lacunarity(8.0);
FBmTextureWrapped* texture_square_ptr = new FBmTextureWrapped(noise_square_ptr);
texture_square_ptr->set_expansion_number(8.0);
texture_square_ptr->set_color(0.7, 1.0, 0.5); // light green
texture_square_ptr->set_min_value(0.0);
texture_square_ptr->set_max_value(1.0);
// textured material:
float exp_square = 1000.0;
SV_GlossyReflector* sv_glossy_square_ptr = new SV_GlossyReflector;
sv_glossy_square_ptr->set_samples(num_samples, exp_square);
sv_glossy_square_ptr->set_ka(0.1);
sv_glossy_square_ptr->set_kd(0.25);
sv_glossy_square_ptr->set_ks(0.1);
sv_glossy_square_ptr->set_exp(exp_square);
sv_glossy_square_ptr->set_cd(texture_square_ptr);
sv_glossy_square_ptr->set_kr(0.75);
sv_glossy_square_ptr->set_exponent(exp_square);
sv_glossy_square_ptr->set_cr(new ConstantColor(white));
Instance* instance_sc_square_ptr = new Instance(sc_square_ptr);
instance_sc_square_ptr->scale(9.6, 0.1, 9.6);
instance_sc_square_ptr->translate(0, -0.4, 0);
instance_sc_square_ptr->set_material(sv_glossy_square_ptr);
add_object(instance_sc_square_ptr);
////////////////////////////////////////sea, Sphere////////////////////////////////////////////////
Sphere* sphere_sea_ptr = new Sphere();
// textured material:
float exp_sea = 10000.0;
SV_GlossyReflector* sv_glossy_sea_ptr = new SV_GlossyReflector;
sv_glossy_sea_ptr->set_samples(num_samples, exp_sea);
sv_glossy_sea_ptr->set_ka(0.1);
sv_glossy_sea_ptr->set_kd(0.25);
sv_glossy_sea_ptr->set_ks(0.1);
sv_glossy_sea_ptr->set_exp(exp_sea);
sv_glossy_sea_ptr->set_cd(new ConstantColor(RGBColor(0.3, 0.3, 1.0)));
sv_glossy_sea_ptr->set_kr(0.75);
sv_glossy_sea_ptr->set_exponent(exp_sea);
sv_glossy_sea_ptr->set_cr(new ConstantColor(white));
Instance* instance_sphere_sea_ptr = new Instance(sphere_sea_ptr);
instance_sphere_sea_ptr->scale(50000);
instance_sphere_sea_ptr->translate(0, -50000.5, -9.6);
instance_sphere_sea_ptr->set_material(sv_glossy_sea_ptr);
add_object(instance_sphere_sea_ptr);
////////////////////////////////////////desk, SolidCylinder////////////////////////////////////////////////
SolidCylinder* sc_desk_ptr = new SolidCylinder();
// wood texture
RGBColor desk_light_color(0.5, 0.2, 0.065);
RGBColor desk_dark_color(0.05);
Wood* wood_desk_ptr = new Wood(desk_light_color, desk_dark_color);
wood_desk_ptr->set_grainy(1.0);
wood_desk_ptr->set_ringy(1.0);
InstanceTexture* transformed_wood_desk_ptr = new InstanceTexture(wood_desk_ptr);
transformed_wood_desk_ptr->scale(0.4);
// transformed_wood_desk_ptr->rotate_z(110);
// material:
SV_Phong* sv_phong_desk_ptr = new SV_Phong;
sv_phong_desk_ptr->set_ka(0.25);
sv_phong_desk_ptr->set_kd(0.75);
sv_phong_desk_ptr->set_cd(transformed_wood_desk_ptr);
sv_phong_desk_ptr->set_ks(0.1);
sv_phong_desk_ptr->set_exp(20.0);
Instance* instance_sc_desk_ptr = new Instance(sc_desk_ptr);
instance_sc_desk_ptr->scale(0.3, 0.2, 0.3);
instance_sc_desk_ptr->translate(-0.4, 0.3, -3);
instance_sc_desk_ptr->set_material(sv_phong_desk_ptr);
add_object(instance_sc_desk_ptr);
////////////////////////////////////////cushion, SolidCylinder////////////////////////////////////////////////
SolidCylinder* sc_cushion_ptr = new SolidCylinder();
// SolidCylinderChecker:
SolidCylinderChecker* sc_checker_cushion_ptr = new SolidCylinderChecker();
sc_checker_cushion_ptr->set_num_horizontal_checkers(6);
sc_checker_cushion_ptr->set_num_vertical_checkers(2);
sc_checker_cushion_ptr->set_num_radius_checkers_disk(3);
sc_checker_cushion_ptr->set_horizontal_line_width(0.01);
sc_checker_cushion_ptr->set_vertical_line_width(0.01);
sc_checker_cushion_ptr->set_color1(0.5, 0.2, 0.065);
sc_checker_cushion_ptr->set_color2(0.4);
sc_checker_cushion_ptr->set_line_color(1.0, 0.0, 0.0);
// material:
SV_Phong* sv_phong_sc_cushion_ptr = new SV_Phong;
sv_phong_sc_cushion_ptr->set_ka(0.25);
sv_phong_sc_cushion_ptr->set_kd(0.75);
sv_phong_sc_cushion_ptr->set_cd(sc_checker_cushion_ptr);
sv_phong_sc_cushion_ptr->set_ks(0.1);
sv_phong_sc_cushion_ptr->set_exp(20.0);
Instance* instance_sc_cushion_ptr = new Instance(sc_cushion_ptr);
instance_sc_cushion_ptr->scale(0.15, 0.05, 0.15);
instance_sc_cushion_ptr->translate(-1, 0.15, -3);
instance_sc_cushion_ptr->set_material(sv_phong_sc_cushion_ptr);
add_object(instance_sc_cushion_ptr);
////////////////////////////////////////teapot, bezier patches////////////////////////////////////////////////
Grid* grid_teapot_ptr = new Grid;
int patches[32][16];
float vertices[306][3];
get_teapot_data(patches, vertices);
grid_teapot_ptr->tessellate_flat_bezier_patches(40, 40, vertices, patches, 32);
grid_teapot_ptr->setup_cells();
// noise:
CubicNoise* noise_teapot_ptr = new CubicNoise;
noise_teapot_ptr->set_num_octaves(6);
noise_teapot_ptr->set_gain(0.5); // not relevant when num_octaves = 1
noise_teapot_ptr->set_lacunarity(2.0); // not relevant when num_octaves = 1
// ramp image:
Image* image_teapot_ptr = new Image;
image_teapot_ptr->read_ppm_file(".\\TextureFiles\\ppm\\BlueMarbleRamp.ppm");
// marble texture:
FBmTextureRamp* marble_teapot_ptr = new FBmTextureRamp(image_teapot_ptr);
marble_teapot_ptr->set_noise(noise_teapot_ptr);
marble_teapot_ptr->set_perturbation(4.0);
InstanceTexture* it_teapot_ptr = new InstanceTexture(marble_teapot_ptr);
// it_teapot_ptr->scale(0.1);
// it_teapot_ptr->rotate_x(-60);
// it_teapot_ptr->rotate_y(-60);
it_teapot_ptr->rotate_z(110);
it_teapot_ptr->translate(1.0, 4.0, 0.0);
// material:
SV_Phong* sv_phong_teapot_ptr = new SV_Phong;
sv_phong_teapot_ptr->set_ka(0.25);
sv_phong_teapot_ptr->set_kd(0.75);
sv_phong_teapot_ptr->set_cd(it_teapot_ptr);
sv_phong_teapot_ptr->set_ks(0.1);
sv_phong_teapot_ptr->set_exp(20.0);
Instance* instance_teapot_ptr = new Instance(grid_teapot_ptr);
instance_teapot_ptr->rotate_x(-90);
instance_teapot_ptr->rotate_y(160);
instance_teapot_ptr->scale(0.06);
instance_teapot_ptr->translate(-0.25, 0.5, -2.9);
instance_teapot_ptr->set_material(sv_phong_teapot_ptr);
add_object(instance_teapot_ptr);
////////////////////////////////////////cup, rotational sweeping////////////////////////////////////////////////
Grid* grid_cup_ptr = new Grid;
Point2D ctrl_points1[6] = {Point2D(-1.0, 5.0), Point2D( 2.0, 4.0),
Point2D( 2.0, 1.0), Point2D(-0.5, 1.0),
Point2D( 1.5, -3.0), Point2D( 3.0, 0.0)};
grid_cup_ptr->tessellate_flat_rotational_sweeping(200, 50, ctrl_points1, 6, false);
grid_cup_ptr->setup_cells();
// noise:
CubicNoise* noise_cup_ptr = new CubicNoise;
noise_cup_ptr->set_num_octaves(6);
noise_cup_ptr->set_gain(0.5); // not relevant when num_octaves = 1
noise_cup_ptr->set_lacunarity(2.0); // not relevant when num_octaves = 1
// ramp image:
Image* image_cup_ptr = new Image;
image_cup_ptr->read_ppm_file(".\\TextureFiles\\ppm\\BlueMarbleRamp.ppm");
// marble texture:
FBmTextureRamp* marble_cup_ptr = new FBmTextureRamp(image_cup_ptr);
marble_cup_ptr->set_noise(noise_cup_ptr);
marble_cup_ptr->set_perturbation(4.0);
InstanceTexture* it_cup_ptr = new InstanceTexture(marble_cup_ptr);
it_cup_ptr->rotate_z(110);
it_cup_ptr->translate(1.0, 4.0, 0.0);
// material:
SV_Phong* sv_phong_cup_ptr = new SV_Phong;
sv_phong_cup_ptr->set_ka(0.25);
sv_phong_cup_ptr->set_kd(0.75);
sv_phong_cup_ptr->set_cd(it_cup_ptr);
sv_phong_cup_ptr->set_ks(0.1);
sv_phong_cup_ptr->set_exp(20.0);
Instance* instance_cup_ptr = new Instance(grid_cup_ptr);
instance_cup_ptr->scale(0.0353);
instance_cup_ptr->translate(-0.5, 0.5646, -2.85);
instance_cup_ptr->set_material(sv_phong_cup_ptr);
add_object(instance_cup_ptr);
////////////////////////////////////////bunny////////////////////////////////////////////////
char* file_bunny_name = ".\\PLYFiles\\Bunny69K.ply";
Grid* grid_bunny_ptr = new Grid(new Mesh);
grid_bunny_ptr->read_smooth_triangles(file_bunny_name);
grid_bunny_ptr->setup_cells();
// noise:
CubicNoise* noise_bunny_ptr = new CubicNoise;
noise_bunny_ptr->set_num_octaves(6);
noise_bunny_ptr->set_gain(0.5); // not relevant when num_octaves = 1
noise_bunny_ptr->set_lacunarity(2.0); // not relevant when num_octaves = 1
// ramp image:
Image* image_bunny_ptr = new Image;
image_bunny_ptr->read_ppm_file(".\\TextureFiles\\ppm\\BlueMarbleRamp.ppm");
// marble texture:
FBmTextureRamp* marble_bunny_ptr = new FBmTextureRamp(image_bunny_ptr);
marble_bunny_ptr->set_noise(noise_bunny_ptr);
marble_bunny_ptr->set_perturbation(4.0);
InstanceTexture* it_bunny_ptr = new InstanceTexture(marble_bunny_ptr);
it_bunny_ptr->rotate_z(110);
it_bunny_ptr->translate(1.0, 4.0, 0.0);
// material:
SV_Phong* sv_phong_bunny_ptr = new SV_Phong;
sv_phong_bunny_ptr->set_ka(0.25);
sv_phong_bunny_ptr->set_kd(0.75);
sv_phong_bunny_ptr->set_cd(it_bunny_ptr);
sv_phong_bunny_ptr->set_ks(0.1);
sv_phong_bunny_ptr->set_exp(20.0);
Instance* instance_bunny_ptr = new Instance(grid_bunny_ptr);
instance_bunny_ptr->scale(2);
instance_bunny_ptr->rotate_y(-60);
instance_bunny_ptr->translate(0.4, 0.0, -3);
instance_bunny_ptr->set_material(sv_phong_bunny_ptr);
add_object(instance_bunny_ptr);
////////////////////////////////////////bunny2////////////////////////////////////////////////
char* file_bunny_name2 = ".\\PLYFiles\\Bunny69K.ply";
Grid* grid_bunny_ptr2 = new Grid(new Mesh);
grid_bunny_ptr2->read_smooth_triangles(file_bunny_name2);
grid_bunny_ptr2->setup_cells();
// noise:
CubicNoise* noise_bunny_ptr2 = new CubicNoise;
noise_bunny_ptr2->set_num_octaves(6);
noise_bunny_ptr2->set_gain(0.5); // not relevant when num_octaves = 1
noise_bunny_ptr2->set_lacunarity(2.0); // not relevant when num_octaves = 1
// ramp image:
Image* image_bunny_ptr2 = new Image;
image_bunny_ptr2->read_ppm_file(".\\TextureFiles\\ppm\\BlueMarbleRamp.ppm");
// marble texture:
FBmTextureRamp* marble_bunny_ptr2 = new FBmTextureRamp(image_bunny_ptr2);
marble_bunny_ptr2->set_noise(noise_bunny_ptr2);
marble_bunny_ptr2->set_perturbation(4.0);
InstanceTexture* it_bunny_ptr2 = new InstanceTexture(marble_bunny_ptr2);
it_bunny_ptr2->scale(0.5);
it_bunny_ptr2->rotate_z(110);
it_bunny_ptr2->translate(1.0, 4.0, 0.0);
// material:
SV_Phong* sv_phong_bunny_ptr2 = new SV_Phong;
sv_phong_bunny_ptr2->set_ka(0.25);
sv_phong_bunny_ptr2->set_kd(0.75);
sv_phong_bunny_ptr2->set_cd(it_bunny_ptr2);
sv_phong_bunny_ptr2->set_ks(0.1);
sv_phong_bunny_ptr2->set_exp(20.0);
Instance* instance_bunny_ptr2 = new Instance(grid_bunny_ptr2);
instance_bunny_ptr2->scale(2);
instance_bunny_ptr2->rotate_y(-120);
instance_bunny_ptr2->translate(0.8, 0.0, -3.3);
instance_bunny_ptr2->set_material(sv_phong_bunny_ptr2);
add_object(instance_bunny_ptr2);
////////////////////////////////////////boat, SpherePartConvex///////////////////////////////////////
SpherePartConvex* spc_boat_ptr = new SpherePartConvex(Point3D(0, 0, 0), 1, 0, 360, 90, 180);
// wood texture
RGBColor boat_light_color(0.5, 0.2, 0.065);
RGBColor boat_dark_color(0.05);
Wood* wood_boat_ptr = new Wood(boat_light_color, boat_dark_color);
wood_boat_ptr->set_grainy(1.0);
wood_boat_ptr->set_ringy(1.0);
InstanceTexture* transformed_wood_boat_ptr = new InstanceTexture(wood_boat_ptr);
transformed_wood_boat_ptr->scale(0.4);
// transformed_wood_boat_ptr->rotate_z(110);
// material:
SV_Phong* sv_phong_boat_ptr = new SV_Phong;
sv_phong_boat_ptr->set_ka(0.25);
sv_phong_boat_ptr->set_kd(0.75);
sv_phong_boat_ptr->set_cd(transformed_wood_boat_ptr);
sv_phong_boat_ptr->set_ks(0.1);
sv_phong_boat_ptr->set_exp(20.0);
Instance* instance_sc_boat_ptr = new Instance(spc_boat_ptr);
instance_sc_boat_ptr->scale(2);
instance_sc_boat_ptr->translate(-5, 0.8, -25);
instance_sc_boat_ptr->set_material(sv_phong_boat_ptr);
add_object(instance_sc_boat_ptr);
////////////////////////////////////////horse////////////////////////////////////////////////
char* file_horse_name = ".\\PLYFiles\\Horse97K.ply";
Grid* grid_horse_ptr = new Grid(new Mesh);
grid_horse_ptr->read_smooth_triangles(file_horse_name);
grid_horse_ptr->setup_cells();
// material:
SV_Phong* sv_phong_horse_ptr = new SV_Phong;
sv_phong_horse_ptr->set_ka(0.25);
sv_phong_horse_ptr->set_kd(0.75);
sv_phong_horse_ptr->set_cd(new ConstantColor(RGBColor(0.816, 0.169, 0.09)));
sv_phong_horse_ptr->set_ks(0.1);
sv_phong_horse_ptr->set_exp(20.0);
Instance* instance_horse_ptr = new Instance(grid_horse_ptr);
instance_horse_ptr->scale(4);
instance_horse_ptr->rotate_y(180);
instance_horse_ptr->translate(1.5, 0.9, -8.6);
instance_horse_ptr->set_material(sv_phong_horse_ptr);
add_object(instance_horse_ptr);
}
2,输出图形
屋檐的映射图片(该图片来自网络):
天空的映射图片(图片来自《Ray Tracing from the Ground Up》官网):
早晨的天空:
傍晚的天空:
面朝大海(早晨)
(由于sea材质glossy的指数为2000,所以天空在海面的倒影不明显)
面朝大海(傍晚)
(由于sea材质glossy的指数为10000,所以天空在海面的倒影能辨析)
面朝大海(晚上)
3,其他说明
完整代码下载链接:
http://download.csdn.net/detail/libing_zeng/9814973