Skip to content

Commit

Permalink
Changes in lectures 10 and 11.
Browse files Browse the repository at this point in the history
Added:
- Lights (we can have multiple lights).
- Light sampling (soft lights), used in RectLight.
- Depth-of-field (camera effect).
- Stereoscopy (camera effect), for use with anaglyph glasses.
  • Loading branch information
anrieff committed Jan 6, 2016
1 parent cc21d4a commit ddab323
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 77 deletions.
20 changes: 10 additions & 10 deletions data/boxed.qdmg
@@ -1,10 +1,10 @@
GlobalSettings {
frameWidth 640
frameHeight 480
ambientLight (0.075, 0.075, 0.075)
frameWidth 1024
frameHeight 768
//ambientLight (0.075, 0.075, 0.075)
ambientLight (0, 0, 0)
maxTraceDepth 8
lightPos (50, 50, -20)
lightIntensity 2048
wantAA false
}

Camera camera {
Expand All @@ -18,27 +18,27 @@ Camera camera {

//////////////////////// LIGHTS ////////////////////////////////////////////

/*

RectLight l2 {
xSubd 4
ySubd 4
translate (50, 50, -20)
scale (8, 8, 8)
color (1, 1, 1)
power 62.5
power 1100.5
rotate (0, 45, 0)
}

RectLight l_small {
translate (0, 28, 50)
rotate (0, -62, 0)
scale (10, 10, 10)
color (1, 1, 1)
power 40
color (1, 0.2, 1)
power 2000
xSubd 4
ySubd 4
}
*/


//////////////////////// GEOMETRIES ////////////////////////////////////////

Expand Down
197 changes: 197 additions & 0 deletions data/meshes.qdmg
@@ -0,0 +1,197 @@
//

// 1. First, some global settings
GlobalSettings {
frameWidth 1024
frameHeight 768
ambientLight (0.28, 0.30, 0.35)
maxTraceDepth 5
saturation 0.25
}

PointLight {
pos (160, 80, 40)
color (1, 1, 1)
power 10000
}

// 2. A camera
// (to enable the spherical lens camera (which introduces heavy spherical abberation)), replace "Camera" with "SphericalLensCamera"

Camera camera {
position (120, 22, 60)
yaw 11.46
pitch -15
roll 0.0
fov 90
aspectRatio 1.333
stereoSeparation 0.25 // comment this out to disable the stereoscopic effect
dof on
numSamples 100
fNumber 5.6
autofocus off
focalPlaneDist 21.48
}

/*
// top view
Camera camera {
pos (130, 85, 75)
yaw 11.46
pitch -90
roll 0.0
fov 90
aspect 1.333
}
*/

Plane floor {
y 0
limit 128
}

CheckerTexture checker {
color1 (0.5, 0.5, 0.25)
color2 (0.25, 0.25, 0.25)
scaling 0.75
}

Lambert floorShader {
color (1, 1, 1)
texture checker
}

// 3. A floor node, using a plane as a geometry, and a flat shader with a checker texture
Node floorNode {
geometry floor
shader floorShader
translate (100, 0, 96)
}


Mesh dice {
file "geom/truncated_cube.obj"
faceted true
}

BumpTexture diceBump {
file "texture/zar-bump.bmp"
strength 5
}

Mesh teapot {
file "geom/teapot_hires.obj"
}

Mesh wineglass {
file "geom/newwine.obj"
backfaceCulling false
}

CheckerTexture teapot_checker {
color1 (0.9, 0.1, 0.1)
color2 (0.05, 0.05, 0.07)
scaling 50
}

Lambert teapot_lambert {
color (1, 1, 1)
texture teapot_checker
}

Phong white_flat {
color (0.7, 0.7, 0.7)
specularExponent 200
}

Refl reflection {
multiplier 0.96
}

Layered teapot_layered {
layer teapot_lambert (1, 1, 1)
layer white_flat (0.16, 0.16, 0.16)
layer reflection (0.05, 0.07, 0.09)
}

BitmapTexture dice_texture {
file "texture/zar-texture.bmp"
}

Lambert flat {
color (1,1,1)
texture dice_texture
}

Refr refraction {
ior 1.5
multiplier 0.96
}

Fresnel fresnel {
ior 1.5
}

Layered glass {
layer refraction (1, 1, 1)
layer reflection (1, 1, 1) fresnel
}

Sphere ball {
R 0.5
}

Refl ball_sfc {
glossiness 0.92
numSamples 10
}

Node ball1 {
geometry ball
shader ball_sfc
translate (125.5, 19, 81)
}

Node ball2 {
geometry ball
shader ball_sfc
translate (126, 16, 80.7)
}

Node ball3 {
geometry ball
shader ball_sfc
translate (126.2, 12.5, 79.5)
}

Node wineglass {
geometry wineglass
//shader white_flat
shader glass
translate (126, 0, 80)
scale (17, 17, 17)
}

Node dice {
geometry dice
shader flat
translate (100, 10.1, 96)
rotate (63, 0, 0)
scale (2.5, 2.5, 2.5)
bump diceBump
}

Node teapotNode {
geometry teapot
shader teapot_layered
translate (110, 19, 90)
rotate (-27, 0, 30)
scale (7.5, 7.5, 7.5)
}



// 5. The cubemap environment:
CubemapEnvironment environment {
folder "env/forest"
}
10 changes: 4 additions & 6 deletions data/zaphod.qdmg
Expand Up @@ -13,17 +13,15 @@ GlobalSettings {
frameHeight 430
ambientLight (0.0, 0.0, 0.0)

lightPos (200, 200, -200) # Simulates my incadescent lamp in the center of the room
lightIntensity 100000
}

/*

PointLight l1 {
pos (200, 200, -200) # Simulates my incadescent lamp in the center of the room
power 100000
color (0.351, 0.332, 0.187) # Simulates the yellowish color of the incadescent lamp
}
*/


Camera camera {
position (1.5, 17, -19.5)
Expand All @@ -34,8 +32,8 @@ Camera camera {
aspectRatio 1.5
dof on
focalPlaneDist 25.29
fNumber 11 # This is also not quite correct, the actual aperture was f/2.0
numSamples 400
fNumber 2.0 # This is also not quite correct, the actual aperture was f/2.0
numSamples 100
}

//////////////////////// LIGHTS ////////////////////////////////////////////
Expand Down
42 changes: 41 additions & 1 deletion src/camera.cpp
Expand Up @@ -21,10 +21,14 @@
* @File camera.cpp
* @Brief Implementation of the raytracing camera.
*/
#include <algorithm>
#include "camera.h"
#include "matrix.h"
#include "util.h"
#include "sdl.h"
#include "geometry.h"
#include "scene.h"
using std::min;

void Camera::beginFrame()
{
Expand All @@ -51,12 +55,29 @@ void Camera::beginFrame()
topRight *= rotation;
bottomLeft *= rotation;

frontDir = Vector(0, 0, 1) * rotation;
upDir = Vector(0, 1, 0) * rotation;
rightDir = Vector(1, 0, 0) * rotation;

topLeft += this->position;
topRight += this->position;
bottomLeft += this->position;

if (autofocus) {
IntersectionInfo info;
double closest = 1e99;
Ray ray = getScreenRay(scene.settings.frameWidth / 2,
scene.settings.frameHeight / 2);
for (auto& node: scene.nodes) {
if (node->intersect(ray, info))
closest = min(closest, info.distance);
}
printf("Autofocus: found distance: %.2lf\n", closest);
focalPlaneDist = closest;
}
}

Ray Camera::getScreenRay(double xScreen, double yScreen)
Ray Camera::getScreenRay(double xScreen, double yScreen, int whichCamera)
{
Vector throughPoint =
topLeft + (topRight - topLeft) * (xScreen / frameWidth())
Expand All @@ -66,5 +87,24 @@ Ray Camera::getScreenRay(double xScreen, double yScreen)
ray.dir = throughPoint - this->position;
ray.dir.normalize();
ray.start = this->position;
if (whichCamera != CAMERA_CENTRAL) {
ray.start += (whichCamera == CAMERA_RIGHT ? +1 : -1) * stereoSeparation * rightDir;
}
return ray;
}

Ray Camera::getDOFRay(double xScreen, double yScreen, int whichCamera)
{
Ray ray = getScreenRay(xScreen, yScreen, whichCamera);
double cosTheta = dot(ray.dir, frontDir);
double M = focalPlaneDist / cosTheta;
Vector target = ray.start + ray.dir * M;

double u, v;
genDiscPoint(apertureSize, u, v);

ray.start = ray.start + u * upDir + v * rightDir;
ray.dir = target - ray.start;
ray.dir.normalize();
return ray;
}

0 comments on commit ddab323

Please sign in to comment.