提交 ee103f37 编写于 作者: M Matt Pharr

RGBSpectrum renaming pass. No change to functionality.

RGBSpectrum -> RGBIlluminantSpectrum
RGBReflectanceSpectrum -> RGBSpectrum
SpectrumType::General -> SpectrumType::Illuminant
SpectrumType::Reflectance -> SpectrumType::General

(Infrastructure for issue #28)
上级 4426f455
......@@ -354,14 +354,14 @@ Float HairBxDF::PDF(Vector3f wo, Vector3f wi, TransportMode mode,
return pdf;
}
RGBSpectrum HairBxDF::SigmaAFromConcentration(Float ce, Float cp) {
RGBIlluminantSpectrum HairBxDF::SigmaAFromConcentration(Float ce, Float cp) {
RGB eumelaninSigmaA(0.419f, 0.697f, 1.37f);
RGB pheomelaninSigmaA(0.187f, 0.4f, 1.05f);
RGB sigma_a = ce * eumelaninSigmaA + cp * pheomelaninSigmaA;
#ifdef PBRT_IS_GPU_CODE
return RGBSpectrum(*RGBColorSpace_sRGB, sigma_a);
return RGBIlluminantSpectrum(*RGBColorSpace_sRGB, sigma_a);
#else
return RGBSpectrum(*RGBColorSpace::sRGB, sigma_a);
return RGBIlluminantSpectrum(*RGBColorSpace::sRGB, sigma_a);
#endif
}
......
......@@ -1194,7 +1194,7 @@ class HairBxDF {
BxDFFlags Flags() const { return BxDFFlags::GlossyReflection; }
PBRT_CPU_GPU
static RGBSpectrum SigmaAFromConcentration(Float ce, Float cp);
static RGBIlluminantSpectrum SigmaAFromConcentration(Float ce, Float cp);
PBRT_CPU_GPU
static SampledSpectrum SigmaAFromReflectance(const SampledSpectrum &c, Float beta_n,
const SampledWavelengths &lambda);
......
......@@ -109,7 +109,7 @@ PointLight *PointLight::Create(const Transform &renderFromLight, MediumHandle me
const RGBColorSpace *colorSpace, const FileLoc *loc,
Allocator alloc) {
SpectrumHandle I = parameters.GetOneSpectrum("I", &colorSpace->illuminant,
SpectrumType::General, alloc);
SpectrumType::Illuminant, alloc);
Float sc = parameters.GetOneFloat("scale", 1);
sc /= SpectrumToPhotometric(I);
......@@ -168,7 +168,7 @@ DistantLight *DistantLight::Create(const Transform &renderFromLight,
const RGBColorSpace *colorSpace, const FileLoc *loc,
Allocator alloc) {
SpectrumHandle L = parameters.GetOneSpectrum("L", &colorSpace->illuminant,
SpectrumType::General, alloc);
SpectrumType::Illuminant, alloc);
Float sc = parameters.GetOneFloat("scale", 1);
Point3f from = parameters.GetOnePoint3f("from", Point3f(0, 0, 0));
......@@ -331,7 +331,7 @@ SampledSpectrum ProjectionLight::Projection(const Vector3f &wl,
for (int c = 0; c < 3; ++c)
rgb[c] = image.LookupNearestChannel(st, c);
return scale * RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
return scale * RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
}
SampledSpectrum ProjectionLight::Phi(const SampledWavelengths &lambda) const {
......@@ -348,7 +348,8 @@ SampledSpectrum ProjectionLight::Phi(const SampledWavelengths &lambda) const {
for (int c = 0; c < 3; ++c)
rgb[c] = image.GetChannel({u, v}, c);
SampledSpectrum L = RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
SampledSpectrum L =
RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
sum += L * dwdA;
}
......@@ -376,7 +377,8 @@ LightLeSample ProjectionLight::SampleLe(const Point2f &u1, const Point2f &u2,
for (int c = 0; c < 3; ++c)
rgb[c] = image.LookupNearestChannel(p, c);
SampledSpectrum L = scale * RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
SampledSpectrum L =
scale * RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
return LightLeSample(L, ray, 1, pdfDir);
}
......@@ -526,7 +528,7 @@ GoniometricLight *GoniometricLight::Create(const Transform &renderFromLight,
const RGBColorSpace *colorSpace,
const FileLoc *loc, Allocator alloc) {
SpectrumHandle I = parameters.GetOneSpectrum("I", &colorSpace->illuminant,
SpectrumType::General, alloc);
SpectrumType::Illuminant, alloc);
Float sc = parameters.GetOneFloat("scale", 1);
Image image(alloc);
......@@ -634,7 +636,7 @@ SampledSpectrum DiffuseAreaLight::Phi(const SampledWavelengths &lambda) const {
RGB rgb;
for (int c = 0; c < 3; ++c)
rgb[c] = image.GetChannel({x, y}, c);
phi += RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
phi += RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
}
phi /= image.Resolution().x * image.Resolution().y;
......@@ -726,7 +728,7 @@ DiffuseAreaLight *DiffuseAreaLight::Create(const Transform &renderFromLight,
const FileLoc *loc, Allocator alloc,
const ShapeHandle shape) {
SpectrumHandle L =
parameters.GetOneSpectrum("L", nullptr, SpectrumType::General, alloc);
parameters.GetOneSpectrum("L", nullptr, SpectrumType::Illuminant, alloc);
Float scale = parameters.GetOneFloat("scale", 1);
bool twoSided = parameters.GetOneBool("twosided", false);
......@@ -904,7 +906,7 @@ SampledSpectrum ImageInfiniteLight::Phi(const SampledWavelengths &lambda) const
RGB rgb;
for (int c = 0; c < 3; ++c)
rgb[c] = image.GetChannel({u, v}, c, wrapMode);
sumL += RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
sumL += RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
}
}
// Integrating over the sphere, so 4pi for that. Then one more for Pi
......@@ -1039,7 +1041,7 @@ SampledSpectrum PortalImageInfiniteLight::Phi(const SampledWavelengths &lambda)
Float duv_dw;
(void)RenderFromImage(st, &duv_dw);
sumL += RGBSpectrum(*imageColorSpace, rgb).Sample(lambda) / duv_dw;
sumL += RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda) / duv_dw;
}
}
......@@ -1063,7 +1065,7 @@ SampledSpectrum PortalImageInfiniteLight::ImageLookup(
RGB rgb;
for (int c = 0; c < 3; ++c)
rgb[c] = image.LookupNearestChannel(st, c);
return scale * RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
return scale * RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
}
LightLiSample PortalImageInfiniteLight::SampleLi(LightSampleContext ctx, Point2f u,
......@@ -1304,7 +1306,7 @@ SpotLight *SpotLight::Create(const Transform &renderFromLight, MediumHandle medi
const RGBColorSpace *colorSpace, const FileLoc *loc,
Allocator alloc) {
SpectrumHandle I = parameters.GetOneSpectrum("I", &colorSpace->illuminant,
SpectrumType::General, alloc);
SpectrumType::Illuminant, alloc);
Float sc = parameters.GetOneFloat("scale", 1);
Float coneangle = parameters.GetOneFloat("coneangle", 30.);
......@@ -1397,7 +1399,7 @@ LightHandle LightHandle::Create(const std::string &name,
else if (name == "infinite") {
const RGBColorSpace *colorSpace = parameters.ColorSpace();
std::vector<SpectrumHandle> L =
parameters.GetSpectrumArray("L", SpectrumType::General, alloc);
parameters.GetSpectrumArray("L", SpectrumType::Illuminant, alloc);
Float scale = parameters.GetOneFloat("scale", 1);
std::vector<Point3f> portal = parameters.GetPoint3fArray("portal");
std::string filename = ResolveFilename(parameters.GetOneString("filename", ""));
......
......@@ -508,7 +508,7 @@ class DiffuseAreaLight : public LightBase {
RGB rgb;
for (int c = 0; c < 3; ++c)
rgb[c] = image.BilerpChannel(uv, c);
return scale * RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
return scale * RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
} else
return scale * Lemit.Sample(lambda);
}
......@@ -667,7 +667,7 @@ class ImageInfiniteLight : public LightBase {
RGB rgb;
for (int c = 0; c < 3; ++c)
rgb[c] = image.LookupNearestChannel(st, c, wrapMode);
return scale * RGBSpectrum(*imageColorSpace, rgb).Sample(lambda);
return scale * RGBIlluminantSpectrum(*imageColorSpace, rgb).Sample(lambda);
}
// ImageInfiniteLight Private Members
......
......@@ -38,7 +38,7 @@ DielectricMaterial *DielectricMaterial::Create(
const TextureParameterDictionary &parameters, const FileLoc *loc, Allocator alloc) {
FloatTextureHandle etaF = parameters.GetFloatTextureOrNull("eta", alloc);
SpectrumTextureHandle etaS =
parameters.GetSpectrumTextureOrNull("eta", SpectrumType::General, alloc);
parameters.GetSpectrumTextureOrNull("eta", SpectrumType::Illuminant, alloc);
if (etaF && etaS) {
Warning(loc, "Both \"float\" and \"spectrum\" variants of \"eta\" parameter "
"were provided. Ignoring the \"float\" one.");
......@@ -71,7 +71,7 @@ ThinDielectricMaterial *ThinDielectricMaterial::Create(
const TextureParameterDictionary &parameters, const FileLoc *loc, Allocator alloc) {
FloatTextureHandle etaF = parameters.GetFloatTextureOrNull("eta", alloc);
SpectrumTextureHandle etaS =
parameters.GetSpectrumTextureOrNull("eta", SpectrumType::General, alloc);
parameters.GetSpectrumTextureOrNull("eta", SpectrumType::Illuminant, alloc);
if (etaF && etaS) {
Warning(loc, "Both \"float\" and \"spectrum\" variants of \"eta\" parameter "
"were provided. Ignoring the \"float\" one.");
......@@ -126,9 +126,9 @@ std::string HairMaterial::ToString() const {
HairMaterial *HairMaterial::Create(const TextureParameterDictionary &parameters,
const FileLoc *loc, Allocator alloc) {
SpectrumTextureHandle sigma_a =
parameters.GetSpectrumTextureOrNull("sigma_a", SpectrumType::General, alloc);
parameters.GetSpectrumTextureOrNull("sigma_a", SpectrumType::Illuminant, alloc);
SpectrumTextureHandle color =
parameters.GetSpectrumTextureOrNull("color", SpectrumType::Reflectance, alloc);
parameters.GetSpectrumTextureOrNull("color", SpectrumType::General, alloc);
FloatTextureHandle eumelanin = parameters.GetFloatTextureOrNull("eumelanin", alloc);
FloatTextureHandle pheomelanin =
parameters.GetFloatTextureOrNull("pheomelanin", alloc);
......@@ -160,7 +160,8 @@ HairMaterial *HairMaterial::Create(const TextureParameterDictionary &parameters,
} else {
// Default: brown-ish hair.
sigma_a = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<RGBSpectrum>(HairBxDF::SigmaAFromConcentration(1.3, 0.)));
alloc.new_object<RGBIlluminantSpectrum>(
HairBxDF::SigmaAFromConcentration(1.3, 0.)));
}
FloatTextureHandle eta = parameters.GetFloatTexture("eta", 1.55f, alloc);
......@@ -181,7 +182,7 @@ std::string DiffuseMaterial::ToString() const {
DiffuseMaterial *DiffuseMaterial::Create(const TextureParameterDictionary &parameters,
const FileLoc *loc, Allocator alloc) {
SpectrumTextureHandle reflectance = parameters.GetSpectrumTexture(
"reflectance", nullptr, SpectrumType::Reflectance, alloc);
"reflectance", nullptr, SpectrumType::General, alloc);
if (!reflectance)
reflectance = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.5f));
......@@ -202,9 +203,9 @@ std::string ConductorMaterial::ToString() const {
ConductorMaterial *ConductorMaterial::Create(const TextureParameterDictionary &parameters,
const FileLoc *loc, Allocator alloc) {
SpectrumTextureHandle eta = parameters.GetSpectrumTexture(
"eta", GetNamedSpectrum("metal-Cu-eta"), SpectrumType::General, alloc);
"eta", GetNamedSpectrum("metal-Cu-eta"), SpectrumType::Illuminant, alloc);
SpectrumTextureHandle k = parameters.GetSpectrumTexture(
"k", GetNamedSpectrum("metal-Cu-k"), SpectrumType::General, alloc);
"k", GetNamedSpectrum("metal-Cu-k"), SpectrumType::Illuminant, alloc);
FloatTextureHandle uRoughness = parameters.GetFloatTextureOrNull("uroughness", alloc);
FloatTextureHandle vRoughness = parameters.GetFloatTextureOrNull("vroughness", alloc);
......@@ -232,7 +233,7 @@ std::string CoatedDiffuseMaterial::ToString() const {
CoatedDiffuseMaterial *CoatedDiffuseMaterial::Create(
const TextureParameterDictionary &parameters, const FileLoc *loc, Allocator alloc) {
SpectrumTextureHandle reflectance = parameters.GetSpectrumTexture(
"reflectance", nullptr, SpectrumType::Reflectance, alloc);
"reflectance", nullptr, SpectrumType::General, alloc);
if (!reflectance)
reflectance = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.5f));
......@@ -253,8 +254,8 @@ CoatedDiffuseMaterial *CoatedDiffuseMaterial::Create(
config.twoSided = parameters.GetOneBool("twosided", config.twoSided);
FloatTextureHandle g = parameters.GetFloatTexture("g", 0.f, alloc);
SpectrumTextureHandle albedo = parameters.GetSpectrumTexture(
"albedo", nullptr, SpectrumType::Reflectance, alloc);
SpectrumTextureHandle albedo =
parameters.GetSpectrumTexture("albedo", nullptr, SpectrumType::General, alloc);
if (!albedo)
albedo = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.f));
......@@ -300,18 +301,19 @@ CoatedConductorMaterial *CoatedConductorMaterial::Create(
if (!conductorVRoughness)
conductorVRoughness =
parameters.GetFloatTexture("conductor.roughness", 0.f, alloc);
SpectrumTextureHandle conductorEta = parameters.GetSpectrumTexture(
"conductor.eta", GetNamedSpectrum("metal-Cu-eta"), SpectrumType::General, alloc);
SpectrumTextureHandle conductorEta =
parameters.GetSpectrumTexture("conductor.eta", GetNamedSpectrum("metal-Cu-eta"),
SpectrumType::Illuminant, alloc);
SpectrumTextureHandle k = parameters.GetSpectrumTexture(
"conductor.k", GetNamedSpectrum("metal-Cu-k"), SpectrumType::General, alloc);
"conductor.k", GetNamedSpectrum("metal-Cu-k"), SpectrumType::Illuminant, alloc);
LayeredBxDFConfig config;
config.maxDepth = parameters.GetOneInt("maxdepth", config.maxDepth);
config.nSamples = parameters.GetOneInt("nsamples", config.nSamples);
FloatTextureHandle g = parameters.GetFloatTexture("g", 0.f, alloc);
SpectrumTextureHandle albedo = parameters.GetSpectrumTexture(
"albedo", nullptr, SpectrumType::Reflectance, alloc);
SpectrumTextureHandle albedo =
parameters.GetSpectrumTexture("albedo", nullptr, SpectrumType::General, alloc);
if (!albedo)
albedo = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.f));
......@@ -357,10 +359,10 @@ SubsurfaceMaterial *SubsurfaceMaterial::Create(
sigma_s = alloc.new_object<SpectrumConstantTexture>(sig_s);
} else {
// 2. sigma_a and sigma_s directly specified
sigma_a =
parameters.GetSpectrumTextureOrNull("sigma_a", SpectrumType::General, alloc);
sigma_s =
parameters.GetSpectrumTextureOrNull("sigma_s", SpectrumType::General, alloc);
sigma_a = parameters.GetSpectrumTextureOrNull("sigma_a", SpectrumType::Illuminant,
alloc);
sigma_s = parameters.GetSpectrumTextureOrNull("sigma_s", SpectrumType::Illuminant,
alloc);
if (sigma_a && !sigma_s)
ErrorExit(loc, "Provided \"sigma_a\" parameter without \"sigma_s\".");
if (sigma_s && !sigma_a)
......@@ -369,17 +371,19 @@ SubsurfaceMaterial *SubsurfaceMaterial::Create(
if (!sigma_a && !sigma_s) {
// 3. RGB/Spectrum, reflectance
reflectance = parameters.GetSpectrumTextureOrNull(
"reflectance", SpectrumType::Reflectance, alloc);
"reflectance", SpectrumType::General, alloc);
if (reflectance) {
SpectrumHandle one = alloc.new_object<ConstantSpectrum>(1.);
mfp = parameters.GetSpectrumTexture("mfp", one, SpectrumType::General,
mfp = parameters.GetSpectrumTexture("mfp", one, SpectrumType::Illuminant,
alloc);
} else {
// 4. nothing specified -- use defaults
RGBSpectrum *defaultSigma_a = alloc.new_object<RGBSpectrum>(
*RGBColorSpace::sRGB, RGB(.0011f, .0024f, .014f));
RGBSpectrum *defaultSigma_s = alloc.new_object<RGBSpectrum>(
*RGBColorSpace::sRGB, RGB(2.55f, 3.21f, 3.77f));
RGBIlluminantSpectrum *defaultSigma_a =
alloc.new_object<RGBIlluminantSpectrum>(*RGBColorSpace::sRGB,
RGB(.0011f, .0024f, .014f));
RGBIlluminantSpectrum *defaultSigma_s =
alloc.new_object<RGBIlluminantSpectrum>(*RGBColorSpace::sRGB,
RGB(2.55f, 3.21f, 3.77f));
sigma_a = alloc.new_object<SpectrumConstantTexture>(defaultSigma_a);
sigma_s = alloc.new_object<SpectrumConstantTexture>(defaultSigma_s);
}
......@@ -414,13 +418,13 @@ std::string DiffuseTransmissionMaterial::ToString() const {
DiffuseTransmissionMaterial *DiffuseTransmissionMaterial::Create(
const TextureParameterDictionary &parameters, const FileLoc *loc, Allocator alloc) {
SpectrumTextureHandle reflectance = parameters.GetSpectrumTexture(
"reflectance", nullptr, SpectrumType::Reflectance, alloc);
"reflectance", nullptr, SpectrumType::General, alloc);
if (!reflectance)
reflectance = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.25f));
SpectrumTextureHandle transmittance = parameters.GetSpectrumTexture(
"transmittance", nullptr, SpectrumType::Reflectance, alloc);
"transmittance", nullptr, SpectrumType::General, alloc);
if (!transmittance)
transmittance = alloc.new_object<SpectrumConstantTexture>(
alloc.new_object<ConstantSpectrum>(0.25f));
......
......@@ -119,9 +119,10 @@ bool GetMediumScatteringProperties(const std::string &name, SpectrumHandle *sigm
for (MeasuredSS &mss : SubsurfaceParameterTable) {
if (name == mss.name) {
*sigma_a = alloc.new_object<RGBSpectrum>(*RGBColorSpace::sRGB, mss.sigma_a);
*sigma_s =
alloc.new_object<RGBSpectrum>(*RGBColorSpace::sRGB, mss.sigma_prime_s);
*sigma_a = alloc.new_object<RGBIlluminantSpectrum>(*RGBColorSpace::sRGB,
mss.sigma_a);
*sigma_s = alloc.new_object<RGBIlluminantSpectrum>(*RGBColorSpace::sRGB,
mss.sigma_prime_s);
return true;
}
}
......@@ -151,20 +152,20 @@ HomogeneousMedium *HomogeneousMedium::Create(const ParameterDictionary &paramete
Warning(loc, "Material preset \"%s\" not found.", preset);
}
if (sig_a == nullptr) {
sig_a =
parameters.GetOneSpectrum("sigma_a", nullptr, SpectrumType::General, alloc);
sig_a = parameters.GetOneSpectrum("sigma_a", nullptr, SpectrumType::Illuminant,
alloc);
if (sig_a == nullptr)
sig_a = alloc.new_object<ConstantSpectrum>(1.f);
}
if (sig_s == nullptr) {
sig_s =
parameters.GetOneSpectrum("sigma_s", nullptr, SpectrumType::General, alloc);
sig_s = parameters.GetOneSpectrum("sigma_s", nullptr, SpectrumType::Illuminant,
alloc);
if (sig_s == nullptr)
sig_s = alloc.new_object<ConstantSpectrum>(1.f);
}
SpectrumHandle Le =
parameters.GetOneSpectrum("Le", nullptr, SpectrumType::General, alloc);
parameters.GetOneSpectrum("Le", nullptr, SpectrumType::Illuminant, alloc);
if (Le == nullptr)
Le = alloc.new_object<ConstantSpectrum>(0.f);
......@@ -227,7 +228,7 @@ UniformGridMediumProvider *UniformGridMediumProvider::Create(
rgbDensityGrid = SampledGrid<RGB>(rgbDensity, nx, ny, nz, alloc);
SpectrumHandle Le =
parameters.GetOneSpectrum("Le", nullptr, SpectrumType::General, alloc);
parameters.GetOneSpectrum("Le", nullptr, SpectrumType::Illuminant, alloc);
if (Le == nullptr)
Le = alloc.new_object<ConstantSpectrum>(0.f);
......
......@@ -292,14 +292,14 @@ class CuboidMedium {
}
if (sig_a == nullptr) {
sig_a = parameters.GetOneSpectrum("sigma_a", nullptr,
SpectrumType::Reflectance, alloc);
sig_a = parameters.GetOneSpectrum("sigma_a", nullptr, SpectrumType::General,
alloc);
if (sig_a == nullptr)
sig_a = alloc.new_object<ConstantSpectrum>(1.f);
}
if (sig_s == nullptr) {
sig_s = parameters.GetOneSpectrum("sigma_s", nullptr,
SpectrumType::Reflectance, alloc);
sig_s = parameters.GetOneSpectrum("sigma_s", nullptr, SpectrumType::General,
alloc);
if (sig_s == nullptr)
sig_s = alloc.new_object<ConstantSpectrum>(1.f);
}
......@@ -357,7 +357,7 @@ class UniformGridMediumProvider {
return SampledSpectrum(densityGrid->Lookup(pp));
else {
RGB rgb = rgbDensityGrid->Lookup(pp);
return RGBSpectrum(*colorSpace, rgb).Sample(lambda);
return RGBIlluminantSpectrum(*colorSpace, rgb).Sample(lambda);
}
}
......@@ -395,7 +395,7 @@ class UniformGridMediumProvider {
if (maxComponent == 0)
continue;
RGBSpectrum spec(*colorSpace, rgb);
RGBIlluminantSpectrum spec(*colorSpace, rgb);
maxDensity = std::max(maxDensity, spec.MaxValue());
}
......
......@@ -378,20 +378,20 @@ std::vector<SpectrumHandle> ParameterDictionary::extractSpectrumArray(
RGB rgb(v[0], v[1], v[2]);
const RGBColorSpace &cs =
param.colorSpace ? *param.colorSpace : *colorSpace;
if (spectrumType == SpectrumType::Reflectance) {
if (spectrumType == SpectrumType::General) {
if (std::min({v[0], v[1], v[2]}) < 0 ||
std::max({v[0], v[1], v[2]}) > 1)
ErrorExit(&param.loc,
"RGB reflectance parameter \"%s\" has "
"parameter outside of [0,1].",
param.name);
return alloc.new_object<RGBReflectanceSpectrum>(cs, rgb);
return alloc.new_object<RGBSpectrum>(cs, rgb);
} else {
CHECK(spectrumType == SpectrumType::General);
CHECK(spectrumType == SpectrumType::Illuminant);
if (std::min({v[0], v[1], v[2]}) < 0)
ErrorExit(&param.loc,
"RGB parameter \"%s\" has negative component value.");
return alloc.new_object<RGBSpectrum>(cs, rgb);
return alloc.new_object<RGBIlluminantSpectrum>(cs, rgb);
}
});
else if (param.type == "blackbody")
......@@ -800,7 +800,7 @@ SpectrumTextureHandle TextureParameterDictionary::GetSpectrumTexture(
SpectrumTextureHandle TextureParameterDictionary::GetSpectrumTextureOrNull(
const std::string &name, SpectrumType spectrumType, Allocator alloc) const {
const auto &spectrumTextures = (spectrumType == SpectrumType::Reflectance)
const auto &spectrumTextures = (spectrumType == SpectrumType::General)
? textures->spectrumReflectanceTextureMap
: textures->spectrumGeneralTextureMap;
......@@ -838,11 +838,11 @@ SpectrumTextureHandle TextureParameterDictionary::GetSpectrumTextureOrNull(
"Negative value provided for \"rgb\" parameter \"%s\".",
p->name);
SpectrumHandle s;
if (spectrumType == SpectrumType::General)
s = alloc.new_object<RGBSpectrum>(*dict->ColorSpace(), rgb);
if (spectrumType == SpectrumType::Illuminant)
s = alloc.new_object<RGBIlluminantSpectrum>(*dict->ColorSpace(), rgb);
else {
CHECK(spectrumType == SpectrumType::Reflectance);
s = alloc.new_object<RGBReflectanceSpectrum>(*dict->ColorSpace(), rgb);
CHECK(spectrumType == SpectrumType::General);
s = alloc.new_object<RGBSpectrum>(*dict->ColorSpace(), rgb);
}
return alloc.new_object<SpectrumConstantTexture>(s);
} else if (p->type == "spectrum" || p->type == "blackbody") {
......
......@@ -40,7 +40,7 @@ enum class ParameterType {
};
// SpectrumType Definition
enum class SpectrumType { Reflectance, General };
enum class SpectrumType { General, Illuminant };
// SceneTextures Definition
struct SceneTextures {
......
......@@ -876,11 +876,11 @@ SceneTextures ParsedScene::CreateTextures(Allocator alloc, bool gpu) const {
// nullptr for the textures, as above.
TextureParameterDictionary texDict(&tex.second.parameters, nullptr);
SpectrumTextureHandle reflectanceTex = SpectrumTextureHandle::Create(
tex.second.texName, renderFromTexture, texDict, SpectrumType::Reflectance,
tex.second.texName, renderFromTexture, texDict, SpectrumType::General,
&tex.second.loc, alloc, gpu);
// This one should be fast since it should hit the texture cache
SpectrumTextureHandle generalTex = SpectrumTextureHandle::Create(
tex.second.texName, renderFromTexture, texDict, SpectrumType::General,
tex.second.texName, renderFromTexture, texDict, SpectrumType::Illuminant,
&tex.second.loc, alloc, gpu);
std::lock_guard<std::mutex> lock(mutex);
......@@ -909,10 +909,10 @@ SceneTextures ParsedScene::CreateTextures(Allocator alloc, bool gpu) const {
pbrt::Transform renderFromTexture = tex.second.renderFromObject.startTransform;
TextureParameterDictionary texDict(&tex.second.parameters, &textures);
SpectrumTextureHandle reflectanceTex = SpectrumTextureHandle::Create(
tex.second.texName, renderFromTexture, texDict, SpectrumType::Reflectance,
tex.second.texName, renderFromTexture, texDict, SpectrumType::General,
&tex.second.loc, alloc, gpu);
SpectrumTextureHandle generalTex = SpectrumTextureHandle::Create(
tex.second.texName, renderFromTexture, texDict, SpectrumType::General,
tex.second.texName, renderFromTexture, texDict, SpectrumType::Illuminant,
&tex.second.loc, alloc, gpu);
textures.spectrumReflectanceTextureMap[tex.first] = reflectanceTex;
textures.spectrumGeneralTextureMap[tex.first] = generalTex;
......@@ -1368,7 +1368,7 @@ std::string FormattingScene::upgradeMaterial(std::string *name, ParameterDiction
bool matches = (rgb && rgb->r == value && rgb->g == value && rgb->b == value);
if (!matches &&
!dict->GetSpectrumArray(paramName, SpectrumType::Reflectance, {}).empty())
!dict->GetSpectrumArray(paramName, SpectrumType::General, {}).empty())
Warning(&loc,
"Parameter is being removed when converting "
"to \"%s\" material: %s",
......@@ -1396,7 +1396,7 @@ std::string FormattingScene::upgradeMaterial(std::string *name, ParameterDiction
return "";
}
if (dict->GetSpectrumArray("opacity", SpectrumType::Reflectance, {}).empty())
if (dict->GetSpectrumArray("opacity", SpectrumType::General, {}).empty())
return "";
pstd::optional<RGB> opacity = dict->GetOneRGB("opacity");
......@@ -1420,7 +1420,8 @@ std::string FormattingScene::upgradeMaterial(std::string *name, ParameterDiction
rgb->r, rgb->g, rgb->b, avg);
extra += indent(1) + StringPrintf("\"float amount\" [ %f ]\n", avg);
}
} else if (dict->GetSpectrumArray("amount", SpectrumType::General, {}).size() > 0)
} else if (dict->GetSpectrumArray("amount", SpectrumType::Illuminant, {}).size() >
0)
ErrorExitDeferred(
&loc, "Unable to update non-RGB spectrum \"amount\" to a scalar: %s",
dict->ToParameterDefinition("amount"));
......@@ -1573,7 +1574,7 @@ void FormattingScene::NamedMaterial(const std::string &name, FileLoc loc) {
static bool upgradeRGBToScale(ParameterDictionary *dict, const char *name,
Float *totalScale) {
std::vector<SpectrumHandle> s =
dict->GetSpectrumArray(name, SpectrumType::General, {});
dict->GetSpectrumArray(name, SpectrumType::Illuminant, {});
if (s.empty())
return true;
......
......@@ -129,7 +129,7 @@ class TriangleMesh;
class RGB;
class RGBColorSpace;
class RGBSigmoidPolynomial;
class RGBSpectrum;
class RGBIlluminantSpectrum;
class SampledSpectrum;
class SampledWavelengths;
class SpectrumWavelengths;
......
......@@ -348,11 +348,11 @@ SampledSpectrum SpectrumImageTexture::Evaluate(TextureEvalContext ctx,
// Return _SampledSpectrum_ for RGB image texture value
if (const RGBColorSpace *cs = mipmap->GetRGBColorSpace(); cs != nullptr) {
if (spectrumType == SpectrumType::Reflectance) {
if (spectrumType == SpectrumType::General) {
rgb = Clamp(rgb, 0, 1);
return RGBReflectanceSpectrum(*cs, rgb).Sample(lambda);
} else
return RGBSpectrum(*cs, rgb).Sample(lambda);
} else
return RGBIlluminantSpectrum(*cs, rgb).Sample(lambda);
}
// otherwise it better be a one-channel texture
DCHECK(rgb[0] == rgb[1] && rgb[1] == rgb[2]);
......@@ -466,9 +466,9 @@ SampledSpectrum MarbleTexture::Evaluate(TextureEvalContext ctx,
RGB rgb = 1.5f * EvaluateCubicBezier(pstd::span(c + first, 4), t);
#ifdef PBRT_IS_GPU_CODE
return RGBReflectanceSpectrum(*RGBColorSpace_sRGB, rgb).Sample(lambda);
return RGBSpectrum(*RGBColorSpace_sRGB, rgb).Sample(lambda);
#else
return RGBReflectanceSpectrum(*RGBColorSpace::sRGB, rgb).Sample(lambda);
return RGBSpectrum(*RGBColorSpace::sRGB, rgb).Sample(lambda);
#endif
}
......@@ -652,11 +652,11 @@ SampledSpectrum SpectrumPtexTexture::Evaluate(TextureEvalContext ctx,
return SampledSpectrum(result[0]);
DCHECK_EQ(3, nc);
RGB rgb(result[0], result[1], result[2]);
if (spectrumType == SpectrumType::Reflectance) {
if (spectrumType == SpectrumType::General) {
rgb = Clamp(rgb, 0, 1);
return RGBReflectanceSpectrum(*RGBColorSpace::sRGB, rgb).Sample(lambda);
} else
return RGBSpectrum(*RGBColorSpace::sRGB, rgb).Sample(lambda);
} else
return RGBIlluminantSpectrum(*RGBColorSpace::sRGB, rgb).Sample(lambda);
#endif
}
......
......@@ -651,11 +651,11 @@ class GPUSpectrumImageTexture {
float4 tex = tex2D<float4>(texObj, st[0], 1 - st[1]);
rgb = scale * RGB(tex.x, tex.y, tex.z);
}
if (spectrumType == SpectrumType::Reflectance) {
if (spectrumType == SpectrumType::General) {
rgb = Clamp(rgb, 0, 1);
return RGBReflectanceSpectrum(*colorSpace, rgb).Sample(lambda);
} else
return RGBSpectrum(*colorSpace, rgb).Sample(lambda);
} else
return RGBIlluminantSpectrum(*colorSpace, rgb).Sample(lambda);
#endif
}
......
......@@ -78,13 +78,13 @@ TEST(RGBColorSpace, StdIllumWhiteACES2065_1) {
EXPECT_LE(rgb.b, 1.01);
}
TEST(RGBSpectrum, MaxValue) {
TEST(RGBIlluminantSpectrum, MaxValue) {
RNG rng;
for (const auto &cs :
{*RGBColorSpace::sRGB, *RGBColorSpace::Rec2020, *RGBColorSpace::ACES2065_1}) {
for (int i = 0; i < 100; ++i) {
RGB rgb(rng.Uniform<Float>(), rng.Uniform<Float>(), rng.Uniform<Float>());
RGBReflectanceSpectrum rs(cs, rgb);
RGBSpectrum rs(cs, rgb);
Float m = rs.MaxValue();
Float sm = 0;
......@@ -96,13 +96,13 @@ TEST(RGBSpectrum, MaxValue) {
}
}
TEST(RGBSpectrum, RoundTripsRGB) {
TEST(RGBIlluminantSpectrum, RoundTripsRGB) {
RNG rng;
const RGBColorSpace &cs = *RGBColorSpace::sRGB;
for (int i = 0; i < 100; ++i) {
RGB rgb(rng.Uniform<Float>(), rng.Uniform<Float>(), rng.Uniform<Float>());
RGBReflectanceSpectrum rs(cs, rgb);
RGBSpectrum rs(cs, rgb);
DenselySampledSpectrum rsIllum = DenselySampledSpectrum::SampleFunction(
[&](Float lambda) { return rs(lambda) * cs.illuminant(lambda); });
......@@ -120,14 +120,14 @@ TEST(RGBSpectrum, RoundTripsRGB) {
}
}
TEST(RGBSpectrum, RoundTripRec2020) {
TEST(RGBIlluminantSpectrum, RoundTripRec2020) {
RNG rng;
const RGBColorSpace &cs = *RGBColorSpace::Rec2020;
for (int i = 0; i < 100; ++i) {
RGB rgb(.1 + .7 * rng.Uniform<Float>(), .1 + .7 * rng.Uniform<Float>(),
.1 + .7 * rng.Uniform<Float>());
RGBReflectanceSpectrum rs(cs, rgb);
RGBSpectrum rs(cs, rgb);
DenselySampledSpectrum rsIllum = DenselySampledSpectrum::SampleFunction(
[&](Float lambda) { return rs(lambda) * cs.illuminant(lambda); });
......@@ -144,14 +144,14 @@ TEST(RGBSpectrum, RoundTripRec2020) {
}
}
TEST(RGBSpectrum, RoundTripACES) {
TEST(RGBIlluminantSpectrum, RoundTripACES) {
RNG rng;
const RGBColorSpace &cs = *RGBColorSpace::ACES2065_1;
for (int i = 0; i < 100; ++i) {
RGB rgb(.3 + .4 * rng.Uniform<Float>(), .3 + .4 * rng.Uniform<Float>(),
.3 + .4 * rng.Uniform<Float>());
RGBReflectanceSpectrum rs(cs, rgb);
RGBSpectrum rs(cs, rgb);
DenselySampledSpectrum rsIllum = DenselySampledSpectrum::SampleFunction(
[&](Float lambda) { return rs(lambda) * cs.illuminant(lambda); });
......
......@@ -32,13 +32,13 @@ namespace pbrt {
// Spectrum Function Definitions
Float SpectrumToPhotometric(SpectrumHandle s) {
// We have to handle RGBSpectrum separately here as it's composed of an
// We have to handle RGBIlluminantSpectrum separately here as it's composed of an
// illuminant spectrum and an RGB multiplier. We only want to consider the
// illuminant for the sake of this calculation, and we should consider the
// RGB separately for the purposes of target power/illuminance computation
// in the lights themselves (but we currently don't)
if (s.Is<RGBSpectrum>())
s = s.Cast<RGBSpectrum>()->Illluminant();
if (s.Is<RGBIlluminantSpectrum>())
s = s.Cast<RGBIlluminantSpectrum>()->Illluminant();
Float y = 0;
for (Float lambda = Lambda_min; lambda <= Lambda_max; ++lambda)
......@@ -261,39 +261,40 @@ RGB SampledSpectrum::ToRGB(const SampledWavelengths &lambda,
return cs.ToRGB(xyz);
}
RGBReflectanceSpectrum::RGBReflectanceSpectrum(const RGBColorSpace &cs, const RGB &rgb)
RGBSpectrum::RGBSpectrum(const RGBColorSpace &cs, const RGB &rgb)
: rgb(rgb), rsp(cs.ToRGBCoeffs(rgb)) {}
RGBSpectrum::RGBSpectrum(const RGBColorSpace &cs, const RGB &rgb)
RGBIlluminantSpectrum::RGBIlluminantSpectrum(const RGBColorSpace &cs, const RGB &rgb)
: rgb(rgb), illuminant(&cs.illuminant) {
Float m = std::max({rgb.r, rgb.g, rgb.b});
scale = 2 * m;
rsp = cs.ToRGBCoeffs(scale ? rgb / scale : RGB(0, 0, 0));
}
std::string RGBReflectanceSpectrum::ToString() const {
return StringPrintf("[ RGBReflectanceSpectrum rsp: %s ]", rsp);
std::string RGBSpectrum::ToString() const {
return StringPrintf("[ RGBSpectrum rsp: %s ]", rsp);
}
std::string RGBReflectanceSpectrum::ParameterType() const {
std::string RGBSpectrum::ParameterType() const {
return "rgb";
}
std::string RGBReflectanceSpectrum::ParameterString() const {
std::string RGBSpectrum::ParameterString() const {
return StringPrintf("%f %f %f", rgb.r, rgb.g, rgb.b);
}
std::string RGBSpectrum::ParameterType() const {
std::string RGBIlluminantSpectrum::ParameterType() const {
return "rgb";
}
std::string RGBSpectrum::ParameterString() const {
std::string RGBIlluminantSpectrum::ParameterString() const {
return StringPrintf("%f %f %f", rgb.r, rgb.g, rgb.b);
}
std::string RGBSpectrum::ToString() const {
return StringPrintf("[ RGBSpectrum rgb: %s rsp: %s scale: %f illuminant: %s ]", rgb,
rsp, scale, *illuminant);
std::string RGBIlluminantSpectrum::ToString() const {
return StringPrintf(
"[ RGBIlluminantSpectrum rgb: %s rsp: %s scale: %f illuminant: %s ]", rgb, rsp,
scale, *illuminant);
}
namespace {
......
......@@ -40,12 +40,13 @@ class BlackbodySpectrum;
class ConstantSpectrum;
class PiecewiseLinearSpectrum;
class DenselySampledSpectrum;
class RGBReflectanceSpectrum;
class RGBSpectrum;
class RGBIlluminantSpectrum;
class SpectrumHandle : public TaggedPointer<ConstantSpectrum, DenselySampledSpectrum,
PiecewiseLinearSpectrum, RGBSpectrum,
RGBReflectanceSpectrum, BlackbodySpectrum> {
class SpectrumHandle
: public TaggedPointer<ConstantSpectrum, DenselySampledSpectrum,
PiecewiseLinearSpectrum, RGBIlluminantSpectrum, RGBSpectrum,
BlackbodySpectrum> {
public:
// SpectrumHandle Public Methods
using TaggedPointer::TaggedPointer;
......@@ -517,16 +518,16 @@ class BlackbodySpectrum {
Float normalizationFactor;
};
class RGBReflectanceSpectrum {
class RGBSpectrum {
public:
// RGBReflectanceSpectrum Public Methods
// RGBSpectrum Public Methods
PBRT_CPU_GPU
Float operator()(Float lambda) const { return scale * rsp(lambda); }
PBRT_CPU_GPU
Float MaxValue() const { return scale * rsp.MaxValue(); }
PBRT_CPU_GPU
RGBReflectanceSpectrum(const RGBColorSpace &cs, const RGB &rgb);
RGBSpectrum(const RGBColorSpace &cs, const RGB &rgb);
PBRT_CPU_GPU
SampledSpectrum Sample(const SampledWavelengths &lambda) const {
......@@ -541,18 +542,18 @@ class RGBReflectanceSpectrum {
std::string ParameterString() const;
private:
// RGBReflectanceSpectrum Private Members
// RGBSpectrum Private Members
Float scale = 1;
RGB rgb;
RGBSigmoidPolynomial rsp;
};
class RGBSpectrum {
class RGBIlluminantSpectrum {
public:
// RGBSpectrum Public Methods
RGBSpectrum() = default;
// RGBIlluminantSpectrum Public Methods
RGBIlluminantSpectrum() = default;
PBRT_CPU_GPU
RGBSpectrum(const RGBColorSpace &cs, const RGB &rgb);
RGBIlluminantSpectrum(const RGBColorSpace &cs, const RGB &rgb);
PBRT_CPU_GPU
Float operator()(Float lambda) const {
......@@ -577,7 +578,7 @@ class RGBSpectrum {
std::string ParameterString() const;
private:
// RGBSpectrum Private Members
// RGBIlluminantSpectrum Private Members
RGB rgb;
Float scale;
RGBSigmoidPolynomial rsp;
......
......@@ -103,12 +103,12 @@ TEST(Spectrum, MaxValue) {
RNG rng;
for (int i = 0; i < 20; ++i) {
RGB rgb(rng.Uniform<Float>(), rng.Uniform<Float>(), rng.Uniform<Float>());
RGBReflectanceSpectrum sr(*RGBColorSpace::sRGB, rgb);
RGBSpectrum sr(*RGBColorSpace::sRGB, rgb);
Float m = sr.MaxValue() * 1.00001f;
for (Float lambda = 360; lambda < 830; lambda += .92)
EXPECT_LE(sr(lambda), m);
RGBSpectrum si(*RGBColorSpace::sRGB, rgb);
RGBIlluminantSpectrum si(*RGBColorSpace::sRGB, rgb);
m = si.MaxValue() * 1.00001f;
for (Float lambda = 360; lambda < 830; lambda += .92)
EXPECT_LE(si(lambda), m);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册