Skip to content

Commit

Permalink
use cosin-weighted hemisphere sampling instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Cchen-77 committed Jul 21, 2024
1 parent 1800ce2 commit 3f63dbe
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@
"type":"porousLayerMicrograin",
"bulkMaterial":
{
"name":"plastic",
"albedo": 0.9,
"type" : "plastic"
"name":"conductor",
"type":"conductor",
"albedo":"textures/rustyMetal.jpg",
"eta":[2,2,2],
"k":[0,0,0],
"roughness":0.3,
"distribution":"ggx"
},
"micrograinType":"conductor",
"tau0":0.99,
"tau0":0.3,
"beta":0.8,
"R0":[0.588,0.294,0.001],
"k":[0,0,0]
},
{
"name":"conductor",
"type":"conductor",
"albedo":"textures/rustyMetal.jpg",
"eta":[2,2,2],
"k":[0,0,0],
"roughness":0.3,
"distribution":"ggx"
},
{
"name":"plastic",
"albedo":0.9,
"type":"plastic"
},
{
"name": "Floor",
"albedo": {
Expand Down Expand Up @@ -116,7 +134,7 @@
"enable_volume_light_sampling": true
},
"renderer": {
"output_file": "goldteapot",
"output_file": "micrograinTeapot",
"resume_render_file": "RenderState.dat",
"overwrite_output_files": false,
"adaptive_sampling": true,
Expand All @@ -127,6 +145,6 @@
"spp_step": 16,
"checkpoint_interval": "0",
"timeout": "0",
"hdr_output_file": "dustteapot.exr"
"hdr_output_file": "micrograinTeapot.exr"
}
}
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
50 changes: 32 additions & 18 deletions src/FunctionLayer/Material/BxDF/PorousLayerBxDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,46 @@ Spectrum PourousLayerBxDF::f(const Vec3d &out, const Vec3d &in) const {
double beta = micrograinBRDF->GetBeta();

double w = getMicrograinWeight(tau0, beta, CosTheta(in), CosTheta(out));
return micrograinBRDF->f(out, in) + (1. - w) * bulkBxDF->f(out, in);
return w * micrograinBRDF->f(out, in) + (1. - w) * bulkBxDF->f(out, in);
}

double PourousLayerBxDF::pdf(const Vec3d &out, const Vec3d &in) const {
double tau0 = micrograinBRDF->GetTau0();
double beta = micrograinBRDF->GetBeta();
/*double tau0 = micrograinBRDF->GetTau0();
double beta = micrograinBRDF->GetBeta();*/

// double w = getMicrograinWeight(tau0, beta, CosTheta(in), CosTheta(out));
double w = 0.5;
return micrograinBRDF->pdf(out, in) + (1. - w) * bulkBxDF->pdf(out, in);
// double w = getMicrograinWeight(tau0, beta, CosTheta(in), CosTheta(out));*/
/*double w = tau0;
return w * micrograinBRDF->pdf(out, in) + (1. - w) * bulkBxDF->pdf(out, in);*/

return CosTheta(in) / fm::pi_d;
}

BxDFSampleResult PourousLayerBxDF::sample(const Vec3d &out, const Point2d &sample) const {
double tau0 = micrograinBRDF->GetTau0();
double beta = micrograinBRDF->GetBeta();
// double tau0 = micrograinBRDF->GetTau0();
// double beta = micrograinBRDF->GetBeta();

////double w = getMicrograinWeight(tau0, beta, CosTheta(in), CosTheta(out));
// BxDFSampleResult result;
// double w = tau0;
// if (rand() * 1.0 / RAND_MAX < w) {
// result = micrograinBRDF->sample(out, sample);
// } else {
// result = bulkBxDF->sample(out, sample);

//}
// result.bxdfSampleType = BXDFType(BXDF_REFLECTION | BXDF_GLOSSY);
// result.s = f(out, result.directionIn);
// result.pdf = pdf(out, result.directionIn);
// return result;

double theta = fm::acos(fm::sqrt(1 - sample[0]));
double phi = 2 * fm::pi_d * sample[1];
Vec3d in = {fm::cos(phi) * fm::sin(theta), fm::sin(phi) * fm::sin(theta), fm::cos(theta)};

// double w = getMicrograinWeight(tau0, beta, CosTheta(in), CosTheta(out));
BxDFSampleResult result;
double w = 0.5;
if (rand() * 1.0 / RAND_MAX < w) {
result = micrograinBRDF->sample(out, sample);
} else {
result = bulkBxDF->sample(out, sample);
}
result.bxdfSampleType = BXDFType(BXDF_REFLECTION | BXDF_GLOSSY);
result.s = f(out, result.directionIn);
result.pdf = pdf(out, result.directionIn);
result.pdf = pdf(out, in);
result.s = f(out, in);
result.bxdfSampleType = BXDFType(BXDF_GLOSSY | BXDF_REFLECTION);
result.directionIn = in;
return result;
}

0 comments on commit 3f63dbe

Please sign in to comment.