-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ange-yaghi/feature/I29_demo_refactoring
[#29] : Refactored all demos into a separate project.
- Loading branch information
Showing
31 changed files
with
992 additions
and
135,152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include <demos.h> | ||
|
||
using namespace manta; | ||
|
||
void manta_demo::cubeTestDemo(int samplesPerPixel, int resolutionX, int resolutionY) { | ||
Scene scene; | ||
|
||
// Load all object files | ||
ObjFileLoader cubeObj; | ||
bool result = cubeObj.readObjFile(MODEL_PATH "cube.obj"); | ||
|
||
// Create all materials | ||
SimpleSpecularDiffuseMaterial wallMaterial; | ||
wallMaterial.setEmission(math::constants::Zero); | ||
wallMaterial.setDiffuseColor(getColor(200, 200, 200)); | ||
wallMaterial.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial outdoorLight; | ||
outdoorLight.setEmission(math::loadVector(9, 8, 8)); | ||
outdoorLight.setDiffuseColor(math::constants::Zero); | ||
outdoorLight.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial outdoorTopLightMaterial; | ||
outdoorTopLightMaterial.setEmission(math::loadVector(10, 10, 11)); | ||
outdoorTopLightMaterial.setDiffuseColor(math::constants::Zero); | ||
outdoorTopLightMaterial.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial teapotMaterial; | ||
teapotMaterial.setEmission(math::constants::Zero); | ||
teapotMaterial.setDiffuseColor(getColor(150, 0, 0)); | ||
teapotMaterial.setSpecularColor(getColor(100, 100, 100)); | ||
|
||
SimpleSpecularDiffuseMaterial groundMaterial; | ||
groundMaterial.setEmission(math::constants::Zero); | ||
groundMaterial.setDiffuseColor(math::constants::Zero); | ||
groundMaterial.setSpecularColor(getColor(100, 100, 100)); | ||
|
||
// Create all scene geometry | ||
Mesh cube; | ||
cube.loadObjFileData(&cubeObj); | ||
cube.setFastIntersectEnabled(false); | ||
cube.setFastIntersectRadius((math::real)4.0); | ||
|
||
// Create scene objects | ||
SceneObject *cubeObject = scene.createSceneObject(); | ||
cubeObject->setGeometry(&cube); | ||
cubeObject->setMaterial(&wallMaterial); | ||
|
||
//SceneObject *outdoorTopLightObject = scene.createSceneObject(); | ||
//outdoorTopLightObject->setGeometry(&outdoorTopLightGeometry); | ||
//outdoorTopLightObject->setMaterial(&outdoorTopLightMaterial); | ||
|
||
//SceneObject *lightSource = scene.createSceneObject(); | ||
//lightSource->setGeometry(&outdoorLightGeometry); | ||
//lightSource->setMaterial(&outdoorLight); | ||
|
||
// Create the camera | ||
CameraRayEmitterGroup camera; | ||
camera.setSamplingWidth(1); | ||
camera.setDirection(math::loadVector(-1.0, 0.0, 0.0)); | ||
camera.setPosition(math::loadVector(7.0, 2.0, 0.0)); | ||
camera.setUp(math::loadVector(0.0f, 1.0, 0.0)); | ||
camera.setPlaneDistance(1.0f); | ||
camera.setPlaneHeight(1.0f); | ||
camera.setResolutionX(resolutionX); | ||
camera.setResolutionY(resolutionY); | ||
camera.setSamplesPerPixel(samplesPerPixel); | ||
|
||
// Create the raytracer | ||
RayTracer rayTracer; | ||
rayTracer.initialize(500 * MB, 500 * MB, 12, 10000, true); | ||
rayTracer.setBackgroundColor(getColor(0, 0, 0)); | ||
rayTracer.traceAll(&scene, &camera); | ||
|
||
// Output the results to file | ||
math::Vector *pixels = (math::Vector *)_aligned_malloc(sizeof(math::Vector) * resolutionX * resolutionY, 16); | ||
|
||
for (int i = 0; i < resolutionY; i++) { | ||
for (int j = 0; j < resolutionX; j++) { | ||
math::Vector v = ((CameraRayEmitter *)(camera.getEmitters()[i * resolutionX + j]))->getIntensity(); | ||
math::real r = math::getX(v); | ||
math::real g = math::getY(v); | ||
math::real b = math::getZ(v); | ||
|
||
pixels[i * resolutionX + j] = v; | ||
} | ||
} | ||
|
||
// Clean everything up | ||
for (int i = camera.getEmitterCount() - 1; i >= 0; i--) { | ||
((CameraRayEmitter *)(camera.getEmitters()[i]))->destroyRays(); | ||
} | ||
|
||
SaveImageData(pixels, resolutionX, resolutionY, createUniqueRenderFilename(RENDER_OUTPUT, "cube_test", samplesPerPixel).c_str()); | ||
camera.destroyEmitters(); | ||
|
||
rayTracer.destroy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef DEMOS_H | ||
#define DEMOS_H | ||
|
||
#include <settings.h> | ||
|
||
// All required manta-ray includes | ||
#include <light_ray.h> | ||
#include <sphere_primitive.h> | ||
#include <intersection_point.h> | ||
#include <scene.h> | ||
#include <scene_object.h> | ||
#include <scene_geometry.h> | ||
#include <material.h> | ||
#include <simple_diffuse_material.h> | ||
#include <simple_specular_diffuse_material.h> | ||
#include <ray_tracer.h> | ||
#include <camera_ray_emitter_group.h> | ||
#include <camera_ray_emitter.h> | ||
#include <image_handling.h> | ||
#include <memory_management.h> | ||
#include <mesh.h> | ||
#include <obj_file_loader.h> | ||
#include <manta_math.h> | ||
#include <utils.h> | ||
|
||
namespace manta_demo { | ||
|
||
void simpleRoomDemo(int samplesPerPixel, int resolutionX, int resolutionY); | ||
void teapotDemo(int samplesPerPixel, int resolutionX, int resolutionY); | ||
void teapotLampDemo(int samplesPerPixel, int resolutionX, int resolutionY); | ||
void cubeTestDemo(int samplesPerPixel, int resolutionX, int resolutionY); | ||
|
||
} /* namespace manta_demo */ | ||
|
||
#endif /* DEMOS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <demos.h> | ||
|
||
using namespace manta_demo; | ||
|
||
int main() { | ||
simpleRoomDemo(10, 1024 * 2, 768 * 2); //1024, 768 | ||
//teapotDemo(1, 500, 500); | ||
//lampDemo(10, 1024*2, 768*2); // 10 for issue replication 1024, 768 | ||
//cubeTestDemo(1, 1024, 768); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef SETTINGS_H | ||
#define SETTINGS_H | ||
|
||
#define VISUAL_STUDIO 0x01 | ||
#define STANDALONE 0x02 | ||
|
||
#define EXECUTION_ENV VISUAL_STUDIO | ||
|
||
// Paths | ||
|
||
#if EXECUTION_ENV == VISUAL_STUDIO | ||
|
||
#define MODEL_PATH "../../demos/models/" | ||
#define RENDER_OUTPUT "../../workspace/render/" | ||
|
||
#elif EXECUTION_ENV == STANDALONE | ||
|
||
#error "Standalone execution environment not defined" | ||
|
||
#else | ||
|
||
#error "Undefined execution environment" | ||
|
||
#endif /* EXECUTION_ENV */ | ||
|
||
#endif /* CONF_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#include <demos.h> | ||
|
||
#include <iostream> | ||
|
||
using namespace manta; | ||
|
||
void manta_demo::simpleRoomDemo(int samplesPerPixel, int resolutionX, int resolutionY) { | ||
Scene scene; | ||
|
||
// Load all object files | ||
ObjFileLoader smallHouseObj; | ||
bool result = smallHouseObj.readObjFile(MODEL_PATH "small_house_unsealed.obj"); | ||
|
||
ObjFileLoader tableObj; | ||
result = tableObj.readObjFile(MODEL_PATH "table.obj"); | ||
|
||
ObjFileLoader shutterObj; | ||
result = shutterObj.readObjFile(MODEL_PATH "room_shutters.obj"); | ||
|
||
// Create all materials | ||
SimpleSpecularDiffuseMaterial wallMaterial; | ||
wallMaterial.setEmission(math::constants::Zero); | ||
wallMaterial.setDiffuseColor(getColor(200, 200, 200)); | ||
wallMaterial.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial outdoorLight; | ||
outdoorLight.setEmission(math::loadVector(18, 16, 16)); | ||
outdoorLight.setDiffuseColor(math::constants::Zero); | ||
outdoorLight.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial outdoorTopLightMaterial; | ||
outdoorTopLightMaterial.setEmission(math::loadVector(20, 20, 22)); | ||
outdoorTopLightMaterial.setDiffuseColor(math::constants::Zero); | ||
outdoorTopLightMaterial.setSpecularColor(math::constants::Zero); | ||
|
||
SimpleSpecularDiffuseMaterial tableMaterial; | ||
tableMaterial.setEmission(math::constants::Zero); | ||
tableMaterial.setDiffuseColor(getColor(78, 46, 40)); | ||
tableMaterial.setSpecularColor(getColor(100, 100, 100)); | ||
|
||
SimpleSpecularDiffuseMaterial groundMaterial; | ||
groundMaterial.setEmission(math::constants::Zero); | ||
groundMaterial.setDiffuseColor(math::mul(math::loadVector(78, 46, 40), math::loadScalar(0.001))); | ||
groundMaterial.setSpecularColor(math::constants::Zero); | ||
|
||
// Create all scene geometry | ||
Mesh smallHouse; | ||
smallHouse.loadObjFileData(&smallHouseObj); | ||
smallHouse.setFastIntersectEnabled(false); | ||
smallHouse.setFastIntersectRadius((math::real)4.0); | ||
|
||
Mesh table; | ||
table.loadObjFileData(&tableObj); | ||
table.setFastIntersectEnabled(false); | ||
table.setFastIntersectRadius((math::real)4.0); | ||
|
||
Mesh shutters; | ||
shutters.loadObjFileData(&shutterObj); | ||
shutters.setFastIntersectEnabled(false); | ||
shutters.setFastIntersectRadius((math::real)4.0); | ||
|
||
SpherePrimitive outdoorLightGeometry; | ||
outdoorLightGeometry.setRadius((math::real)10.0); | ||
outdoorLightGeometry.setPosition(math::loadVector(10.5, 0.0, -20.5)); | ||
|
||
SpherePrimitive outdoorTopLightGeometry; | ||
outdoorTopLightGeometry.setRadius((math::real)10.0); | ||
outdoorTopLightGeometry.setPosition(math::loadVector(0.0, 25.0, 2)); | ||
//outdoorTopLightGeometry.setPosition(math::loadVector(0.0, 4.0, 0)); | ||
//outdoorTopLightGeometry.setRadius((math::real)0.5); | ||
|
||
SpherePrimitive groundGeometry; | ||
groundGeometry.setRadius((math::real)50000.0); | ||
groundGeometry.setPosition(math::loadVector(0.0, -50000.1, 0)); | ||
|
||
// Create scene objects | ||
SceneObject *smallHouseObject = scene.createSceneObject(); | ||
smallHouseObject->setGeometry(&smallHouse); | ||
smallHouseObject->setMaterial(&wallMaterial); | ||
smallHouseObject->setName("House"); | ||
|
||
SceneObject *tableObject = scene.createSceneObject(); | ||
tableObject->setGeometry(&table); | ||
tableObject->setMaterial(&tableMaterial); | ||
tableObject->setName("Table"); | ||
|
||
//SceneObject *shuttersObject = scene.createSceneObject(); | ||
//shuttersObject->setGeometry(&shutters); | ||
//shuttersObject->setMaterial(&wallMaterial); | ||
//shuttersObject->setName("Shutters"); | ||
|
||
//SceneObject *ground = scene.createSceneObject(); | ||
//ground->setGeometry(&groundGeometry); | ||
//ground->setMaterial(&groundMaterial); | ||
|
||
//SceneObject *outdoorTopLightObject = scene.createSceneObject(); | ||
//outdoorTopLightObject->setGeometry(&outdoorTopLightGeometry); | ||
//outdoorTopLightObject->setMaterial(&outdoorTopLightMaterial); | ||
|
||
SceneObject *lightSource = scene.createSceneObject(); | ||
lightSource->setGeometry(&outdoorLightGeometry); | ||
lightSource->setMaterial(&outdoorLight); | ||
|
||
// Create the camera | ||
CameraRayEmitterGroup camera; | ||
camera.setSamplingWidth(1); | ||
camera.setDirection(math::loadVector(-1.0, 0.0, 0.0)); | ||
camera.setPosition(math::loadVector(5.0, 2.0, 0.0)); | ||
camera.setUp(math::loadVector(0.0f, 1.0, 0.0)); | ||
camera.setPlaneDistance(1.0f); | ||
camera.setPlaneHeight(1.0f); | ||
camera.setResolutionX(resolutionX); | ||
camera.setResolutionY(resolutionY); | ||
camera.setSamplesPerPixel(samplesPerPixel); | ||
|
||
// Create the raytracer | ||
RayTracer rayTracer; | ||
rayTracer.initialize(1000 * MB, 100 * MB, 12, 10000, true); | ||
rayTracer.setBackgroundColor(getColor(135, 206, 235)); | ||
rayTracer.setDeterministicSeedMode(true); | ||
rayTracer.traceAll(&scene, &camera); | ||
// Leaks | ||
//rayTracer.tracePixel(518, 101, &scene, &camera); | ||
//rayTracer.tracePixel(495, 122, &scene, &camera); | ||
//rayTracer.tracePixel(389, 188, &scene, &camera); | ||
//rayTracer.tracePixel(1441, 227, &scene, &camera); | ||
//rayTracer.tracePixel(459, 358, &scene, &camera); | ||
//rayTracer.tracePixel(1160, 566, &scene, &camera); | ||
//rayTracer.tracePixel(2020, 739, &scene, &camera); | ||
//rayTracer.tracePixel(1094, 910, &scene, &camera); | ||
//rayTracer.tracePixel(1829, 1402, &scene, &camera); | ||
//rayTracer.tracePixel(839, 1417, &scene, &camera); | ||
//rayTracer.tracePixel(2026, 1443, &scene, &camera); | ||
//rayTracer.tracePixel(1215, 1511, &scene, &camera); | ||
|
||
// Output the results to file | ||
math::Vector *pixels = (math::Vector *)_aligned_malloc(sizeof(math::Vector) * resolutionX * resolutionY, 16); | ||
|
||
for (int i = 0; i < resolutionY; i++) { | ||
for (int j = 0; j < resolutionX; j++) { | ||
math::Vector v = math::constants::Zero; | ||
|
||
if (camera.getEmitters()[i * resolutionX + j] != nullptr) { | ||
v = ((CameraRayEmitter *)(camera.getEmitters()[i * resolutionX + j]))->getIntensity(); | ||
math::real r = math::getX(v); | ||
math::real g = math::getY(v); | ||
math::real b = math::getZ(v); | ||
|
||
//if (r > 0.0 || g > 0.0 || b > 0.0) { | ||
// std::cout << "LEAK AT: " << j << ", " << i << std::endl; | ||
//} | ||
} | ||
|
||
pixels[i * resolutionX + j] = v; | ||
} | ||
} | ||
|
||
// Clean everything up | ||
for (int i = camera.getEmitterCount() - 1; i >= 0; i--) { | ||
if (camera.getEmitters()[i] != nullptr) { | ||
((CameraRayEmitter *)(camera.getEmitters()[i]))->destroyRays(); | ||
} | ||
} | ||
|
||
SaveImageData(pixels, resolutionX, resolutionY, createUniqueRenderFilename(RENDER_OUTPUT, "small_house_demo", samplesPerPixel).c_str()); | ||
camera.destroyEmitters(); | ||
|
||
rayTracer.destroy(); | ||
} |
Oops, something went wrong.