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 long double normsinv(long double p);
00034
00035 void RejectionSampleDisk(float u1, float u2, float *x, float *y);
00036 Vector UniformSampleHemisphere(float u1, float u2);
00037 float UniformHemispherePdf(float theta, float phi);
00038 Vector UniformSampleSphere(float u1, float u2);
00039 float UniformSpherePdf();
00040 Vector UniformSampleCone(float u1, float u2, float costhetamax);
00041 Vector UniformSampleCone(float u1, float u2, float costhetamax,
00042 const Vector &x, const Vector &y, const Vector &z);
00043 float UniformConePdf(float costhetamax);
00044 void UniformSampleDisk(float u1, float u2, float *x, float *y);
00045 void UniformSampleTriangle(float ud1, float ud2, float *u, float *v);
00046 Vector SampleHG(const Vector &w, float g, float u1, float u2);
00047 float HGPdf(const Vector &w, const Vector &wp, float g);
00048 void ComputeStep1dCDF(float *f, int nValues, float *c, float *cdf);
00049 float SampleStep1d(float *f, float *cdf, float c, int nSteps, float u,
00050 float *weight);
00051 void ConcentricSampleDisk(float u1, float u2, float *dx, float *dy);
00052 float GaussianSampleDisk(float u1);
00053 float InverseGaussianSampleDisk(float u1);
00054 float ExponentialSampleDisk(float u1, int power);
00055 float InverseExponentialSampleDisk(float u1, int power);
00056 float TriangularSampleDisk(float u1);
00057 void HoneycombSampleDisk(float u1, float u2, float *dx, float *dy);
00058
00059
00060 inline Vector CosineSampleHemisphere(float u1, float u2)
00061 {
00062 Vector ret;
00063 ConcentricSampleDisk(u1, u2, &ret.x, &ret.y);
00064 ret.z = sqrtf(max(0.f, 1.f - ret.x * ret.x - ret.y * ret.y));
00065 return ret;
00066 }
00067 inline float CosineHemispherePdf(float costheta, float phi) {
00068 return costheta * INV_PI;
00069 }
00070 inline float BalanceHeuristic(int nf, float fPdf, int ng, float gPdf)
00071 {
00072 return (nf * fPdf) / (nf * fPdf + ng * gPdf);
00073 }
00074 inline float PowerHeuristic(int nf, float fPdf, int ng, float gPdf)
00075 {
00076 float f = nf * fPdf, g = ng * gPdf;
00077 return (f * f) / (f * f + g * g);
00078 }
00079
00080 }
00081
00082 #endif // LUX_MC_H