Skip to content

Commit

Permalink
Everything coded, but artifacted results and not multithreaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanschmitty committed Jan 16, 2012
1 parent 35640c9 commit 27abad2
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 142 deletions.
4 changes: 2 additions & 2 deletions assets/cornell_simp.pov
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ camera {
} }


//TOP LIGHT //TOP LIGHT
//light_source {<0, 10, 0> color rgb <3, 2.55, 1.29>} light_source {<0, 10, 0> color rgb <3, 2.55, 1.29>}
//doubled the real colors, it was too dark //doubled the real colors, it was too dark
light_source {<0, 10, 0> color rgb <2, 1.7, 0.86>} //light_source {<0, 10, 0> color rgb <2, 1.7, 0.86>}
//halved the real colors, so it is subtle //halved the real colors, so it is subtle
//light_source {<0, 5, 15> color rgb <0.1, 0.085, 0.043>} //light_source {<0, 5, 15> color rgb <0.1, 0.085, 0.043>}


Expand Down
10 changes: 4 additions & 6 deletions src/POVRayParser.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


#include "POVRayParser.h" #include "POVRayParser.h"
#include "RDSbvh.h" #include "RDSbvh.h"
#include "RDSPointDistribution.h"
#include "RDSSurfelCloud.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cctype> #include <cctype>
Expand Down Expand Up @@ -68,7 +66,7 @@ namespace RDST
objs->push_back(pBox); objs->push_back(pBox);


//Generate surfels //Generate surfels
GenerateSurfels(*surfels, *pBox); // GenerateSurfels(*surfels, *pBox);
} }
pos = line.find("cone"); pos = line.find("cone");
if (pos != std::string::npos) { if (pos != std::string::npos) {
Expand All @@ -92,7 +90,7 @@ namespace RDST
objs->push_back(pSphere); objs->push_back(pSphere);


//Generate surfels //Generate surfels
GenerateSurfels(*surfels, *pSphere); // GenerateSurfels(*surfels, *pSphere);


} }
pos = line.find("triangle"); pos = line.find("triangle");
Expand All @@ -105,7 +103,7 @@ namespace RDST
objs->push_back(pTri); objs->push_back(pTri);


//Generate surfels //Generate surfels
surfels->push_back(pTri); // surfels->push_back(pTri);


//Get point cloud and generate surfels //Get point cloud and generate surfels
// float minDist = 0.f; // float minDist = 0.f;
Expand Down Expand Up @@ -134,7 +132,7 @@ namespace RDST
} }
} }
std::cout << "Done." << std::endl; std::cout << "Done." << std::endl;
return SceneDescription(pCam, lights, areaLights, objs, planes, BVH(objs), BVH(surfels), surfels); return SceneDescription(pCam, lights, areaLights, objs, planes, BVH(objs), BVH(objs/*surfels*/), surfels);
} }


std::string& std::string&
Expand Down
63 changes: 44 additions & 19 deletions src/RDSIndirectIllum.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RDSIndirectIllum.h" #include "RDSIndirectIllum.h"
#define GLM_FORCE_INLINE #define GLM_FORCE_INLINE
#include <glm/gtx/rotate_vector.hpp> #include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/vector_angle.hpp>


namespace RDST namespace RDST
{ {
Expand Down Expand Up @@ -48,7 +49,7 @@ namespace RDST
} }


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //unbind fbo for now glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //unbind fbo for now
printf("lol\n"); // printf("lol\n");


loadVBO(desc); loadVBO(desc);


Expand All @@ -66,6 +67,8 @@ namespace RDST


