104 lines
3.7 KiB
C++
104 lines
3.7 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 "util/Polygon.h"
|
|
|
|
#include "shapes/shapes.h"
|
|
|
|
#include "parser/parser.h"
|
|
#include "parser/nodes.h"
|
|
|
|
#include "Light.h"
|
|
|
|
#define SCENE_FACTOR_THRESHOLD 0.02
|
|
|
|
class Scene
|
|
{
|
|
public:
|
|
Scene(const std::map<std::string, const char *> & options,
|
|
const char * filename);
|
|
~Scene();
|
|
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; }
|
|
void renderPixel(int x, int y, unsigned char * pixel);
|
|
void setMaxDepth(int d) { m_max_depth = d; }
|
|
int getWidth() { return m_width; }
|
|
int getHeight() { return m_height; }
|
|
int getMultisampleLevel() { return m_multisample_level; }
|
|
int getAmbientOcclusionLevel() { return m_ambient_occlusion_level; }
|
|
double getVFOV() { return m_vfov; }
|
|
int getMaxDepth() { return m_max_depth; }
|
|
|
|
protected:
|
|
/* private methods */
|
|
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,
|
|
const Vector & lightPosition);
|
|
Color calculateAmbientOcclusion(const Ray & surfaceNormal);
|
|
|
|
/* 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);
|
|
refptr<Shape> processExtrude(refptr<Node> node);
|
|
refptr<Polygon> processPolygon(refptr<Node> node);
|
|
refptr<Polygon> processNGon(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;
|
|
double m_vfov;
|
|
Color m_ambient_light;
|
|
int m_max_depth;
|
|
double m_exposure;
|
|
int m_ambient_occlusion_level;
|
|
|
|
/* 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;
|
|
};
|
|
|
|
#endif
|
|
|