Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfiniteAreaLight中使用AliasMethod的疑惑 #10

Open
hegaoxiang opened this issue May 31, 2022 · 0 comments
Open

InfiniteAreaLight中使用AliasMethod的疑惑 #10

hegaoxiang opened this issue May 31, 2022 · 0 comments

Comments

@hegaoxiang
Copy link

u聚,在这里InfiniteAreaLight初始化这里,sum不是要再除以(w*h)才等于贴图这个二维函数在定义域上的积分吗?如果这里不除的话,distribution中的值应该并不是pdf(i,j)吧,应该只是个分布,若是这样的话。好像u聚在AliasMethod却是直接把他当作pdf了。

	auto w = img->GetWidth();
	auto h = img->GetHeight();
	vector<double> distribution(w*h);
	double sum = 0.f;
	for (int y = 0; y < h; y++) {
		double sinTheta = sin(PI<float> * (y + 0.5) / static_cast<double>(h));
		for (int x = 0; x < w; x++) {
			int idx = img->xy2idx(x, y);
			distribution[idx] = sinTheta * img->GetPixel(x, y).to_rgb().illumination();
			sum += distribution[idx];
		}
	}

	for (auto & p : distribution)
		p /= sum;

	aliasMethod.Init(distribution);


......
void AliasMethod::Init(const vector<double> & distribution) {
	......
	for (int i = 0; i < num; i++) {
		// 默认设置为 i
		table[i].k = static_cast<int>(i);

		table[i].p = distribution[i];
		table[i].u = num * distribution[i];

		if (table[i].u < 1)
			underfulls.push_back(i);
		if (table[i].u > 1)
			overfulls.push_back(i);
	}

	......
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant