PBRT_V2 总结记录 <57> DensityRegion

DensityRegion 类

class DensityRegion : public VolumeRegion {
public:
    // DensityRegion Public Methods
    DensityRegion(const Spectrum &sa, const Spectrum &ss, float gg,
                  const Spectrum &emit, const Transform &VolumeToWorld)
        : sig_a(sa), sig_s(ss), le(emit), g(gg),
          WorldToVolume(Inverse(VolumeToWorld)) { }
    virtual float Density(const Point &Pobj) const = 0;
    Spectrum sigma_a(const Point &p, const Vector &, float) const {
        return Density(WorldToVolume(p)) * sig_a;
    }
    Spectrum sigma_s(const Point &p, const Vector &, float) const {
        return Density(WorldToVolume(p)) * sig_s;
    }
    Spectrum sigma_t(const Point &p, const Vector &, float) const {
        return Density(WorldToVolume(p)) * (sig_a + sig_s);
    }
    Spectrum Lve(const Point &p, const Vector &, float) const {
        return Density(WorldToVolume(p)) * le;
    }
    float p(const Point &p, const Vector &w, const Vector &wp, float) const {
        return PhaseHG(w, wp, g);
    }
    Spectrum tau(const Ray &r, float stepSize, float offset) const;
protected:
    // DensityRegion Protected Data
    Spectrum sig_a, sig_s, le;
    float g;
    Transform WorldToVolume;
};

类的作用:

(这个类就是 考虑到 密度 到  volume 中)

The rest of the volume representations in this chapter are based on the assumption
that the underlying particles throughout the medium all have the same basic scattering
properties, but their density is spatially varying in the medium
.

One consequence(结论) of this
assumption is that it is possible to describe the volume scattering properties at a point as
the product of the density at that point and some baseline value. For example, we might
set the attenuation coefficient σt to have a base value of 0.2. In regions where the particle
density was 1, a σt value of 0.2 would be returned. If the particle density were 3, however,
a σt value of 0.6 would be the result.

 

1. 构造函数

    DensityRegion(const Spectrum &sa, const Spectrum &ss, float gg,
                  const Spectrum &emit, const Transform &VolumeToWorld)
        : sig_a(sa), sig_s(ss), le(emit), g(gg),
          WorldToVolume(Inverse(VolumeToWorld)) { }

作用:

(直接传入 sig_a, sig_s, le, g,g就时候phase function的g)

The DensityRegion constructor takes the basic values of the scattering properties and
stores them in corresponding member variables. Note that the interface specifies the
volume-to-world transformation, but the class instead stores the world-to-volume transformation.

 

2. virtual float Density(const Point &Pobj) const = 0;

作用:

(DensityRegion 的子类,必须要实现 DensityRegion::Density() 函数,这个其实就是密度函数,给一个 点,就会返回 这个点在 在 object space 对应的体积密度)

All DensityRegion implementations must implement the DensityRegion::Density()
method, which returns the volume’s density at the given point in object space. The density
is used to scale the basic scattering parameters, so it must be nonnegative everywhere.

 

3. Spectrum sigma_a(const Point &p, const Vector &, float) const

    Spectrum sigma_a(const Point &p, const Vector &, float) const {
        return Density(WorldToVolume(p)) * sig_a;
    }

作用:

(这里是  sig_a 是乘上 这个点的 体积密度的,需要注意下)

The DensityRegion::sigma_a() method is illustrative of how a DensityRegion works; it
scales DensityRegion::sig_a by the local density at the point. The other VolumeRegion
methods are similar and not shown here.

 

4.  float p(const Point &p, const Vector &w, const Vector &wp, float) const

    float p(const Point &p, const Vector &w, const Vector &wp, float) const {
        return PhaseHG(w, wp, g);
    }

作用:

(这里需要注意的是,p() 不需要 乘上 local destiry)

One exception is the DensityRegion::p() method, which does not scale the phase function’s
value by the local density. Variations in the amount of scattering from point to
point are already accounted for by the scaled σs values.

 

5. Spectrum tau(const Ray &r, float stepSize, float offset) const;


Spectrum DensityRegion::tau(const Ray &r, float stepSize,
                            float u) const {
    float t0, t1;
    float length = r.d.Length();
    if (length == 0.f) return 0.f;
    Ray rn(r.o, r.d / length, r.mint * length, r.maxt * length, r.time);
    if (!IntersectP(rn, &t0, &t1)) return 0.;
    Spectrum tau(0.);
    t0 += u * stepSize;
    while (t0 < t1) {
        tau += sigma_t(rn(t0), -rn.d, r.time);
        t0 += stepSize;
    }
    return tau * stepSize;
}

作用:

计算厚度

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值