Commit 1584180e authored by Jan Scheffczyk's avatar Jan Scheffczyk

Bokeh distribution and shape working

parent b4e1a1c4
This diff is collapsed.
......@@ -64,8 +64,9 @@ namespace pbrt {
float step;
std::unique_ptr<Point2f[]> corners;
float innerRadius;
float edgeOffset;
float edgeStrength;
int weightDistr;
float weightStrength;
float integral;
};
void initBokehVerts(Bokeh &bokehOptions);
......@@ -110,8 +111,6 @@ namespace pbrt {
Point2f ret = sample.pLens;
float edge = 0.0f;
// return ConcentricSampleDisk(sample.pLens);
if (bokehOptions.blades >= 3) {
Float a = sample.pLens.x;
......@@ -119,18 +118,14 @@ namespace pbrt {
float xSample = sample.pLens.x;
int index = static_cast<int>(xSample * bokehOptions.blades);
index = std::min(index, bokehOptions.blades - 1);
xSample = (xSample - (index * (1.0f / bokehOptions.blades))) * bokehOptions.blades;
// int index = int((sample.random - 0.000001f) * bokehOptions.blades);
int previous = index + 1 == bokehOptions.blades ? 0 : index + 1;
Point2f A = Point2f(0, 0);
Point2f B = bokehOptions.corners[index];
Point2f C = bokehOptions.corners[previous];
// Float r1 = sample.pLens.x;
Float r1 = xSample;
Float r2 = sample.pLens.y;
......@@ -140,37 +135,38 @@ namespace pbrt {
edge = (r1);
}// optical vignetting enabled
else if (bokehOptions.rateOfChange > -1.0f) {
else if (abs(bokehOptions.rateOfChange) > 0.002f) {
float rateOfChange = bokehOptions.rateOfChange, radius = bokehOptions.innerRadius;
Point2f s = (2.f * sample.pLens - Vector2f(1, 1));
float c1 = s.x * s.x + s.y * s.y;
Point2f s = ConcentricSampleDisk(sample.pLens);
// convert film samples to [0-1] scale
Point2f ndc = sample.pFilm;
ndc.x /= film->fullResolution.x;
ndc.y /= film->fullResolution.y;
ndc.y = 1.0f - ndc.y;
// convert to [-1,1]
ndc = 2.f * (ndc) - Vector2f(1, 1);
float res = std::max(film->fullResolution.x, film->fullResolution.y);
ndc.y = film->fullResolution.y - ndc.y;
ndc.y = ndc.y - film->fullResolution.y/2;
ndc.x = ndc.x - film->fullResolution.x/2;
ndc *=2;
ndc.x /= res;
ndc.y /= res;
s.x += rateOfChange * ndc.x;
s.y += rateOfChange * ndc.y;
float c2 = s.x * s.x + s.y * s.y;
c2 *= radius; // shape
// convert to [-1,1]
float c1 = s.x * s.x + s.y * s.y;
s.x -= rateOfChange * ndc.x;
s.y -= rateOfChange * ndc.y;
float c2 = s.x * s.x + s.y * s.y;
c2 *= radius; // shape
edge = std::max(c1, c2);
// rejectionSampling
if (c1 > 1 || c2 > 1)
weight = 0.0f;
if ( c2 > 1)
weight = -1.0e20f;
ret = s;
edge = std::max(c1, c2);
} else { //default circle
......@@ -192,11 +188,23 @@ namespace pbrt {
edge = std::abs(r);
}
// edge
if (edge < bokehOptions.edgeOffset) {
weight += - bokehOptions.edgeStrength;
float power = bokehOptions.weightStrength;
float distr = bokehOptions.weightDistr;
float intg = bokehOptions.integral;
if (distr < 0) {
edge= 1-edge;
distr= -distr;
power= -power;
}
float w = power * pow(edge, distr) + 1 - intg;
if (weight > 0) {
weight = w;
}
// default
return ret;
......
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