Commit 33862ea8 authored by Jan Scheffczyk's avatar Jan Scheffczyk

before adding new options

parent 2e55bb3b
......@@ -72,6 +72,7 @@ namespace pbrt {
Float PerspectiveCamera::GenerateRay(const CameraSample &sample,
Ray *ray) const {
ProfilePhase prof(Prof::GenerateCameraRay);
float weight = 1.0f;
// Compute raster and camera sample positions
Point3f pFilm = Point3f(sample.pFilm.x, sample.pFilm.y, 0);
Point3f pCamera = RasterToCamera(pFilm);
......@@ -81,7 +82,8 @@ Float PerspectiveCamera::GenerateRay(const CameraSample &sample,
if (lensRadius > 0) {
// Sample point on lens
Point2f pLens = lensRadius * biasSample(sample);
Point2f pLens = lensRadius * biasSample(sample, weight);
// Point2f pLens = lensRadius * ConcentricSampleDisk(sample.pLens);
// pLens= Point2f(1-pLens.x*pLens.x,1-pLens.y*pLens.y);
// Compute point on plane of focus
......@@ -95,12 +97,15 @@ Float PerspectiveCamera::GenerateRay(const CameraSample &sample,
ray->time = Lerp(sample.time, shutterOpen, shutterClose);
ray->medium = medium;
*ray = CameraToWorld(*ray);
return 1;
return weight;
}
Float PerspectiveCamera::GenerateRayDifferential(const CameraSample &sample,
RayDifferential *ray) const {
ProfilePhase prof(Prof::GenerateCameraRay);
float weight = 1.0f;
// Compute raster and camera sample positions
Point3f pFilm = Point3f(sample.pFilm.x, sample.pFilm.y, 0);
Point3f pCamera = RasterToCamera(pFilm);
......@@ -109,8 +114,10 @@ Float PerspectiveCamera::GenerateRayDifferential(const CameraSample &sample,
// Modify ray for depth of field
if (lensRadius > 0) {
// Sample point on lens
Point2f pLens = lensRadius * biasSample(sample);
pLens *= lensRadius;
Point2f pLens = lensRadius * biasSample(sample, weight);
// Point2f pLens = lensRadius * ConcentricSampleDisk(sample.pLens);
// Compute point on plane of focus
Float ft = focalDistance / ray->d.z;
Point3f pFocus = (*ray)(ft);
......@@ -118,14 +125,18 @@ Float PerspectiveCamera::GenerateRayDifferential(const CameraSample &sample,
// Update ray for effect of lens
ray->o = Point3f(pLens.x, pLens.y, 0);
ray->d = Normalize(pFocus - ray->o);
}
float dummy;
// Compute offset rays for _PerspectiveCamera_ ray differentials
if (lensRadius > 0) {
// Compute _PerspectiveCamera_ ray differentials accounting for lens
// Sample point on lens
Point2f pLens = lensRadius * biasSample(sample);
Point2f pLens = lensRadius * biasSample(sample,dummy );
// Point2f pLens = lensRadius * ConcentricSampleDisk(sample.pLens);
Vector3f dx = Normalize(Vector3f(pCamera + dxCamera));
Float ft = focalDistance / dx.z;
Point3f pFocus = Point3f(0, 0, 0) + (ft * dx);
......@@ -146,7 +157,7 @@ Float PerspectiveCamera::GenerateRayDifferential(const CameraSample &sample,
ray->medium = medium;
*ray = CameraToWorld(*ray);
ray->hasDifferentials = true;
return 1;
return weight;
}
Spectrum PerspectiveCamera::We(const Ray &ray, Point2f *pRaster2) const {
......
......@@ -680,7 +680,7 @@ Float RealisticCamera::GenerateRay(const CameraSample &sample, Ray *ray) const {
// Trace ray from _pFilm_ through lens system
Float exitPupilBoundsArea;
Point3f pRear = SampleExitPupil(Point2f(pFilm.x, pFilm.y), biasSample(sample),
Point3f pRear = SampleExitPupil(Point2f(pFilm.x, pFilm.y), ConcentricSampleDisk(sample.pLens),
&exitPupilBoundsArea);
Ray rFilm(pFilm, pRear - pFilm, Infinity,
Lerp(sample.time, shutterOpen, shutterClose));
......
......@@ -60,6 +60,7 @@ Camera::Camera(const AnimatedTransform &CameraToWorld, Float shutterOpen,
Float Camera::GenerateRayDifferential(const CameraSample &sample,
RayDifferential *rd) const {
Float wt = GenerateRay(sample, rd);
// Find camera ray after shifting one pixel in the $x$ direction
CameraSample sshift = sample;
sshift.pFilm.x++;
......@@ -99,6 +100,8 @@ Spectrum Camera::Sample_Wi(const Interaction &ref, const Point2f &u,
void Camera::initBokeh(int cornerAmount) {
bokehOptions.amount=cornerAmount;
if(cornerAmount<=0)
return;
bokehOptions.step = 2 * Pi / cornerAmount;
bokehOptions.corners = std::unique_ptr<Point2f[]>(new Point2f[cornerAmount]);
float cur = Pi / 2.0f;
......
......@@ -56,7 +56,7 @@ namespace pbrt {
struct Bokeh {
// also used as type
int amount;
int amount = 0;
float step;
std::unique_ptr<Point2f[]> corners;
};
......@@ -97,9 +97,8 @@ namespace pbrt {
Bokeh bokehOptions;
inline Point2f biasSample(const CameraSample &sample) const {
inline Point2f biasSample(const CameraSample &sample, float &weight) const {
// return ConcentricSampleDisk(sample.pLens);
if (bokehOptions.amount == 0)
return ConcentricSampleDisk(sample.pLens);
......@@ -114,29 +113,88 @@ namespace pbrt {
return Point2f(0, 0);
}
Float theta, r;
Float theta, r = 1.0;
if (std::abs(sampleOffset.x) > std::abs(sampleOffset.y)) {
// r = std::pow(std::abs(sampleOffset.x),1/3.0f);
r = sampleOffset.x;
r = std::exp(-4 * r * r) - std::exp(-4);
r = sampleOffset.x < 0 ? -1 + r : 1 - r;
theta = PiOver4 * (sampleOffset.y / sampleOffset.x);
} else {
// r = std::pow(std::abs(sampleOffset.y),1/3.0f);
r = sampleOffset.y;
r = std::exp(-4 * r * r) - std::exp(-4);
r = sampleOffset.y < 0 ? -1 + r : 1 - r;
theta = PiOver2 - PiOver4 * (sampleOffset.x / sampleOffset.y);
}
if (r <= -0.85)
r = -0.85;
if (r >= 0.85)
r = 0.85;
return r * Point2f(std::cos(theta), std::sin(theta));
}
if (bokehOptions.amount == -2) {
return Point2f(0, 0);
}
if (bokehOptions.amount == -3) {
Point2f sampleOffset = 2.f * sample.pLens - Vector2f(1, 1);
Point2f ndc = sample.pFilm;
ndc.x /= film->fullResolution.x;
ndc.y /= film->fullResolution.y;
ndc.y = 1.0f-ndc.y;
ndc = 2.f * (ndc) - Vector2f(1, 1);
// quadric major axis angle
float alpha = -std::atan2(ndc.y,ndc.x)+Pi*0.5f;
float cos = std::cos(alpha);
float sin = std::sin(alpha);
//rotate sample
float xRot = cos * sampleOffset.x - sin*sampleOffset.y;
float yRot = sin * sampleOffset.x + cos * sampleOffset.y;
float dist = Vector2f(ndc).Length();
dist /= 1.8f;
// dist = 1.0f- (std::exp(-4*dist*dist)-std::exp(-4));
// float quad= (xRot*xRot+ std::max(1.0f,dist*3)*yRot*yRot);
//
float quad=0.0f;
if(yRot>=0){
quad= (xRot*xRot+ std::max(1.0f,(dist-0.1f)*4)*std::pow(yRot,(25.0f+15.0f*(1-dist))/20.0f));
}
else{
quad= (xRot*xRot+ std::max(1.0f,(dist)*4)*std::pow(-yRot,(20.0f+20.0f*(1-dist))/20.0f));
}
if(quad>1){
weight=0.0f;
}
if(quad<0.9){
weight = 0.4f;
}
return sampleOffset;
}
if (bokehOptions.amount < 0) {
std::cerr << "not a valid option" << std::endl;
}
int index = int((sample.random - 0.000001f) * bokehOptions.amount);
......
......@@ -146,6 +146,7 @@ class FilmTile {
filterTableSize);
ify[y - p0.y] = std::min((int)std::floor(fy), filterTableSize - 1);
}
// std::cout << (p1.x - p0.x)* ( p1.y - p0.y) << std::endl;
for (int y = p0.y; y < p1.y; ++y) {
for (int x = p0.x; x < p1.x; ++x) {
// Evaluate filter value at $(x,y)$ pixel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment