Commit b4e1a1c4 authored by Jan Scheffczyk's avatar Jan Scheffczyk

Created new branch as tag for later refrence

parent 194896a8
......@@ -292,63 +292,13 @@ PerspectiveCamera *CreatePerspectiveCamera(const ParamSet &params,
bokehOptions.blades=edges;
initBokehVerts(bokehOptions);
int amount;
const float *optical = params.FindFloat("optVign",&amount);
if(optical) {
if (amount != 3) {
Error("optVign expects 2 variables. I distribution of vignetting 1 for linear distribution, 2 for quadratic...), II parameter controls the strength of the vignetting");
}
std::cout << "found something"<<std::endl;
bokehOptions.optical_d=optical[1];
bokehOptions.optical_s=optical[0];
bokehOptions.optical_radius=optical[2];
}else{ // defaults (deactivates optical vignetting)
bokehOptions.optical_d=-1.0f;
bokehOptions.optical_s=-1.0f;
bokehOptions.optical_radius=1.5f;
}
const float *shape = params.FindFloat("shape",&amount);
if(shape) {
if (amount != 2) {
Error("optVign expects 3 variables. I distribution of vignetting 1 for linear distribution, 2 for quadratic...), II parameter controls the strength of the vignetting");
}
bokehOptions.shape_s=shape[0];
bokehOptions.shape_d=shape[1];
}else{ // defaults (deactivates optical vignetting)
bokehOptions.shape_s=0.6f;
bokehOptions.shape_d=0.2f;
}
bokehOptions.innerRadius= params.FindOneFloat("innerRadius", 1.0);
bokehOptions.rateOfChange= params.FindOneFloat("rateOfChange", -2.0);
const float *bias = params.FindFloat("bias",&amount);
if(bias) {
if (amount != 2) {
Error("2 parameters, I: bias distribution as exponent of a gaus function, if negative 1-gauß is used. II strength");
}
bokehOptions.edgeOffset = params.FindOneFloat("edgeOffset",1.0);
bokehOptions.edgeStrength = params.FindOneFloat("edgeStrength",0.3);
bokehOptions.bias_d= bias[1];
bokehOptions.bias_s= bias[0];
}else{ // default vals
bokehOptions.bias_d= 0;
bokehOptions.bias_s=1;
}
const float *edge = params.FindFloat("edge",&amount);
if(edge) {
if (amount != 2) {
Error("2 Parameters, I: [0-1]clamp, 0.9 => outer 0.1 make up the edge. II: how pronounced the edge is [0-1] ");
}
bokehOptions.edge_d= edge[1];
bokehOptions.edge_s= edge[0];
}else{
bokehOptions.edge_d= 1.0;
bokehOptions.edge_s= 0.0;
}
......
......@@ -100,7 +100,7 @@ namespace pbrt {
void initBokehVerts(Bokeh &bokehOptions) {
int nVert = bokehOptions.blades;
if (nVert <= 3)
if (nVert < 3)
return;
bokehOptions.step = 2 * Pi / nVert;
bokehOptions.corners = std::unique_ptr<Point2f[]>(new Point2f[nVert]);
......
......@@ -58,18 +58,14 @@ namespace pbrt {
// also used as type
int blades = 0;
// strength and distribution of optical vignetting
float optical_s = 1;
float optical_d = 1;
float shape_s = 0.5;
float shape_d = 2;
float bias_d = 0;
float bias_s = 1;
float edge_d = 1;
float edge_s = 0.6;
float radius = 0.5;
float rateOfChange = 2;
// caches to avoid recalc
float step;
std::unique_ptr<Point2f[]> corners;
float optical_radius;
float innerRadius;
float edgeOffset;
float edgeStrength;
};
void initBokehVerts(Bokeh &bokehOptions);
......@@ -112,25 +108,27 @@ namespace pbrt {
Point2f ret = sample.pLens;
float quad = 0.0f;
float edge = 0.0f;
// return ConcentricSampleDisk(sample.pLens);
if (bokehOptions.blades >= 3) {
Float a = sample.pLens.x;
float xSample = sample.pLens.x;
int index = static_cast<int>(xSample*bokehOptions.blades);
index= std::min(index,2);
int index = static_cast<int>(xSample * bokehOptions.blades);
index = std::min(index, bokehOptions.blades - 1);
xSample = (xSample-(index* (1.0f/bokehOptions.blades)))*bokehOptions.blades;
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 = bokehOptions.corners[previous];
Point2f A = Point2f(0, 0);
Point2f B = bokehOptions.corners[index];
Point2f C = Point2f(0, 0);
Point2f C = bokehOptions.corners[previous];
// Float r1 = sample.pLens.x;
Float r1 = xSample;
......@@ -139,12 +137,17 @@ namespace pbrt {
// edge and bias?
ret = (1 - sqrt(r1)) * A + (sqrt(r1) * (1 - r2)) * B + (sqrt(r1) * r2) * C;
quad = (1-r2);
edge = (r1);
}// optical vignetting enabled
else if (bokehOptions.rateOfChange > -1.0f) {
float rateOfChange = bokehOptions.rateOfChange, radius = bokehOptions.innerRadius;
Point2f s = (2.f * sample.pLens - Vector2f(1, 1));
}
// optical vignetting enabled
else if (bokehOptions.optical_s > 0) {
Point2f sampleOffset = 2.f * sample.pLens - Vector2f(1, 1);
float c1 = s.x * s.x + s.y * s.y;
// convert film samples to [0-1] scale
Point2f ndc = sample.pFilm;
......@@ -154,66 +157,22 @@ namespace pbrt {
// convert to [-1,1]
ndc = 2.f * (ndc) - Vector2f(1, 1);
s.x += rateOfChange * ndc.x;
s.y += rateOfChange * ndc.y;
float c2 = s.x * s.x + s.y * s.y;
c2 *= radius; // shape
// 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 str = bokehOptions.optical_s;
float dist = Vector2f(ndc).Length();
float adist = dist;
// dist /= (str-1)*(str-1) +1.7f;
dist /= bokehOptions.optical_radius;
//distr
float distr = std::pow(0.1f + dist, bokehOptions.optical_d);
//shape
edge = std::max(c1, c2);
float shape_s = bokehOptions.shape_s;
float shape_d = std::exp(-bokehOptions.shape_d * adist * adist);;
float mult = 1 + str * 15;
float start = 40 * (1 - shape_s);
float end = 40 - start;
mult = 2.0f * std::pow(dist + 0.56f, 4) + 0.8;
// start=20.0f;
// end=20.0f;
if (yRot >= 0) {
quad = (xRot * xRot +
std::max(1.0f, (distr - 0.1f) * mult) * std::pow(yRot, (start + end * (shape_d)) / 20.0f));
} else {
quad = (xRot * xRot +
std::max(1.0f, (distr) * mult) *
std::pow(-yRot, ((start + 3) + (end - 3) * (shape_d)) / 20.0f));
}
// rejection sampling
if (quad > 1) {
// rejectionSampling
if (c1 > 1 || c2 > 1)
weight = 0.0f;
// bias
if(std::abs(bokehOptions.bias_d)>0.2f){
float b;
if(bokehOptions.bias_d<0){
float bias = -bokehOptions.bias_d;
b = std::exp(-bias*dist*dist);
b = 1-bokehOptions.bias_s*b;
}else{
b = bokehOptions.bias_s*std::exp(-bokehOptions.bias_d*dist*dist);
}
weight*=b;
}
ret = s;
}
} else { //default circle
Point2f uOffset = 2.f * sample.pLens - Vector2f(1, 1);
// Handle degeneracy at the origin
......@@ -230,14 +189,15 @@ namespace pbrt {
}
ret = r * Point2f(std::cos(theta), std::sin(theta));
quad = std::abs(r);
edge = std::abs(r);
}
// edge
if (quad < bokehOptions.edge_d) {
weight = 1.0f - bokehOptions.edge_s;
if (edge < bokehOptions.edgeOffset) {
weight += - bokehOptions.edgeStrength;
}
// 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