void Rasterizer::initGL() void Rasterizer::initGL()
{ {
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
// int argc = 0; // int argc = 0;
// char** argv; // char** argv;
// glutInit(&argc, argv); // glutInit(&argc, argv);
Expand Down Expand Up @@ -200,7 +203,8 @@ namespace RDST


void Rasterizer::lights(const SceneDescription& desc) { void Rasterizer::lights(const SceneDescription& desc) {
/* LIGHTS */ /* LIGHTS */
glEnable(GL_LIGHTING); // glEnable(GL_LIGHTING);
glDisable(GL_LIGHTING);
int i=0; int i=0;
unsigned int curLight = GL_LIGHT0; unsigned int curLight = GL_LIGHT0;
for(std::vector<PointLightPtr>::const_iterator it = desc.lights().begin(); it != desc.lights().end(); ++it) { for(std::vector<PointLightPtr>::const_iterator it = desc.lights().begin(); it != desc.lights().end(); ++it) {
Expand All @@ -210,9 +214,10 @@ namespace RDST
glm::vec4 lcolor = (*it)->getColor(); glm::vec4 lcolor = (*it)->getColor();
//Point light position //Point light position
GLfloat lightPos[] = {lpos.x, lpos.y, lpos.z, 0.0}; GLfloat lightPos[] = {lpos.x, lpos.y, lpos.z, 0.0};
GLfloat ambientComp[] = {0.0, 0.0, 0.0, 0.0}; GLfloat ambientComp[] = {lcolor.r, lcolor.g, lcolor.b, 0.0};
//Diffuse composition //Diffuse composition
GLfloat diffuseComp[] = {lcolor.r, lcolor.g, lcolor.b, 0.0}; // GLfloat diffuseComp[] = {lcolor.r, lcolor.g, lcolor.b, 0.0};
GLfloat diffuseComp[] = {0.f, 0.f, 0.f, 0.f};
//Specular composition //Specular composition
GLfloat specularComp[] = {0.0, 0.0, 0.0, 0.0}; GLfloat specularComp[] = {0.0, 0.0, 0.0, 0.0};
//Point light //Point light
Expand Down Expand Up @@ -250,7 +255,6 @@ namespace RDST
return colortexture; return colortexture;
} }



glm::vec3 IndirectIllumMonteCarlo(const Intersection& intrs, const SceneDescription& scene, unsigned int recursionsLeft) glm::vec3 IndirectIllumMonteCarlo(const Intersection& intrs, const SceneDescription& scene, unsigned int recursionsLeft)
{ {
glm::vec3 indirectColor(0.f); glm::vec3 indirectColor(0.f);
Expand Down Expand Up @@ -291,42 +295,63 @@ namespace RDST
glm::vec3 tan = fabs(intrs.n.y) == 1.f ? glm::vec3(1,0,0) : glm::normalize(k - ((glm::dot(k, intrs.n))*intrs.n)); //Gram-Schmidt Process glm::vec3 tan = fabs(intrs.n.y) == 1.f ? glm::vec3(1,0,0) : glm::normalize(k - ((glm::dot(k, intrs.n))*intrs.n)); //Gram-Schmidt Process
//Generate 6 cube faces (i.e. 5 cameras) //Generate 6 cube faces (i.e. 5 cameras)
::Camera cameras [5]; ::Camera cameras [5];
float near = 0.01f, far = 15.f;
glm::vec3 loc = intrs.p + (near*intrs.n);
// glm::vec3 loc = intrs.p;
glm::vec3 dir1 = tan;
glm::vec3 dir2 = glm::rotate(tan, 90.f, intrs.n);
glm::vec3 dir3 = glm::rotate(tan, 180.f, intrs.n);
glm::vec3 dir4 = glm::rotate(tan, 270.f, intrs.n);
glm::vec3 dir5 = intrs.n;
for (int i=0; i<4; ++i) { for (int i=0; i<4; ++i) {
glm::vec3 dir(0.f); glm::vec3 dir;
if (i==0) dir = tan; if (i==0) dir = dir1;
else if (i==1) dir = glm::rotate(tan, 90.f, intrs.n); else if (i==1) dir = dir2;
else if (i==2) dir = glm::rotate(tan, 180.f, intrs.n); else if (i==2) dir = dir3;
else /*(i==3)*/ dir = glm::rotate(tan, 270.f, intrs.n); else /*(i==3)*/ dir = dir4;
cameras[i] = ::Camera(90, //fov cameras[i] = ::Camera(90, //fov
intrs.p.x, intrs.p.y, intrs.p.z, //loc loc.x, loc.y, loc.z, //loc
dir.x, dir.y, dir.z, //dir dir.x, dir.y, dir.z, //dir
intrs.n.x, intrs.n.y, intrs.n.z, //up intrs.n.x, intrs.n.y, intrs.n.z, //up
0.01f, 100.f); //near/far near, far); //clipping planes
} }
cameras[4] = ::Camera(90, //fov cameras[4] = ::Camera(90, //fov
intrs.p.x, intrs.p.y, intrs.p.z, //loc loc.x, loc.y, loc.z, //loc
intrs.n.x, intrs.n.y, intrs.n.z, //dir dir5.x, dir5.y, dir5.z, //dir
tan.x, tan.y, tan.z, //up tan.x, tan.y, tan.z, //up
0.01f, 100.f); //near/far near, far); //clipping planes
//Rasterize cube faces (i.e. render 8x8 texture per camera) //Rasterize cube faces (i.e. render 8x8 texture per camera)
static Rasterizer rstr(8, 8, scene); //TODO: static? or should I redesign? static Rasterizer rstr(8, 8, scene); //TODO: static? or should I redesign?
unsigned char pixelData[4*64]; unsigned char pixelData[4*64];
// printf("\nPoint!\n");
for (int i=0; i<5; ++i) { for (int i=0; i<5; ++i) {
GLuint tex = rstr.rasterSurfels(cameras[i]); GLuint tex = rstr.rasterSurfels(cameras[i]);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixelData); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixelData);
float weight = 0.f;
for (int j=0; j<64; ++j) { for (int j=0; j<64; ++j) {
// printf("<%f %f %f> ", pixelData[4*j]/255.f, pixelData[4*j+1]/255.f, pixelData[4*j+2]/255.f); int x = j%8, y = j/8;
// if (j%8 == 0) printf("\n"); glm::vec3 U(cameras[i].up.x, cameras[i].up.y, cameras[i].up.z);
glm::vec3 D(cameras[i].dir.x, cameras[i].dir.y, cameras[i].dir.z);
glm::vec3 R = -glm::cross(U, D);
glm::vec3 M = loc + (near*D);
glm::vec3 pt = M + (-0.875f*near + 0.25f*(float)x*near)*R + (-0.875f*near + 0.25f*(float)y*near)*U;
glm::vec3 v = glm::normalize(pt - intrs.p);
weight = glm::dot(intrs.n, v);
// if (j%8 == 0) printf("\n");
// printf("<%f %f %f, %f> ", pixelData[4*j]/255.f, pixelData[4*j+1]/255.f, pixelData[4*j+2]/255.f, weight);
// printf("%f ", weight);
indirectColor.r += pixelData[4*j+0]/255.f; //red indirectColor.r += pixelData[4*j+0]/255.f; //red
indirectColor.g += pixelData[4*j+1]/255.f; //green indirectColor.g += pixelData[4*j+1]/255.f; //green
indirectColor.b += pixelData[4*j+2]/255.f; //blue indirectColor.b += pixelData[4*j+2]/255.f; //blue
// indirectColor += pixelData[4*j+3]; //alpha //indirectColor += pixelData[4*j+3]; //alpha
indirectColor *= weight;
} }
// printf("\n"); // printf("\n");
} }
// printf("Point done!\n");
indirectColor /= 64.f * 5.f; indirectColor /= 64.f * 5.f;
// printf("final color: %f %f %f\n", indirectColor.r, indirectColor.g, indirectColor.b); // printf("final color: %f %f %f\n", indirectColor.r, indirectColor.g, indirectColor.b);


return indirectColor; return 6.f*indirectColor;
} }
} }
Loading

0 comments on commit 27abad2

Please sign in to comment.