From 3f63dbeb077ad6cdc903509e6588a58d3383cd7d Mon Sep 17 00:00:00 2001 From: Cchen77 <1204918763@qq.com> Date: Sun, 21 Jul 2024 22:03:55 +0800 Subject: [PATCH] use cosin-weighted hemisphere sampling instead --- .../models/Mesh000.obj | 0 .../models/Mesh001.obj | 0 .../scene.json | 30 ++++++++--- .../textures/envmap.hdr | Bin .../textures/fangzexia.jpg | Bin .../textures/rustyMetal.jpg | Bin .../textures/tau0.png | Bin .../Material/BxDF/PorousLayerBxDF.cpp | 50 +++++++++++------- 8 files changed, 56 insertions(+), 24 deletions(-) rename scenes/{gold-teapot => micrograin-teapot}/models/Mesh000.obj (100%) rename scenes/{gold-teapot => micrograin-teapot}/models/Mesh001.obj (100%) rename scenes/{gold-teapot => micrograin-teapot}/scene.json (80%) rename scenes/{gold-teapot => micrograin-teapot}/textures/envmap.hdr (100%) rename scenes/{gold-teapot => micrograin-teapot}/textures/fangzexia.jpg (100%) rename scenes/{gold-teapot => micrograin-teapot}/textures/rustyMetal.jpg (100%) rename scenes/{gold-teapot => micrograin-teapot}/textures/tau0.png (100%) diff --git a/scenes/gold-teapot/models/Mesh000.obj b/scenes/micrograin-teapot/models/Mesh000.obj similarity index 100% rename from scenes/gold-teapot/models/Mesh000.obj rename to scenes/micrograin-teapot/models/Mesh000.obj diff --git a/scenes/gold-teapot/models/Mesh001.obj b/scenes/micrograin-teapot/models/Mesh001.obj similarity index 100% rename from scenes/gold-teapot/models/Mesh001.obj rename to scenes/micrograin-teapot/models/Mesh001.obj diff --git a/scenes/gold-teapot/scene.json b/scenes/micrograin-teapot/scene.json similarity index 80% rename from scenes/gold-teapot/scene.json rename to scenes/micrograin-teapot/scene.json index e7b3841f..45cef54e 100644 --- a/scenes/gold-teapot/scene.json +++ b/scenes/micrograin-teapot/scene.json @@ -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": { @@ -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, @@ -127,6 +145,6 @@ "spp_step": 16, "checkpoint_interval": "0", "timeout": "0", - "hdr_output_file": "dustteapot.exr" + "hdr_output_file": "micrograinTeapot.exr" } } \ No newline at end of file diff --git a/scenes/gold-teapot/textures/envmap.hdr b/scenes/micrograin-teapot/textures/envmap.hdr similarity index 100% rename from scenes/gold-teapot/textures/envmap.hdr rename to scenes/micrograin-teapot/textures/envmap.hdr diff --git a/scenes/gold-teapot/textures/fangzexia.jpg b/scenes/micrograin-teapot/textures/fangzexia.jpg similarity index 100% rename from scenes/gold-teapot/textures/fangzexia.jpg rename to scenes/micrograin-teapot/textures/fangzexia.jpg diff --git a/scenes/gold-teapot/textures/rustyMetal.jpg b/scenes/micrograin-teapot/textures/rustyMetal.jpg similarity index 100% rename from scenes/gold-teapot/textures/rustyMetal.jpg rename to scenes/micrograin-teapot/textures/rustyMetal.jpg diff --git a/scenes/gold-teapot/textures/tau0.png b/scenes/micrograin-teapot/textures/tau0.png similarity index 100% rename from scenes/gold-teapot/textures/tau0.png rename to scenes/micrograin-teapot/textures/tau0.png diff --git a/src/FunctionLayer/Material/BxDF/PorousLayerBxDF.cpp b/src/FunctionLayer/Material/BxDF/PorousLayerBxDF.cpp index 33156f4f..dc262bf0 100644 --- a/src/FunctionLayer/Material/BxDF/PorousLayerBxDF.cpp +++ b/src/FunctionLayer/Material/BxDF/PorousLayerBxDF.cpp @@ -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; }