00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "cameras/orthographic.h"
00028 #include "paramset.h"
00029 #include "sampler.h"
00030 #include "montecarlo.h"
00031
00032
00033 OrthoCamera::OrthoCamera(const AnimatedTransform &cam2world,
00034 const float screenWindow[4], float sopen, float sclose,
00035 float lensr, float focald, Film *f)
00036 : ProjectiveCamera(cam2world, Orthographic(0., 1.), screenWindow,
00037 sopen, sclose, lensr, focald, f) {
00038
00039 dxCamera = RasterToCamera(Vector(1, 0, 0));
00040 dyCamera = RasterToCamera(Vector(0, 1, 0));
00041 }
00042
00043
00044 float OrthoCamera::GenerateRay(const CameraSample &sample, Ray *ray) const {
00045
00046 Point Pras(sample.imageX, sample.imageY, 0);
00047 Point Pcamera;
00048 RasterToCamera(Pras, &Pcamera);
00049 *ray = Ray(Pcamera, Vector(0,0,1), 0.f, INFINITY);
00050
00051 if (lensRadius > 0.) {
00052
00053 float lensU, lensV;
00054 ConcentricSampleDisk(sample.lensU, sample.lensV, &lensU, &lensV);
00055 lensU *= lensRadius;
00056 lensV *= lensRadius;
00057
00058
00059 float ft = focalDistance / ray->d.z;
00060 Point Pfocus = (*ray)(ft);
00061
00062
00063 ray->o = Point(lensU, lensV, 0.f);
00064 ray->d = Normalize(Pfocus - ray->o);
00065 }
00066 ray->time = Lerp(sample.time, shutterOpen, shutterClose);
00067 CameraToWorld(*ray, ray);
00068 return 1.f;
00069 }
00070
00071
00072 float OrthoCamera::GenerateRayDifferential(const CameraSample &sample,
00073 RayDifferential *ray) const {
00074
00075
00076
00077 Point Pras(sample.imageX, sample.imageY, 0);
00078 Point Pcamera;
00079 RasterToCamera(Pras, &Pcamera);
00080 *ray = RayDifferential(Pcamera, Vector(0,0,1), 0., INFINITY);
00081
00082
00083 if (lensRadius > 0.) {
00084
00085 float lensU, lensV;
00086 ConcentricSampleDisk(sample.lensU, sample.lensV, &lensU, &lensV);
00087 lensU *= lensRadius;
00088 lensV *= lensRadius;
00089
00090
00091 float ft = focalDistance / ray->d.z;
00092 Point Pfocus = (*ray)(ft);
00093
00094
00095 ray->o = Point(lensU, lensV, 0.f);
00096 ray->d = Normalize(Pfocus - ray->o);
00097 }
00098 ray->time = Lerp(sample.time, shutterOpen, shutterClose);
00099 ray->rxOrigin = ray->o + dxCamera;
00100 ray->ryOrigin = ray->o + dyCamera;
00101 ray->rxDirection = ray->ryDirection = ray->d;
00102 ray->hasDifferentials = true;
00103 CameraToWorld(*ray, ray);
00104 return 1.f;
00105 }
00106
00107
00108 OrthoCamera *CreateOrthographicCamera(const ParamSet ¶ms,
00109 const AnimatedTransform &cam2world, Film *film) {
00110
00111 float shutteropen = params.FindOneFloat("shutteropen", 0.f);
00112 float shutterclose = params.FindOneFloat("shutterclose", 1.f);
00113 float lensradius = params.FindOneFloat("lensradius", 0.f);
00114 float focaldistance = params.FindOneFloat("focaldistance", 1e30f);
00115 float frame = params.FindOneFloat("frameaspectratio",
00116 float(film->xResolution)/float(film->yResolution));
00117 float screen[4];
00118 if (frame > 1.f) {
00119 screen[0] = -frame;
00120 screen[1] = frame;
00121 screen[2] = -1.f;
00122 screen[3] = 1.f;
00123 }
00124 else {
00125 screen[0] = -1.f;
00126 screen[1] = 1.f;
00127 screen[2] = -1.f / frame;
00128 screen[3] = 1.f / frame;
00129 }
00130 int swi;
00131 const float *sw = params.FindFloat("screenwindow", &swi);
00132 if (sw && swi == 4)
00133 memcpy(screen, sw, 4*sizeof(float));
00134 return new OrthoCamera(cam2world, screen, shutteropen, shutterclose,
00135 lensradius, focaldistance, film);
00136 }
00137
00138