-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from NJUCG/thin_lens
Complete the thin-lens camera.
- Loading branch information
Showing
7 changed files
with
179 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
#include <cmath> | ||
#include "Thinlens.h" | ||
#include "CoreLayer/Math/Common.h" | ||
#include "FastMath.h" | ||
#include "CoreLayer/Math/Warp.h" | ||
|
||
#define _USE_MATH_DEFINES | ||
ThinlensCamera::ThinlensCamera(const Json &json) : PerspectiveCamera(json) { | ||
|
||
apertureRadius = getOptional(json, "aperture_radius", 0.1); | ||
focusDistance = getOptional(json, "focus_distance", 10); | ||
} | ||
|
||
Ray ThinlensCamera::generateRay(const Point2i &filmResolution, const Point2i &pixelPosition, const CameraSample &sample) const { | ||
double x = (double) (pixelPosition.x + sample.xy.x) / filmResolution.x, | ||
y = (double) (pixelPosition.y + sample.xy.y) / filmResolution.y; | ||
|
||
Point3d pointOnFilm = sampleToFilm * Point3d (x, y, 0), | ||
pointOnFocalPlane = pointOnFilm * (focalDistance / pointOnFilm.z); | ||
// TODO warp the sample transform | ||
float r = fm::sqrt(sample.lens[0]), | ||
theta = sample.lens[1] * 2 * M_PI; | ||
Point3d pointOnApeture = | ||
apertureRadius * Point3d(r * fm::cos(theta), r * fm::sin(theta), 0); | ||
Vec3d dir = normalize(pointOnFocalPlane - pointOnApeture); | ||
return Ray( | ||
cameraToWorld * pointOnApeture, | ||
cameraToWorld * dir | ||
); | ||
} | ||
double x = (double)(pixelPosition.x + sample.xy.x) / filmResolution.x; | ||
double y = (double)(pixelPosition.y + sample.xy.y) / filmResolution.y; | ||
|
||
Point3d pointOnFilm = sampleToFilm * Point3d(x, y, 0); | ||
Point3d pointOnFocalPlane = pointOnFilm * (focusDistance / pointOnFilm.z); | ||
|
||
Point2d pointOnDisk = apertureRadius * SquareToUniformDiskConcentric(sample.lens); | ||
Point3d pointOnAperture = {pointOnDisk.x, pointOnDisk.y, 0}; | ||
|
||
Vec3d dir = normalize(pointOnFocalPlane - pointOnAperture); | ||
|
||
return {cameraToWorld * pointOnAperture, cameraToWorld * dir}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.