1. 程式人生 > >PBRT_V2 總結記錄 DensityRegion

PBRT_V2 總結記錄 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;

作用:

待續...