00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "beckmann.h"
00025 #include "color.h"
00026 #include "spectrum.h"
00027 #include "mc.h"
00028 #include "sampling.h"
00029 #include "bxdf.h"
00030 #include <stdarg.h>
00031
00032 using namespace lux;
00033
00034 Beckmann::Beckmann(float rms) {
00035 r = rms;
00036 }
00037
00038 float Beckmann::D(const Vector &wh) const {
00039 float costhetah = CosTheta(wh);
00040 float theta = acos(costhetah);
00041 float tanthetah = tan(theta);
00042
00043 float dfac = tanthetah / r;
00044
00045 return exp(-(dfac * dfac)) / (r * r * powf(costhetah, 4.0));
00046 }
00047
00048 void Beckmann::Sample_f(const Vector &wo, Vector *wi, float u1, float u2, float *pdf) const {
00049
00050
00051
00052 float theta = atan (sqrt (-(r * r) * log(1.0 - u1)));
00053 float costheta = cos (theta);
00054 float sintheta = sqrtf(max(0.f, 1.f - costheta*costheta));
00055 float phi = u2 * 2.f * M_PI;
00056
00057 Vector H = SphericalDirection(sintheta, costheta, phi);
00058
00059 if (!SameHemisphere(wo, H))
00060 H.z *= -1.f;
00061
00062
00063 *wi = -wo + 2.f * Dot(wo, H) * H;
00064
00065
00066
00067
00068
00069 float conversion_factor = 1.0 / (4.f * Dot(wo, H));
00070 float beckmann_pdf = conversion_factor * D(H);
00071
00072 *pdf = beckmann_pdf;
00073 }
00074
00075
00076 float Beckmann::Pdf(const Vector &wo, const Vector &wi) const {
00077 Vector H = Normalize(wo + wi);
00078 float conversion_factor = 1.0 / 4.f * Dot(wo, H);
00079 float beckmann_pdf = conversion_factor * D(H);
00080
00081 return beckmann_pdf;
00082 }
00083