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 "bxdf.h"
00026
00027 using namespace lux;
00028
00029
00030 WardIsotropic::WardIsotropic(float rms) {
00031 r = rms;
00032 }
00033
00034 float WardIsotropic::D(const Vector &wh) const {
00035 float costhetah = CosTheta(wh);
00036 float theta = acos(costhetah);
00037 float tanthetah = tan(theta);
00038
00039 float dfac = tanthetah / r;
00040
00041 return exp(-(dfac * dfac)) / (M_PI * r * r * powf(costhetah, 3.0));
00042 }
00043
00044 void WardIsotropic::Sample_f(const Vector &wo, Vector *wi, float u1, float u2, float *pdf) const {
00045
00046
00047 float theta = atan (r * sqrt (-log(1.0 - u1)));
00048 float costheta = cos (theta);
00049 float sintheta = sqrtf(max(0.f, 1.f - costheta*costheta));
00050 float phi = u2 * 2.f * M_PI;
00051
00052 Vector H = SphericalDirection(sintheta, costheta, phi);
00053
00054 if (!SameHemisphere(wo, H))
00055 H.z *= -1.f;
00056
00057
00058 *wi = -wo + 2.f * Dot(wo, H) * H;
00059
00060
00061
00062 float conversion_factor = 1.0 / (4.f * Dot(wo, H));
00063 float ward_pdf = conversion_factor * D(H);
00064
00065 *pdf = ward_pdf;
00066 }
00067
00068 float WardIsotropic::Pdf(const Vector &wo, const Vector &wi) const {
00069 Vector H = Normalize(wo + wi);
00070 float conversion_factor = 1.0 / 4.f * Dot(wo, H);
00071 float ward_pdf = conversion_factor * D(H);
00072
00073 return ward_pdf;
00074 }
00075