Added refractions and fresnel.

This commit is contained in:
2017-01-02 00:08:22 -04:00
parent c78a8d284f
commit 806040018e
7 changed files with 93 additions and 30 deletions

View File

@@ -31,6 +31,7 @@ static vec3 ** image;
static void scene_1(vector<Figure *> & vf, vector<Light *> & vl);
static void scene_2(vector<Figure *> & vf, vector<Light *> & vl);
static void scene_3(vector<Figure *> & vf, vector<Light *> & vl);
int main(int argc, char ** argv) {
FILE * out;
@@ -90,7 +91,7 @@ int main(int argc, char ** argv) {
image[i] = new vec3[g_w];
}
scene_1(figures, lights);
scene_3(figures, lights);
tracer = Tracer(g_h, g_w, g_fov);
@@ -167,7 +168,6 @@ static void scene_1(vector<Figure *> & vf, vector<Light *> & vl) {
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(0.0f, 0.0f, -2.0f, 1.0f);
//s->set_color(1.0f, 1.0f, 0.0f);
s->m_mat.m_diffuse = vec3(1.0f, 1.0f, 0.0f);
vf.push_back(static_cast<Figure *>(s));
@@ -183,6 +183,8 @@ static void scene_1(vector<Figure *> & vf, vector<Light *> & vl) {
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);
@@ -195,9 +197,11 @@ static void scene_1(vector<Figure *> & vf, vector<Light *> & vl) {
s->m_mat.m_rho = 0.1f;
vf.push_back(static_cast<Figure *>(s));
d = new Disk(vec3(0.0f, 2.0f, -2.0f), vec3(0.0f, -1.0f, 0.0f), 1.0f);
d->m_mat.m_diffuse = vec3(1.0f, 1.0f, 0.0f);
d->m_mat.m_rho = 0.8f;
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();
@@ -222,28 +226,28 @@ static void scene_2(vector<Figure *> & vf, vector<Light *> & vl) {
DirectionalLight * l;
p = new Plane(vec3(0.0f, -1.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
//p->set_color(0.0f, 1.0f, 0.0f);
p->m_mat.m_diffuse = vec3(0.0f, 1.0f, 0.0f);
vf.push_back(static_cast<Figure *>(p));
p = new Plane(vec3(-1.0f, 0.0f, 0.0f), vec3(1.0f, 0.0f, 0.0f));
//p->set_color(1.0f, 0.0f, 0.0f);
p->m_mat.m_diffuse = vec3(1.0f, 0.0f, 0.0f);
vf.push_back(static_cast<Figure *>(p));
p = new Plane(vec3(1.0f, 0.0f, 0.0f), vec3(-1.0f, 0.0f, 0.0f));
//p->set_color(0.0f, 0.0f, 1.0f);
p->m_mat.m_diffuse = vec3(0.0f, 0.0f, 1.0f);
vf.push_back(static_cast<Figure *>(p));
p = new Plane(vec3(0.0f, 1.0f, 0.0f), vec3(0.0f, -1.0f, 0.0f));
//p->set_color(1.0f, 1.0f, 1.0f);
p->m_mat.m_diffuse = vec3(1.0f, 1.0f, 1.0f);
vf.push_back(static_cast<Figure *>(p));
p = new Plane(vec3(0.0f, 0.0f, -2.0f), vec3(0.0f, 0.0f, 1.0f));
//p->set_color(1.0f, 0.0f, 1.0f);
p->m_mat.m_diffuse = vec3(1.0f, 0.0f, 1.0f);
vf.push_back(static_cast<Figure *>(p));
s = new Sphere(-0.4f, -0.5f, -1.5f, 0.5f);
//s->set_color(1.0f, 1.0f, 0.0f);
//s->rho = 0.4f;
s->m_mat.m_diffuse = vec3(1.0f, 1.0f, 0.0f);
s->m_mat.m_rho = 0.4f;
vf.push_back(static_cast<Figure *>(s));
l = new DirectionalLight();
@@ -251,3 +255,35 @@ static void scene_2(vector<Figure *> & vf, vector<Light *> & vl) {
l->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
vl.push_back(static_cast<Light *>(l));
}
static void scene_3(vector<Figure *> & vf, vector<Light *> & vl) {
Sphere * s;
Plane * p;
DirectionalLight * l;
s = new Sphere(0.0f, -0.15f, -2.0f, 1.0f);
s->m_mat.m_diffuse = vec3(1.0f, 0.5f, 0.0f);
s->m_mat.m_rho = 0.4f;
s->m_mat.m_refract = true;
s->m_mat.m_ref_index = 1.33f;
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(2.0f, 0.0f, -2.0f, 1.0f);
s->m_mat.m_diffuse = vec3(1.0f, 0.0f, 1.0f);
s->m_mat.m_rho = 0.6f;
vf.push_back(static_cast<Figure *>(s));
s = new Sphere(-1.0f, 0.25f, -3.25f, 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, 1.0f, 1.0f);
p->m_mat.m_specular = vec3(0.0f);
vf.push_back(static_cast<Figure *>(p));
l = new DirectionalLight();
l->m_position = normalize(vec3(-1.0f, 1.0f, 1.0f));
l->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
vl.push_back(static_cast<Light *>(l));
}