gpt4 book ai didi

MIS path tracing got brighter image(遗漏路径跟踪图像变得更亮)

转载 作者:bug小助手 更新时间:2023-10-25 19:53:55 26 4
gpt4 key购买 nike



I am currently implementing a Path tracer, and I want to implement the Multiple importance sampling which use two distributions (Light and BRDF) at each bounce to evaluate direct lighting

我目前正在实现一个路径跟踪器,我想实现多重重要性采样,它在每次反弹时使用两个分布(Light和BRDF)来评估直接照明


This is my MIS implementation (implement in recursive funtion):

这是我的管理信息系统实现(以递归函数实现):


   vec3 TraceMISRecur(const Ray& WorldRay, int MaxDepth, std::vector<Object*>& World, Object* Lights) {
if (MaxDepth == 0) return vec3::Zero();
// direct integral, use light dis and brdf dis to approx
HitRecord Record;
bool Flag = HitClosest(WorldRay, Record, World);
if (!Flag) return vec3::Zero();
vec3 L_direct = vec3::Zero(), L_indirect = vec3::Zero();

vec3 LightSample;
float PdfOnLight;
vec3 LightColor;
vec3 LightNormal;
SampleLights(LightSample, PdfOnLight, LightColor, LightNormal, Lights);

vec3 SurfacePosition = Record.HitPoint;
vec3 Dir = LightSample - SurfacePosition;
float Distance = Dir.norm();
Dir.stableNormalize();
bool HitOtherObject = HitAny(Ray(SurfacePosition, Dir), World);
HitOtherObject |= LightNormal.dot(-Dir.stableNormalized()) < 0;
HitOtherObject |= Dir.dot(Record.Normal) < 0;
if (!HitOtherObject) {
float GFactor = GeometryFactor(SurfacePosition, LightSample, LightNormal);
float LightpdfOnHemisphere = PdfOnLight / GFactor;
vec3 BRDF = Record.Mat->BRDF(-WorldRay.B, Dir, Record);
float MatPdf = Record.Mat->PDF(-WorldRay.B, Dir, Record);
vec3 Le = LightColor;
float MISWeight = BalanceHuristic(LightpdfOnHemisphere, MatPdf);
L_direct += MISWeight * BRDF.cwiseProduct(Le) * Dir.dot(Record.Normal) / LightpdfOnHemisphere;
}

vec3 Wi = Record.Mat->Sample(-WorldRay.B, Record);
float MatPdf = Record.Mat->PDF(-WorldRay.B, Wi, Record);
vec3 BRDF = Record.Mat->BRDF(-WorldRay.B, Wi, Record);
HitRecord LightRecord;
bool HitLight = Lights->IntersectClosest(Ray(Record.HitPoint, Wi), LightRecord);

if (HitLight) {
float GFactor = GeometryFactor(SurfacePosition, LightRecord.HitPoint, LightRecord.Normal);
int LightIndex = LightRecord.PrimitiveIndex;
float LightArea = Lights->Primitives[LightIndex]->GetArea();
float LightpdfOnHemisphere = 1. / Lights->Primitives.size() / LightArea / GFactor;
vec3 Le = LightRecord.Mat->BRDF();
float MISWeight = BalanceHuristic(MatPdf, LightpdfOnHemisphere);
L_direct += MISWeight * BRDF.cwiseProduct(Le) * Wi.dot(Record.Normal) / MatPdf;
}

// indirect
L_indirect = BRDF.cwiseProduct(TraceMISRecur(Ray(Record.HitPoint, Wi), MaxDepth - 1, World, Lights)) * Wi.dot(Record.Normal) / MatPdf;
return L_direct + L_indirect;
}

This is my Brute force implementation (which I think can produce ground truth image):

这是我的蛮力实现(我认为它可以产生真实的图像):


    vec3 Trace(Ray &WorldRay, int MaxDepth, std::vector<Object*> &World) {
vec3 Background = vec3::Zero();
vec3 Throughput = vec3::Ones();
vec3 OutputRadiance = vec3::Zero();
HitRecord Record;
for (int i = 0; i < MaxDepth; i++) {
HitRecord Record;
bool Flag = HitClosest(WorldRay, Record, World);
if (!Flag) {
// currently, the env light not included in MIS
OutputRadiance += Throughput.cwiseProduct(Background);
return OutputRadiance;
}
int MaterialType = Record.Mat->MaterialType();
bool IsBackFace = Record.IsBackFace;
vec3 Wi = Record.Mat->Sample(WorldRay.B, Record);
float pdf = Record.Mat->PDF(WorldRay.B, Wi, Record);
vec3 BRDF = Record.Mat->BRDF(WorldRay.B, Wi, Record);
if (MaterialType == EMISSION) {
if (IsBackFace) return vec3::Zero();
OutputRadiance += Throughput.cwiseProduct(BRDF);
return OutputRadiance;
}
Throughput = Throughput.cwiseProduct(BRDF) * Wi.dot(Record.Normal) / pdf;
WorldRay = Ray(Record.HitPoint, Wi);
}
return vec3::Zero();
}

But when I compare the result of MIS to brute force, the MIS result is brigher, here is the comparision:

但当我将管理信息系统的结果与蛮力进行比较时,管理信息系统的结果更有说服力,下面是比较:


The MIS result (small light):

管理信息系统结果(小灯):


MIS


The brute force result (small light):

暴力效果(小光):


BF


The MIS result (larger light):

管理信息系统结果(较大的灯光):


MISLarge


The brute force result (larger light):

暴力的结果(更大的光):


BFLarge


I think there is something wrong with my MIS implementation, but I can't find it, Could you give me some hint? thanks.

我想我的管理信息系统的实施有问题,但我找不到,你能给我一些提示吗?谢谢。


更多回答
优秀答案推荐
更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com