Assorted bug fixes.

This commit is contained in:
Miguel Angel Astor Romero
2017-01-20 12:13:42 -04:00
parent 33aba8cae2
commit 5970be923b
9 changed files with 314 additions and 270 deletions

View File

@@ -26,84 +26,3 @@
- [X] Tone mapping
- [ ] Texture mapping
- [ ] Photon mapping
* Junk
#+BEGIN_SRC c++
void scene_1(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c) {
Sphere * s;
Plane * p;
Disk * d;
DirectionalLight * l;
e = new Environment(NULL, false, vec3(0.7f, 0.4f, 0.05f));
s = new Sphere(1.0f, 1.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(1.0f, 0.0f, 0.0f);
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(-1.0f, 1.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(0.0f, 1.0f, 0.0f);
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(1.0f, -1.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(0.0f, 0.0f, 1.0f);
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(-1.0f, -1.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(1.0f, 0.0f, 1.0f);
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(0.0f, 0.0f, -2.0f, 1.0f);
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 0.0f);
vf.push_back(static_cast<Figure *>(s));
p = new Plane(vec3(0.0f, -1.5f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
p->m_mat->m_diffuse = vec3(1.0f, 0.5f, 0.4f);
vf.push_back(static_cast<Figure *>(p));
s = new Sphere(-1.5f, 0.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
s->m_mat->m_rho = 0.3f;
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(1.5f, 0.0f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
s->m_mat->m_rho = 0.08f;
s->m_mat->m_refract = true;
s->m_mat->m_ref_index = 1.1f;
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(0.0f, 1.5f, -2.0f, 0.5f);
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
s->m_mat->m_rho = 0.5f;
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(0.0f, 0.0f, -1.0f, 0.25f);
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
s->m_mat->m_rho = 0.1f;
vf.push_back(static_cast<Figure *>(s));
d = new Disk(vec3(-0.0f, -0.0f, -0.5f), vec3(0.0f, 0.0f, 0.1f), 0.25f);
d->m_mat->m_diffuse = vec3(1.0f, 0.0f, 0.0f);
d->m_mat->m_rho = 0.3f;
d->m_mat->m_refract = true;
d->m_mat->m_ref_index = 1.33f;
vf.push_back(static_cast<Figure *>(d));
l = new DirectionalLight();
l->m_position = normalize(vec3(1.0f, 1.0f, 1.0f));
l->m_diffuse = vec3(0.0f, 1.0f, 1.0f);
vl.push_back(static_cast<Light *>(l));
l = new DirectionalLight();
l->m_position = normalize(vec3(-1.0f, 1.0f, 1.0f));
l->m_diffuse = vec3(1.0f, 1.0f, 0.0f);
vl.push_back(static_cast<Light *>(l));
l = new DirectionalLight();
l->m_position = normalize(vec3(0.0f, 1.0f, -1.0f));
l->m_diffuse = vec3(1.0f, 0.0f, 1.0f);
vl.push_back(static_cast<Light *>(l));
}
#+END_SRC

View File

@@ -2,13 +2,17 @@
#ifndef DIRECTIONAL_LIGHT_HPP
#define DIRECTIONAL_LIGHT_HPP
#include <glm/glm.hpp>
#include "light.hpp"
using glm::normalize;
class DirectionalLight: public Light {
public:
DirectionalLight(): Light() { }
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) { }
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): Light(normalize(_p), _d, _s) { }
virtual vec3 direction(vec3 point);
virtual float distance(vec3 point);

View File

@@ -30,10 +30,6 @@ using namespace glm;
////////////////////////////////////////////
// Function prototypes.
////////////////////////////////////////////
// static void scene_1(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
// static void scene_2(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
// static void scene_3(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
// static void scene_4(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
static void print_usage(char ** const argv);
static void parse_args(int argc, char ** const argv);
@@ -143,27 +139,50 @@ int main(int argc, char ** argv) {
cout << endl;
// Copy the pixels to the output bitmap.
cout << "Saving output image." << endl;
input_bitmap = FreeImage_AllocateT(FIT_RGBF, g_w, g_h, 96);
pitch = FreeImage_GetPitch(input_bitmap);
bits = (BYTE*)FreeImage_GetBits(input_bitmap);
for (unsigned int y = 0; y < FreeImage_GetHeight(input_bitmap); y++) {
pixel = (FIRGBF*)bits;
for (unsigned int x = 0; x < FreeImage_GetWidth(input_bitmap); x++) {
pixel[x].red = image[g_h - 1 - y][x].r;
pixel[x].green = image[g_h - 1 - y][x].g;
pixel[x].blue = image[g_h - 1 - y][x].b;
if (g_tracer == MONTE_CARLO || g_tracer == JENSEN) {
cout << "Saving output image." << endl;
input_bitmap = FreeImage_AllocateT(FIT_RGBF, g_w, g_h, 96);
pitch = FreeImage_GetPitch(input_bitmap);
bits = (BYTE *)FreeImage_GetBits(input_bitmap);
for (unsigned int y = 0; y < FreeImage_GetHeight(input_bitmap); y++) {
pixel = (FIRGBF *)bits;
for (unsigned int x = 0; x < FreeImage_GetWidth(input_bitmap); x++) {
pixel[x].red = image[g_h - 1 - y][x].r;
pixel[x].green = image[g_h - 1 - y][x].g;
pixel[x].blue = image[g_h - 1 - y][x].b;
}
bits += pitch;
}
bits += pitch;
}
output_bitmap = FreeImage_ToneMapping(input_bitmap, FITMO_DRAGO03, g_gamma, g_exposure);
// Save the output image.
fif = FreeImage_GetFIFFromFilename(g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Save(fif, output_bitmap, g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Unload(input_bitmap);
FreeImage_Unload(output_bitmap);
output_bitmap = FreeImage_ToneMapping(input_bitmap, FITMO_DRAGO03, g_gamma, g_exposure);
// Save the output image.
fif = FreeImage_GetFIFFromFilename(g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Save(fif, output_bitmap, g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Unload(input_bitmap);
FreeImage_Unload(output_bitmap);
} else {
input_bitmap = FreeImage_Allocate(g_w, g_h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
pitch = FreeImage_GetLine(input_bitmap) / FreeImage_GetWidth(input_bitmap);
bits = (BYTE *)FreeImage_GetBits(input_bitmap);
for (unsigned int y = 0; y < FreeImage_GetHeight(input_bitmap); y++) {
bits = FreeImage_GetScanLine(input_bitmap, y);
for (unsigned int x = 0; x < FreeImage_GetWidth(input_bitmap); x++) {
bits[FI_RGBA_RED] = static_cast<BYTE>(image[g_h - 1 - y][x].r * 255.0f);
bits[FI_RGBA_GREEN] = static_cast<BYTE>(image[g_h - 1 - y][x].g * 255.0f);
bits[FI_RGBA_BLUE] = static_cast<BYTE>(image[g_h - 1 - y][x].b * 255.0f);
bits += pitch;
}
}
FreeImage_AdjustGamma(input_bitmap, g_gamma);
// Save the output image.
fif = FreeImage_GetFIFFromFilename(g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Save(fif, input_bitmap, g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
FreeImage_Unload(input_bitmap);
}
// Clean up.
if (g_out_file_name != NULL)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 KiB

After

Width:  |  Height:  |  Size: 396 KiB

280
scene.cpp
View File

@@ -89,7 +89,7 @@ static const string LGT_SPD_KEY = "spot_direction";
static const string LGT_SPC_KEY = "spot_cutoff";
static const string LGT_SPE_KEY = "spot_exponent";
Scene::Scene(const char * file_name, int h, int w, float fov) throw(SceneError) {
Scene::Scene(const char * file_name, int h, int w, float fov) {
ostringstream oss;
ifstream ifs(file_name, ios::in);
Value val;
@@ -142,6 +142,8 @@ Scene::Scene(const char * file_name, int h, int w, float fov) throw(SceneError)
}
} catch (SceneError & e) {
throw e;
} catch (runtime_error & r) {
throw SceneError("Type error in input file.");
}
// If there were no camera and/or environment defined, create some default ones.
@@ -169,7 +171,7 @@ Scene::~Scene() {
m_lights.clear();
}
void Scene::read_vector(Value & val, vec3 & vec) throw(SceneError) {
void Scene::read_vector(Value & val, vec3 & vec) {
Array a = val.get_value<Array>();
if (a.size() < 3)
@@ -178,7 +180,7 @@ void Scene::read_vector(Value & val, vec3 & vec) throw(SceneError) {
vec = vec3(a[0].get_value<double>(), a[1].get_value<double>(), a[2].get_value<double>());
}
void Scene::read_environment(Value & v) throw(SceneError) {
void Scene::read_environment(Value & v) {
string t_name = "";
bool l_probe = false, has_tex = false, has_color = false;
vec3 color = vec3(1.0f);
@@ -211,47 +213,43 @@ void Scene::read_environment(Value & v) throw(SceneError) {
m_env = new Environment(has_tex ? t_name.c_str() : NULL , l_probe, color);
}
void Scene::read_camera(Value & v) throw(SceneError) {
void Scene::read_camera(Value & v) {
bool has_up = false, has_left = false, has_eye = false, has_look = false;
vec3 eye, look, left, up, translation;
float pitch = 0.0f, yaw = 0.0f, roll = 0.0f;
Object cam_obj = v.get_value<Object>();
try {
for (Object::iterator it = cam_obj.begin(); it != cam_obj.end(); it++) {
if ((*it).name_ == CAM_EYE_KEY) {
read_vector((*it).value_, eye);
has_eye = true;
for (Object::iterator it = cam_obj.begin(); it != cam_obj.end(); it++) {
if ((*it).name_ == CAM_EYE_KEY) {
read_vector((*it).value_, eye);
has_eye = true;
} else if ((*it).name_ == CAM_CNT_KEY) {
read_vector((*it).value_, look);
has_look = true;
} else if ((*it).name_ == CAM_CNT_KEY) {
read_vector((*it).value_, look);
has_look = true;
} else if ((*it).name_ == CAM_LFT_KEY) {
read_vector((*it).value_, left);
has_left = true;
} else if ((*it).name_ == CAM_LFT_KEY) {
read_vector((*it).value_, left);
has_left = true;
} else if ((*it).name_ == CAM_UPV_KEY) {
read_vector((*it).value_, up);
has_up = true;
} else if ((*it).name_ == CAM_UPV_KEY) {
read_vector((*it).value_, up);
has_up = true;
} else if ((*it).name_ == GEO_TRN_KEY)
read_vector((*it).value_, translation);
} else if ((*it).name_ == GEO_TRN_KEY)
read_vector((*it).value_, translation);
else if ((*it).name_ == CAM_RLL_KEY)
roll = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == CAM_RLL_KEY)
roll = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == CAM_PTC_KEY)
pitch = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == CAM_PTC_KEY)
pitch = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == CAM_YAW_KEY)
yaw = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == CAM_YAW_KEY)
yaw = static_cast<float>((*it).value_.get_value<double>());
else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in camera." << endl;
}
} catch (SceneError & e) {
throw e;
else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in camera." << endl;
}
if (!has_eye || !has_look)
@@ -271,49 +269,45 @@ void Scene::read_camera(Value & v) throw(SceneError) {
m_cam->translate(translation);
}
Material * Scene::read_material(Value & v) throw(SceneError) {
Material * Scene::read_material(Value & v) {
vec3 emission = vec3(0.0f), diffuse = vec3(1.0f), specular = vec3(1.0f);
bool transmissive = false;
float rho = 0.0f, ref_index = 1.0f, shininess = 89.0f;
Material * mat = NULL;
Object mat_obj = v.get_value<Object>();
try {
for (Object::iterator it = mat_obj.begin(); it != mat_obj.end(); it++) {
if ((*it).name_ == MLT_EMS_KEY) {
read_vector((*it).value_, emission);
for (Object::iterator it = mat_obj.begin(); it != mat_obj.end(); it++) {
if ((*it).name_ == MLT_EMS_KEY) {
read_vector((*it).value_, emission);
} else if ((*it).name_ == MLT_DIF_KEY) {
read_vector((*it).value_, diffuse);
} else if ((*it).name_ == MLT_DIF_KEY) {
read_vector((*it).value_, diffuse);
} else if ((*it).name_ == MLT_SPC_KEY) {
read_vector((*it).value_, specular);
} else if ((*it).name_ == MLT_SPC_KEY) {
read_vector((*it).value_, specular);
} else if ((*it).name_ == MLT_RHO_KEY) {
rho = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_RHO_KEY) {
rho = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_SHN_KEY) {
shininess = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_SHN_KEY) {
shininess = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_RFI_KEY) {
ref_index = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_RFI_KEY) {
ref_index = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == MLT_BRF_KEY) {
transmissive = (*it).value_.get_value<bool>();
} else if ((*it).name_ == MLT_BRF_KEY) {
transmissive = (*it).value_.get_value<bool>();
} else if ((*it).name_ == MLT_BRD_KEY) {
if ((*it).value_.get_value<string>() == BRD_PHN_KEY)
mat = new Material(new PhongBRDF());
else if ((*it).value_.get_value<string>() == BRD_HSA_KEY)
mat = new Material(new HeidrichSeidelAnisotropicBRDF(vec3(0.0f, 1.0f, 0.0f)));
else
throw SceneError("Unrecognized BRDF in material.");
} else if ((*it).name_ == MLT_BRD_KEY) {
if ((*it).value_.get_value<string>() == BRD_PHN_KEY)
mat = new Material(new PhongBRDF());
else if ((*it).value_.get_value<string>() == BRD_HSA_KEY)
mat = new Material(new HeidrichSeidelAnisotropicBRDF(vec3(0.0f, 1.0f, 0.0f)));
else
throw SceneError("Unrecognized BRDF in material.");
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in material." << endl;
}
} catch(SceneError & e) {
throw e;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in material." << endl;
}
if (mat == NULL)
@@ -329,39 +323,35 @@ Material * Scene::read_material(Value & v) throw(SceneError) {
return mat;
}
Figure * Scene::read_sphere(Value &v) throw(SceneError) {
Figure * Scene::read_sphere(Value &v) {
bool has_position = false, has_radius = false;
vec3 position;
float radius = 1.0f;
Material * mat = NULL;
Object sph_obj = v.get_value<Object>();
try {
for (Object::iterator it = sph_obj.begin(); it != sph_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY) {
read_vector((*it).value_, position);
has_position = true;
for (Object::iterator it = sph_obj.begin(); it != sph_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY) {
read_vector((*it).value_, position);
has_position = true;
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_RAD_KEY) {
radius = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == FIG_RAD_KEY) {
radius = static_cast<float>((*it).value_.get_value<double>());
if (radius <= 0.0f)
throw SceneError("Sphere radius must be greater than 0.");
if (radius <= 0.0f)
throw SceneError("Sphere radius must be greater than 0.");
has_radius = true;
has_radius = true;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in sphere." << endl;
}
} catch (SceneError & e) {
throw e;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in sphere." << endl;
}
if (!has_position || !has_radius)
@@ -370,34 +360,30 @@ Figure * Scene::read_sphere(Value &v) throw(SceneError) {
return static_cast<Figure *>(new Sphere(position, radius, mat));
}
Figure * Scene::read_plane(Value &v) throw(SceneError) {
Figure * Scene::read_plane(Value &v) {
bool has_position = false, has_normal = false;
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
Material * mat = NULL;
Object pln_obj = v.get_value<Object>();
try {
for (Object::iterator it = pln_obj.begin(); it != pln_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
read_vector((*it).value_, position);
has_position = true;
for (Object::iterator it = pln_obj.begin(); it != pln_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
read_vector((*it).value_, position);
has_position = true;
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_NOR_KEY) {
read_vector((*it).value_, normal);
has_normal = true;
} else if ((*it).name_ == FIG_NOR_KEY) {
read_vector((*it).value_, normal);
has_normal = true;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in plane." << endl;
}
} catch (SceneError & e) {
throw e;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in plane." << endl;
}
if (!has_position || !has_normal)
@@ -406,43 +392,39 @@ Figure * Scene::read_plane(Value &v) throw(SceneError) {
return static_cast<Figure *>(new Plane(position, normal, mat));
}
Figure * Scene::read_disk(Value &v) throw(SceneError) {
Figure * Scene::read_disk(Value &v) {
bool has_position = false, has_normal = false, has_radius = false;
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
float radius = 1.0f;
Material * mat = NULL;
Object dsk_obj = v.get_value<Object>();
try {
for (Object::iterator it = dsk_obj.begin(); it != dsk_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
read_vector((*it).value_, position);
has_position = true;
for (Object::iterator it = dsk_obj.begin(); it != dsk_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
read_vector((*it).value_, position);
has_position = true;
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_MAT_KEY) {
try {
mat = read_material((*it).value_);
} catch (SceneError & e) {
throw e;
}
} else if ((*it).name_ == FIG_NOR_KEY) {
read_vector((*it).value_, normal);
has_normal = true;
} else if ((*it).name_ == FIG_NOR_KEY) {
read_vector((*it).value_, normal);
has_normal = true;
} else if ((*it).name_ == FIG_RAD_KEY) {
radius = static_cast<float>((*it).value_.get_value<double>());
} else if ((*it).name_ == FIG_RAD_KEY) {
radius = static_cast<float>((*it).value_.get_value<double>());
if (radius <= 0.0f)
throw SceneError("Disk radius must be greater than 0.");
if (radius <= 0.0f)
throw SceneError("Disk radius must be greater than 0.");
has_radius = true;
has_radius = true;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in disk." << endl;
}
} catch (SceneError & e) {
throw e;
} else
cerr << "Unrecognized key \"" << (*it).name_ << "\" in disk." << endl;
}
if (!has_position || !has_normal || !has_radius)
@@ -451,42 +433,38 @@ Figure * Scene::read_disk(Value &v) throw(SceneError) {
return static_cast<Figure *>(new Disk(position, normal, radius, mat));
}
Light * Scene::read_light(Value & v, light_type_t t) throw(SceneError) {
Light * Scene::read_light(Value & v, light_type_t t) {
vec3 position, diffuse = vec3(1.0f), specular = vec3(1.0f), spot_dir = vec3(0.0f, -1.0f, 0.0f);
float const_att = 1.0f, lin_att = 0.0f, quad_att = 0.0f, spot_cutoff = 45.0f, spot_exp = 0.0f;
Object lght_obj = v.get_value<Object>();
try {
for (Object::iterator it = lght_obj.begin(); it != lght_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == LGT_DIR_KEY)
read_vector((*it).value_, position);
for (Object::iterator it = lght_obj.begin(); it != lght_obj.end(); it++) {
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == LGT_DIR_KEY)
read_vector((*it).value_, position);
else if((*it).name_ == MLT_DIF_KEY)
read_vector((*it).value_, diffuse);
else if((*it).name_ == MLT_DIF_KEY)
read_vector((*it).value_, diffuse);
else if((*it).name_ == MLT_SPC_KEY)
read_vector((*it).value_, specular);
else if((*it).name_ == MLT_SPC_KEY)
read_vector((*it).value_, specular);
else if((*it).name_ == LGT_SPD_KEY)
read_vector((*it).value_, spot_dir);
else if((*it).name_ == LGT_SPD_KEY)
read_vector((*it).value_, spot_dir);
else if ((*it).name_ == LGT_CAT_KEY)
const_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_CAT_KEY)
const_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_LAT_KEY)
lin_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_LAT_KEY)
lin_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_QAT_KEY)
quad_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_QAT_KEY)
quad_att = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_SPC_KEY)
spot_cutoff = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_SPC_KEY)
spot_cutoff = static_cast<float>((*it).value_.get_value<double>());
else if ((*it).name_ == LGT_SPE_KEY)
spot_exp = static_cast<float>((*it).value_.get_value<double>());
}
} catch (SceneError & e) {
throw e;
else if ((*it).name_ == LGT_SPE_KEY)
spot_exp = static_cast<float>((*it).value_.get_value<double>());
}
if (t == DIRECTIONAL)

View File

@@ -33,18 +33,18 @@ public:
Environment * m_env;
Camera * m_cam;
Scene(const char * file_name, int h = 480, int w = 640, float fov = 90.0f) throw(SceneError);
Scene(const char * file_name, int h = 480, int w = 640, float fov = 90.0f);
~Scene();
private:
void read_vector(Value & val, vec3 & vec) throw(SceneError);
void read_environment(Value & v) throw(SceneError);
void read_camera(Value & v) throw(SceneError);
Material * read_material(Value & v) throw(SceneError);
Figure * read_sphere(Value & v) throw(SceneError);
Figure * read_plane(Value & v) throw(SceneError);
Figure * read_disk(Value & v) throw(SceneError);
Light * read_light(Value & v, light_type_t t) throw(SceneError);
void read_vector(Value & val, vec3 & vec);
void read_environment(Value & v);
void read_camera(Value & v);
Material * read_material(Value & v);
Figure * read_sphere(Value & v);
Figure * read_plane(Value & v);
Figure * read_disk(Value & v);
Light * read_light(Value & v, light_type_t t);
};
#endif

124
scenes/scene1.json Normal file
View File

@@ -0,0 +1,124 @@
{
"directional_light": {
"direction": [1.0, 1.0, 1.0],
"diffuse": [0.0, 1.0, 1.0]
},
"directional_light": {
"direction": [-1.0, 1.0, 1.0],
"diffuse": [1.0, 1.0, 0.0]
},
"directional_light": {
"direction": [0.0, 1.0, -1.0],
"diffuse": [1.0, 0.0, 1.0]
},
"disk": {
"position": [-0.0, -0.0, -0.5],
"normal": [0.0, 0.0, 0.1],
"radius": 0.25,
"material": {
"diffuse": [1.0, 0.0, 0.0],
"rho": 0.3,
"transmissive": true,
"ref_index": 1.33
}
},
"plane": {
"point": [0.0, -1.5, 0.0],
"normal": [0.0, 1.0, 0.0],
"material": {
"diffuse": [1.0, 0.5, 0.4]
}
},
"sphere": {
"position": [1.0, 1.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [1.0, 0.0, 0.0]
}
},
"sphere": {
"position": [-1.0, 1.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [0.0, 1.0, 0.0]
}
},
"sphere": {
"position": [1.0, -1.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [0.0, 0.0, 1.0]
}
},
"sphere": {
"position": [-1.0, -1.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [1.0, 0.0, 1.0]
}
},
"sphere": {
"position": [0.0, 0.0, -2.0],
"radius": 1.0,
"material": {
"diffuse": [1.0, 1.0, 0.0]
}
},
"sphere": {
"position": [-1.5, 0.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [1.0, 1.0, 1.0],
"rho": 0.3
}
},
"sphere": {
"position": [1.5, 0.0, -2.0],
"radius": 0.5,
"material": {
"diffuse": [1.0, 1.0, 1.0],
"rho": 0.08,
"transmissive": true,
"ref_index": 1.1
}
},
"sphere": {
"position": [0.0, 1.5, -2.0],
"radius": 0.5,
"material": {
"diffuse": [1.0, 1.0, 1.0],
"rho": 0.5
}
},
"sphere": {
"position": [0.0, 0.0, -1.0],
"radius": 0.25,
"material": {
"diffuse": [1.0, 1.0, 1.0],
"rho": 0.1
}
},
"environment": {
"color": [0.7, 0.4, 0.05]
},
"camera": {
"eye": [0.0, 0.0, 1.0],
"look": [0.0, 0.0, -1.0],
"up": [0.0, 1.0, 0.0]
}
}

View File

@@ -1,5 +1,5 @@
{
"point_light":{
"point_light": {
"position": [0.0, 0.9, -1.0]
},
@@ -12,7 +12,7 @@
}
},
"sphere":{
"sphere": {
"position": [-0.5, -0.5, -1.5],
"radius": 0.5,
"material": {
@@ -21,7 +21,7 @@
}
},
"sphere":{
"sphere": {
"position": [-0.5, -0.5, 0.6],
"radius": 0.5,
"material": {

View File

@@ -85,8 +85,8 @@ vec3 WhittedTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const
}
// Return final color.
return _f->m_mat->m_emission + color;
return clamp(_f->m_mat->m_emission + color, 0.0f, 1.0f);
} else
return s->m_env->get_color(r);
return clamp(s->m_env->get_color(r), 0.0f, 1.0f);
}