当前位置: 首页>>代码示例>>C++>>正文


C++ Light::SampleL方法代码示例

本文整理汇总了C++中Light::SampleL方法的典型用法代码示例。如果您正苦于以下问题:C++ Light::SampleL方法的具体用法?C++ Light::SampleL怎么用?C++ Light::SampleL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Light的用法示例。


在下文中一共展示了Light::SampleL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Li

u_int SingleScattering::Li(const Scene &scene, const Ray &ray,
	const Sample &sample, SWCSpectrum *Lv, float *alpha) const
{
	*Lv = 0.f;
	Region *vr = scene.volumeRegion;
	float t0, t1;
	if (!vr || !vr->IntersectP(ray, &t0, &t1))
		return 0;
	// Do single scattering volume integration in _vr_
	// Prepare for volume integration stepping
	const float length = ray.d.Length();
	const u_int N = Ceil2UInt((t1 - t0) * length / stepSize);
	const float step = (t1 - t0) / N;
	const SpectrumWavelengths &sw(sample.swl);
	SWCSpectrum Tr(1.f);
	const Vector w(-ray.d / length);
	t0 += sample.sampler->GetOneD(sample, tauSampleOffset, 0) * step;
	Ray r(ray(t0), ray.d, 0.f, step, ray.time);
	const u_int nLights = scene.lights.size();
	const u_int lightNum = min(nLights - 1,
		Floor2UInt(sample.sampler->GetOneD(sample, scatterSampleOffset, 0) * nLights));
	Light *light = scene.lights[lightNum];

	// Compute sample patterns for single scattering samples
	// FIXME - use real samples
	float *samp = static_cast<float *>(alloca(3 * N * sizeof(float)));
	LatinHypercube(*(sample.rng), samp, N, 3);
	u_int sampOffset = 0;
	DifferentialGeometry dg;
	dg.p = r.o;
	dg.nn = Normal(w);
	for (u_int i = 0; i < N; ++i) {
		// Ray is already offset above, no need to do it again
		const SWCSpectrum stepTau(vr->Tau(sw, r, .5f * stepSize, 0.f));
		Tr *= Exp(-stepTau);
		// Possibly terminate raymarching if transmittance is small
		if (Tr.Filter(sw) < 1e-3f) {
			const float continueProb = .5f;
			if (sample.rng->floatValue() > continueProb)
				break; // TODO - REFACT - remove and add random value from sample
			Tr /= continueProb;
		}

		// Compute single-scattering source term at _p_
		*Lv += Tr * vr->Lve(sw, dg);

		if (nLights > 0) {
			const SWCSpectrum ss(vr->SigmaS(sw, dg));
			if (!ss.Black()) {
				// Add contribution of _light_ due to scattering at _p_
				float pdf;
				float u1 = samp[sampOffset], u2 = samp[sampOffset + 1],
					u3 = samp[sampOffset + 2];
				BSDF *ibsdf;
				SWCSpectrum L;
				if (light->SampleL(scene, sample, r.o, u1, u2, u3,
					&ibsdf, NULL, &pdf, &L)) {
					if (Connect(scene, sample, vr, true, false,
						r.o, ibsdf->dgShading.p, false, &L,
						NULL, NULL)) {
						const Vector wo(Normalize(r.o - ibsdf->dgShading.p));
						*Lv += Tr * ss * L *
							ibsdf->F(sw, Vector(ibsdf->dgShading.nn), wo, false) *
							(vr->P(sw, dg, w, wo) *
							nLights);
					}
				}
			}
		}
		sampOffset += 3;

		// Advance to sample at _t0_ and update _T_
		t0 += step;
		r.o = ray(t0);
		dg.p = r.o;
	}
	*Lv *= step * length;
	return light->group;
}
开发者ID:marwan-abdellah,项目名称:luxrender-lux,代码行数:79,代码来源:single.cpp


注:本文中的Light::SampleL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。