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 "wardisotropic.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
00035 WardIsotropic::WardIsotropic(float rms) {
00036 r = rms;
00037 }
00038
00039 float WardIsotropic::D(const Vector &wh) const {
00040 float costhetah = CosTheta(wh);
00041 float theta = acos(costhetah);
00042 float tanthetah = tan(theta);
00043
00044 float dfac = tanthetah / r;
00045
00046 return exp(-(dfac * dfac)) / (M_PI * r * r * powf(costhetah, 3.0));
00047 }
00048
00049 void WardIsotropic::Sample_f(const Vector &wo, Vector *wi, float u1, float u2, float *pdf) const {
00050
00051
00052 float theta = atan (r * sqrt (-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 float conversion_factor = 1.0 / (4.f * Dot(wo, H));
00068 float ward_pdf = conversion_factor * D(H);
00069
00070 *pdf = ward_pdf;
00071 }
00072
00073 float WardIsotropic::Pdf(const Vector &wo, const Vector &wi) const {
00074 Vector H = Normalize(wo + wi);
00075 float conversion_factor = 1.0 / 4.f * Dot(wo, H);
00076 float ward_pdf = conversion_factor * D(H);
00077
00078 return ward_pdf;
00079 }
00080