Woo Scene updates...
This commit is contained in:
parent
c49457a817
commit
47ae52ed05
4 changed files with 258 additions and 224 deletions
|
@ -51,7 +51,6 @@ struct Camera
|
||||||
virtual basics::Ray PrimaryRay(const int x, const int width,
|
virtual basics::Ray PrimaryRay(const int x, const int width,
|
||||||
const int y, const int height) const = 0;
|
const int y, const int height) const = 0;
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual std::string GetTypeString() const;
|
virtual std::string GetTypeString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
311
src/scene.cc
311
src/scene.cc
|
@ -5,84 +5,123 @@
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <chrono>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#include "scene.hh"
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "log.hh"
|
#include "log.hh"
|
||||||
#include "object.h"
|
#include "object.hh"
|
||||||
#include "scene.h"
|
|
||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
#define LOG_NAME "scene"
|
#define LOG_NAME "scene"
|
||||||
#include "logModule.hh"
|
#include "logModule.hh"
|
||||||
|
|
||||||
using namespace charles;
|
|
||||||
|
using charles::basics::Ray;
|
||||||
|
using charles::basics::Vector4;
|
||||||
|
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::Scene --
|
||||||
|
*/
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
: width(640), height(480),
|
: mWidth(640),
|
||||||
|
mHeight(480),
|
||||||
mCamera(new PerspectiveCamera()),
|
mCamera(new PerspectiveCamera()),
|
||||||
max_depth(5),
|
mMaxDepth(5),
|
||||||
min_weight(1e-4),
|
mMinWeight(1e-6),
|
||||||
ambient(new AmbientLight()),
|
mAmbient(),
|
||||||
shapes(),
|
mObjects(),
|
||||||
lights(),
|
mLights(),
|
||||||
mStats(),
|
mStats(),
|
||||||
pixels(NULL)
|
mPixels(NULL)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::~Scene --
|
||||||
|
*/
|
||||||
Scene::~Scene()
|
Scene::~Scene()
|
||||||
{
|
{
|
||||||
mCamera.reset();
|
mCamera.reset();
|
||||||
|
|
||||||
if (ambient != NULL) {
|
mObjects.clear();
|
||||||
delete ambient;
|
|
||||||
}
|
|
||||||
|
|
||||||
shapes.clear();
|
for (PointLight *l : mLights) {
|
||||||
|
|
||||||
for (PointLight *l : lights) {
|
|
||||||
delete l;
|
delete l;
|
||||||
}
|
}
|
||||||
lights.clear();
|
mLights.clear();
|
||||||
|
|
||||||
if (pixels != NULL) {
|
if (mPixels != NULL) {
|
||||||
delete[] pixels;
|
delete[] mPixels;
|
||||||
_is_rendered = false;
|
mIsRendered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
Scene::is_rendered()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return _is_rendered;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
Scene::get_width()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
Scene::get_height()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::GetCamera --
|
* charles::Scene::IsRendered --
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
Scene::IsRendered()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mIsRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::GetWidth --
|
||||||
|
*/
|
||||||
|
UInt
|
||||||
|
Scene::GetWidth()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::SetWidth --
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Scene::SetWidth(UInt w)
|
||||||
|
{
|
||||||
|
mWidth = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::GetHeight --
|
||||||
|
*/
|
||||||
|
UInt
|
||||||
|
Scene::GetHeight()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::SetHeight --
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Scene::SetHeight(UInt h)
|
||||||
|
{
|
||||||
|
mHeight = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::GetCamera --
|
||||||
*/
|
*/
|
||||||
Camera::Ptr
|
Camera::Ptr
|
||||||
Scene::GetCamera()
|
Scene::GetCamera()
|
||||||
|
@ -93,63 +132,55 @@ Scene::GetCamera()
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::SetCamera --
|
* charles::Scene::SetCamera --
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Scene::SetCamera(Camera* camera)
|
Scene::SetCamera(Camera::Ptr camera)
|
||||||
{
|
{
|
||||||
mCamera.reset(camera);
|
mCamera = camera;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AmbientLight &
|
|
||||||
Scene::get_ambient()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return *ambient;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const Color *
|
|
||||||
Scene::get_pixels()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return pixels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* scene_load --
|
* charles::Scene::GetAmbient --
|
||||||
*
|
|
||||||
* Load scene objects into this Scene from the given file.
|
|
||||||
*/
|
*/
|
||||||
void
|
AmbientLight&
|
||||||
Scene::read(const std::string &filename)
|
Scene::GetAmbient()
|
||||||
{ }
|
{
|
||||||
|
return mAmbient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* scene_save --
|
* charles::Scene::GetPixels --
|
||||||
*
|
*/
|
||||||
* Write a rendered scene to the given file.
|
const Color*
|
||||||
|
Scene::GetPixels()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mPixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::Write --
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Scene::write(Writer &writer, const std::string &filename)
|
Scene::Write(Writer& writer,
|
||||||
|
const std::string& filename)
|
||||||
{
|
{
|
||||||
writer.write_scene(*this, filename);
|
writer.write_scene(*this, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::render --
|
* charles::Scene::Render --
|
||||||
*
|
|
||||||
* Render the given Scene.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Scene::render()
|
Scene::Render()
|
||||||
{
|
{
|
||||||
LOG_INFO << "Rendering scene with " << shapes.size() << " objects.";
|
LOG_INFO << "Rendering scene with " << mObjects.size() << " objects.";
|
||||||
printf("Rendering scene with %lu objects.\n", shapes.size());
|
printf("Rendering scene with %lu objects.\n", mObjects.size());
|
||||||
|
|
||||||
LogCamera();
|
LogCamera();
|
||||||
LogObjects();
|
LogObjects();
|
||||||
|
@ -157,23 +188,23 @@ Scene::render()
|
||||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||||
start = std::chrono::system_clock::now();
|
start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
pixels = new Color[width * height];
|
mPixels = new Color[mWidth * mHeight];
|
||||||
|
|
||||||
Ray primary_ray;
|
Ray primaryRay;
|
||||||
Vector3 o, d;
|
Vector4 o, d;
|
||||||
for (int y = 0; y < height; y++) {
|
for (UInt y = 0; y < mHeight; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (UInt x = 0; x < mWidth; x++) {
|
||||||
primary_ray = mCamera->compute_primary_ray(x, width, y, height);
|
primaryRay = mCamera->PrimaryRay(x, mWidth, y, mHeight);
|
||||||
mStats.primaryRays++;
|
mStats.primaryRays++;
|
||||||
Color c = trace_ray(primary_ray);
|
Color c = TraceRay(primaryRay);
|
||||||
pixels[y * width + x] = c;
|
mPixels[y * mWidth + x] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end = std::chrono::system_clock::now();
|
end = std::chrono::system_clock::now();
|
||||||
std::chrono::duration<float> seconds = end - start;
|
std::chrono::duration<Double> seconds = end - start;
|
||||||
|
|
||||||
_is_rendered = true;
|
mIsRendered = true;
|
||||||
|
|
||||||
printf("Rendering completed in %f seconds.\n\n", seconds.count());
|
printf("Rendering completed in %f seconds.\n\n", seconds.count());
|
||||||
LOG_INFO << "Rendering completed in " << seconds.count() << " seconds.";
|
LOG_INFO << "Rendering completed in " << seconds.count() << " seconds.";
|
||||||
|
@ -184,83 +215,77 @@ Scene::render()
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::add_shape --
|
* charles::Scene::AddObject --
|
||||||
*
|
|
||||||
* Add a shape to the scene.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Scene::add_shape(Object::Ptr shape)
|
Scene::AddObject(Object::Ptr obj)
|
||||||
{
|
{
|
||||||
shapes.push_back(shape);
|
mObjects.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::add_light --
|
* charles::Scene::AddLight --
|
||||||
*
|
|
||||||
* Add a light to the scene.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Scene::add_light(PointLight *light)
|
Scene::AddLight(PointLight* light)
|
||||||
{
|
{
|
||||||
lights.push_back(light);
|
mLights.push_back(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scene::trace_ray --
|
* charles::Scene::TraceRay --
|
||||||
*
|
|
||||||
* Trace the given ray through the scene, recursing until depth has been reached.
|
|
||||||
*/
|
*/
|
||||||
Color
|
Color
|
||||||
Scene::trace_ray(const Ray &ray,
|
Scene::TraceRay(const Ray &ray,
|
||||||
const int depth,
|
const int depth,
|
||||||
const float weight)
|
const Double weight)
|
||||||
{
|
{
|
||||||
if (depth >= max_depth || weight <= min_weight) {
|
if (depth >= mMaxDepth || weight <= mMinWeight) {
|
||||||
return Color::Black;
|
return Color::Black;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color out_color = Color::Black;
|
Color outColor = Color::Black;
|
||||||
Object::Ptr intersected_shape;
|
Object::Ptr intersectedObj;
|
||||||
TVector ts;
|
TVector ts;
|
||||||
Double nearest_t = INFINITY;
|
Double nearestT = INFINITY;
|
||||||
|
|
||||||
ts.reserve(2);
|
ts.reserve(2);
|
||||||
|
|
||||||
// Find intersections of this ray with objects in the scene.
|
// Find intersections of this ray with objects in the scene.
|
||||||
for (Object::Ptr s : shapes) {
|
for (Object::Ptr obj : mObjects) {
|
||||||
ts.clear();
|
ts.clear();
|
||||||
if (s->DoesIntersect(ray, ts, mStats)) {
|
if (obj->Intersect(ray, ts, mStats)) {
|
||||||
if (ts[0] < nearest_t) {
|
if (ts[0] < nearestT) {
|
||||||
intersected_shape = s;
|
intersectedObj = obj;
|
||||||
nearest_t = ts[0];
|
nearestT = ts[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was no intersection, return black.
|
// If there was no intersection, return black.
|
||||||
if (!intersected_shape) {
|
if (!intersectedObj) {
|
||||||
return out_color;
|
return outColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
Material& shape_material = intersected_shape->GetMaterial();
|
Material& material = intersectedObj->GetMaterial();
|
||||||
const Color& shape_color = shape_material.GetDiffuseColor();
|
const Color& shapeColor = material.GetDiffuseColor();
|
||||||
|
|
||||||
Vector3 intersection = ray.parameterize(nearest_t);
|
Vector4 intersection = ray.Parameterize(nearestT);
|
||||||
Vector3 normal = intersected_shape->compute_normal(intersection);
|
Vector4 normal = intersectedObj->Normal(intersection);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Diffuse lighting. (Shading, etc.)
|
* Diffuse lighting. (Shading, etc.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Vector3 light_direction;
|
Vector4 lightDirection;
|
||||||
Double ldotn, diffuse_level, ambient_level;
|
Double ldotn, diffuseLevel, ambientLevel;
|
||||||
Ray shadowRay;
|
Ray shadowRay;
|
||||||
|
|
||||||
for (PointLight *l : lights) {
|
for (PointLight *l : mLights) {
|
||||||
light_direction = (l->GetOrigin() - intersection).normalize();
|
lightDirection = (l->GetOrigin() - intersection).normalize();
|
||||||
ldotn = light_direction.dot(normal);
|
ldotn = lightDirection.Dot(normal);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: What is this even for? Removing it makes the darker showers
|
* TODO: What is this even for? Removing it makes the darker showers
|
||||||
|
@ -270,12 +295,12 @@ Scene::trace_ray(const Ray &ray,
|
||||||
ldotn = 0.0;
|
ldotn = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
diffuse_level = shape_material.GetDiffuseIntensity();
|
diffuseLevel = material.GetDiffuseIntensity();
|
||||||
ambient_level = 1.0 - diffuse_level;
|
ambientLevel = 1.0 - diffuseLevel;
|
||||||
|
|
||||||
shadowRay = Ray(intersection, light_direction);
|
shadowRay = Ray(intersection, lightDirection);
|
||||||
for (Object::Ptr s : shapes) {
|
for (Object::Ptr obj : mObjects) {
|
||||||
if (s == intersected_shape) {
|
if (obj == intersectedObj) {
|
||||||
/* Skip the intersected shape. */
|
/* Skip the intersected shape. */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -284,8 +309,8 @@ Scene::trace_ray(const Ray &ray,
|
||||||
|
|
||||||
/* Figure out if we're in shadow. */
|
/* Figure out if we're in shadow. */
|
||||||
ts.clear();
|
ts.clear();
|
||||||
if (s->DoesIntersect(shadowRay, ts, mStats)) {
|
if (obj->Intersect(shadowRay, ts, mStats)) {
|
||||||
diffuse_level = 0.0;
|
diffuseLevel = 0.0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,8 +318,8 @@ Scene::trace_ray(const Ray &ray,
|
||||||
/*
|
/*
|
||||||
* Compute basic Lambert diffuse shading for this object.
|
* Compute basic Lambert diffuse shading for this object.
|
||||||
*/
|
*/
|
||||||
out_color += shape_color * ( ambient_level * ambient->compute_color_contribution()
|
outColor += shapeColor * ( ambientLevel * mAmbient.compute_color_contribution()
|
||||||
+ diffuse_level * ldotn);
|
+ diffuseLevel * ldotn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -328,10 +353,13 @@ Scene::trace_ray(const Ray &ray,
|
||||||
out_color += specular_level * specular_color * reflection_color;
|
out_color += specular_level * specular_color * reflection_color;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return out_color;
|
return outColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::LogCamera --
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Scene::LogCamera()
|
Scene::LogCamera()
|
||||||
const
|
const
|
||||||
|
@ -341,7 +369,7 @@ Scene::LogCamera()
|
||||||
LOG_DEBUG << "BEGIN CAMERA";
|
LOG_DEBUG << "BEGIN CAMERA";
|
||||||
LOG_DEBUG << " type = " << c.GetTypeString();
|
LOG_DEBUG << " type = " << c.GetTypeString();
|
||||||
LOG_DEBUG << " origin = " << c.GetOrigin();
|
LOG_DEBUG << " origin = " << c.GetOrigin();
|
||||||
LOG_DEBUG << " direction = " << c.get_direction();
|
LOG_DEBUG << " direction = " << c.GetDirection();
|
||||||
LOG_DEBUG << " right = " << c.GetRight();
|
LOG_DEBUG << " right = " << c.GetRight();
|
||||||
LOG_DEBUG << " up = " << c.GetUp();
|
LOG_DEBUG << " up = " << c.GetUp();
|
||||||
LOG_DEBUG << " coordinate system is "
|
LOG_DEBUG << " coordinate system is "
|
||||||
|
@ -350,15 +378,20 @@ Scene::LogCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Scene::LogObjects --
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Scene::LogObjects()
|
Scene::LogObjects()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "BEGIN SCENE OBJECTS";
|
LOG_DEBUG << "BEGIN SCENE OBJECTS";
|
||||||
|
|
||||||
for (Object::Ptr obj : shapes) {
|
for (Object::Ptr obj : mObjects) {
|
||||||
LOG_DEBUG << " " << *obj;
|
LOG_DEBUG << " " << *obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG << "END SCENE OBJECTS";
|
LOG_DEBUG << "END SCENE OBJECTS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} /* namespace charles */
|
||||||
|
|
84
src/scene.h
84
src/scene.h
|
@ -1,84 +0,0 @@
|
||||||
/* scene.h
|
|
||||||
*
|
|
||||||
* Definition of the Scene class.
|
|
||||||
*
|
|
||||||
* Scenes are the top level object in charles. Scenes contain objects, lights, a camera,
|
|
||||||
* etc. and can be rendered to pixel data and written to a file.
|
|
||||||
*
|
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __SCENE_H__
|
|
||||||
#define __SCENE_H__
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
#include "basics.h"
|
|
||||||
#include "camera.h"
|
|
||||||
#include "object.h"
|
|
||||||
#include "stats.hh"
|
|
||||||
|
|
||||||
|
|
||||||
class AmbientLight;
|
|
||||||
class PointLight;
|
|
||||||
class Writer;
|
|
||||||
|
|
||||||
|
|
||||||
class Scene
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Scene();
|
|
||||||
~Scene();
|
|
||||||
|
|
||||||
bool is_rendered() const;
|
|
||||||
|
|
||||||
int get_width() const;
|
|
||||||
void set_width(int w) { width = w; }
|
|
||||||
int get_height() const;
|
|
||||||
void set_height(int h) { height = h; }
|
|
||||||
|
|
||||||
Camera::Ptr GetCamera() const;
|
|
||||||
void SetCamera(Camera* camera);
|
|
||||||
|
|
||||||
AmbientLight &get_ambient() const;
|
|
||||||
const Color *get_pixels() const;
|
|
||||||
|
|
||||||
void read(const std::string &filename);
|
|
||||||
void write(Writer &writer, const std::string &filename);
|
|
||||||
void render();
|
|
||||||
|
|
||||||
void add_shape(charles::Object::Ptr obj);
|
|
||||||
void add_light(PointLight *light);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Color trace_ray(const Ray &ray, const int depth = 0, const float weight = 1.0);
|
|
||||||
|
|
||||||
void LogCamera() const;
|
|
||||||
void LogObjects() const;
|
|
||||||
|
|
||||||
// Pixel dimensions of the image.
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
Camera::Ptr mCamera;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum
|
|
||||||
* specular weight to apply before giving up.
|
|
||||||
*/
|
|
||||||
int max_depth;
|
|
||||||
float min_weight;
|
|
||||||
|
|
||||||
// Scene objects.
|
|
||||||
AmbientLight *ambient;
|
|
||||||
std::list<charles::Object::Ptr> shapes;
|
|
||||||
std::list<PointLight *> lights;
|
|
||||||
|
|
||||||
// Rendering stats
|
|
||||||
charles::Stats mStats;
|
|
||||||
|
|
||||||
// Rendering output.
|
|
||||||
bool _is_rendered;
|
|
||||||
Color *pixels;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
86
src/scene.hh
Normal file
86
src/scene.hh
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/* scene.h
|
||||||
|
* vim: tw=80:
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SCENE_H__
|
||||||
|
#define __SCENE_H__
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "camera.hh"
|
||||||
|
#include "light.h"
|
||||||
|
#include "object.hh"
|
||||||
|
#include "stats.hh"
|
||||||
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
|
class Writer;
|
||||||
|
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenes are the top level object in charles. Scenes contain objects, lights, a
|
||||||
|
* camera, etc. and can be rendered to pixel data and written to a file.
|
||||||
|
*/
|
||||||
|
struct Scene
|
||||||
|
{
|
||||||
|
Scene();
|
||||||
|
~Scene();
|
||||||
|
|
||||||
|
UInt GetWidth() const;
|
||||||
|
void SetWidth(UInt w);
|
||||||
|
UInt GetHeight() const;
|
||||||
|
void SetHeight(UInt h);
|
||||||
|
|
||||||
|
Camera::Ptr GetCamera() const;
|
||||||
|
void SetCamera(Camera::Ptr camera);
|
||||||
|
|
||||||
|
void Write(Writer& writer, const std::string& filename);
|
||||||
|
|
||||||
|
void Render();
|
||||||
|
bool IsRendered() const;
|
||||||
|
const Color* GetPixels() const;
|
||||||
|
|
||||||
|
AmbientLight& GetAmbient();
|
||||||
|
void AddObject(Object::Ptr obj);
|
||||||
|
void AddLight(PointLight* light);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color TraceRay(const basics::Ray &ray,
|
||||||
|
const int depth = 0,
|
||||||
|
const Double weight = 1.0);
|
||||||
|
|
||||||
|
void LogCamera() const;
|
||||||
|
void LogObjects() const;
|
||||||
|
|
||||||
|
/** Pixel width */
|
||||||
|
UInt mWidth;
|
||||||
|
/** Pixel height */
|
||||||
|
UInt mHeight;
|
||||||
|
|
||||||
|
Camera::Ptr mCamera;
|
||||||
|
|
||||||
|
/** Maximum depth of the ray tree */
|
||||||
|
int mMaxDepth;
|
||||||
|
/** Minimum specular weight to apply before giving up */
|
||||||
|
float mMinWeight;
|
||||||
|
|
||||||
|
// Scene objects.
|
||||||
|
AmbientLight mAmbient;
|
||||||
|
std::list<charles::Object::Ptr> mObjects;
|
||||||
|
std::list<PointLight *> mLights;
|
||||||
|
|
||||||
|
// Rendering stats
|
||||||
|
charles::Stats mStats;
|
||||||
|
|
||||||
|
// Rendering output.
|
||||||
|
bool mIsRendered;
|
||||||
|
Color *mPixels;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace charles */
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue