108 lines
3.4 KiB
C++
108 lines
3.4 KiB
C++
|
|
#ifndef SCENE_H
|
|
#define SCENE_H SCENE_H
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include <stack>
|
|
|
|
#include "util/refptr.h"
|
|
#include "util/Ray.h"
|
|
#include "util/Color.h"
|
|
#include "util/Material.h"
|
|
|
|
#include "distrib/distrib.h"
|
|
|
|
#include "shapes/shapes.h"
|
|
|
|
#include "parser/parser.h"
|
|
#include "parser/nodes.h"
|
|
|
|
#include "Light.h"
|
|
|
|
#define SCENE_FACTOR_THRESHOLD 0.02
|
|
#define UNIT_TASK_SIZE 50
|
|
|
|
class Scene
|
|
{
|
|
public:
|
|
Scene(const std::map<std::string, const char *> & options,
|
|
const char * filename);
|
|
~Scene();
|
|
void render();
|
|
void setWidth(int width) { m_width = width; }
|
|
void setHeight(int height) { m_height = height; }
|
|
void setMultisampleLevel(int level) { m_multisample_level = level; }
|
|
void setVFOV(double vfov) { m_vfov = vfov; }
|
|
void setAmbientLight(const Color & al) { m_ambient_light = al; }
|
|
|
|
protected:
|
|
/* private methods */
|
|
void renderPixel(int x, int y, unsigned char * pixel);
|
|
Color traceRay(const Ray & ray);
|
|
Color traceRayRecurse(const Ray & ray, int depth, double factor);
|
|
Shape::Intersection getRayClosestHit(const Ray & ray);
|
|
Color computePhong(const refptr<Material> material,
|
|
const Ray & viewRay,
|
|
const Vector & surfacePoint,
|
|
const Vector & surfaceNormal);
|
|
Color calculateLightContribution(const Ray & toLight,
|
|
refptr<Light> light);
|
|
void taskLoop();
|
|
|
|
/* In Scene-load.cc */
|
|
void load(const char * filename);
|
|
void processNode(refptr<Node> node);
|
|
void processChildren(refptr<Node> node);
|
|
void processScene(refptr<Node> node);
|
|
refptr<Material> processMaterial(refptr<Node> node);
|
|
refptr<Shape> processBox(refptr<Node> node);
|
|
refptr<Shape> processCyl(refptr<Node> node);
|
|
refptr<Light> processLight(refptr<Node> node);
|
|
refptr<Shape> processPlane(refptr<Node> node);
|
|
refptr<Shape> processSphere(refptr<Node> node);
|
|
refptr<Shape> processShape(refptr<Node> node);
|
|
refptr<Shape> processBool(refptr<Node> node);
|
|
bool processTransforms(refptr<Node> node);
|
|
void processCamera(refptr<Node> node);
|
|
void processOptions(refptr<Node> node);
|
|
void processTransformBlock(refptr<Node> node);
|
|
void processMaterialDefinition(refptr<Node> node);
|
|
|
|
/* rendering parameters */
|
|
int m_width;
|
|
int m_height;
|
|
int m_multisample_level;
|
|
std::string m_output_file_name;
|
|
bool m_verbose;
|
|
double m_vfov;
|
|
Color m_ambient_light;
|
|
int m_max_depth;
|
|
|
|
/* private data */
|
|
std::vector< refptr<Shape> > m_shapes;
|
|
std::vector< refptr<Light> > m_lights;
|
|
std::stack<Transform> m_transforms;
|
|
double m_view_plane_dist;
|
|
int m_multisample_level_squared;
|
|
double m_sample_span;
|
|
double m_half_sample_span;
|
|
std::map< std::string, refptr<Material> > m_materials;
|
|
|
|
/* distribution infrastructure */
|
|
bool m_server;
|
|
std::string m_server_name;
|
|
std::string m_hosts_file;
|
|
int m_server_port;
|
|
distrib m_distrib;
|
|
std::vector<std::string> m_client_options;
|
|
|
|
/* framebuffer */
|
|
unsigned char * m_data;
|
|
};
|
|
|
|
#endif
|
|
|