00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_MC_H
00024 #define LUX_MC_H
00025
00026
00027 #include "geometry/vector.h"
00028
00029
00030 namespace lux
00031 {
00032
00033 void RejectionSampleDisk(float u1, float u2, float *x, float *y);
00034 Vector UniformSampleHemisphere(float u1, float u2);
00035 float UniformHemispherePdf(float theta, float phi);
00036 Vector UniformSampleSphere(float u1, float u2);
00037 float UniformSpherePdf();
00038 Vector UniformSampleCone(float u1, float u2, float costhetamax);
00039 Vector UniformSampleCone(float u1, float u2, float costhetamax,
00040 const Vector &x, const Vector &y, const Vector &z);
00041 float UniformConePdf(float costhetamax);
00042 void UniformSampleDisk(float u1, float u2, float *x, float *y);
00043 void UniformSampleTriangle(float ud1, float ud2, float *u, float *v);
00044 Vector SampleHG(const Vector &w, float g, float u1, float u2);
00045 float HGPdf(const Vector &w, const Vector &wp, float g);
00046 void ComputeStep1dCDF(float *f, int nValues, float *c, float *cdf);
00047 float SampleStep1d(float *f, float *cdf, float c, int nSteps, float u,
00048 float *weight);
00049 void ConcentricSampleDisk(float u1, float u2, float *dx, float *dy);
00050
00051
00052 inline Vector CosineSampleHemisphere(float u1, float u2)
00053 {
00054 Vector ret;
00055 ConcentricSampleDisk(u1, u2, &ret.x, &ret.y);
00056 ret.z = sqrtf(max(0.f, 1.f - ret.x * ret.x - ret.y * ret.y));
00057 return ret;
00058 }
00059 inline float CosineHemispherePdf(float costheta, float phi) {
00060 return costheta * INV_PI;
00061 }
00062 inline float BalanceHeuristic(int nf, float fPdf, int ng, float gPdf)
00063 {
00064 return (nf * fPdf) / (nf * fPdf + ng * gPdf);
00065 }
00066 inline float PowerHeuristic(int nf, float fPdf, int ng, float gPdf)
00067 {
00068 float f = nf * fPdf, g = ng * gPdf;
00069 return (f * f) / (f * f + g * g);
00070 }
00071
00072 }
00073
00074 #endif // LUX_MC_H