Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dso/map/Image/ImageMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ ImageMap::update()
if (needsUpdate ||
hasChanged(attrTexture) ||
hasChanged(attrGamma) ||
hasChanged(attrSourceColorSpace) ||
hasChanged(attrWrapAround) ||
hasChanged(attrUseDefaultColor) ||
hasChanged(attrDefaultColor)) {
Expand All @@ -137,6 +138,7 @@ ImageMap::update()
sLogEventRegistry,
get(attrTexture),
static_cast<ispc::TEXTURE_GammaMode>(get(attrGamma)),
get(attrSourceColorSpace),
wrapS,
wrapT,
get(attrUseDefaultColor),
Expand All @@ -162,12 +164,14 @@ ImageMap::update()
if (needsUpdate ||
hasChanged(attrTexture) ||
hasChanged(attrGamma) ||
hasChanged(attrSourceColorSpace) ||
hasChanged(attrWrapAround) ||
hasChanged(attrUseDefaultColor) ||
hasChanged(attrDefaultColor)) {
std::string errorStr;
if (!mTexture->update(get(attrTexture),
static_cast<ispc::TEXTURE_GammaMode>(get(attrGamma)),
get(attrSourceColorSpace),
wrapS,
wrapT,
get(attrUseDefaultColor),
Expand Down Expand Up @@ -415,4 +419,3 @@ ImageMap::applyColorCorrection(Color& result) const
}

//---------------------------------------------------------------------------

7 changes: 7 additions & 0 deletions dso/map/Image/ImageMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
},
"comment": "If this is set to 'on' or 'auto' and the 'texture' file is 8-bit, then a power of 2.2 will be applied to the RGB channels of the image."
},
"attrSourceColorSpace": {
"name": "source_color_space",
"label": "source color space",
"type": "String",
"default": "\"auto\"",
"comment": "OCIO source color space for the texture. Use 'auto' to apply the active OCIO file rules, 'raw' or 'data' to disable source conversion, or an explicit color-space name from the active OCIO config. When OCIO conversion is active, the legacy gamma mode is bypassed."
},
"attrOffset": {
"name": "offset",
"type": "Vec2f",
Expand Down
32 changes: 31 additions & 1 deletion dso/map/UsdUVTexture/UsdUVTexture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ static ispc::StaticUsdUVTextureData sStaticUsdUVTextureData;

//----------------------------------------------------------------------------

namespace {

std::string
sourceColorSpaceFromUsdEnum(const int sourceColorSpace, const std::string& overrideValue)
{
if (!overrideValue.empty()) {
return overrideValue;
}

switch (sourceColorSpace) {
case ispc::TEXTURE_GAMMA_OFF:
return "raw";
case ispc::TEXTURE_GAMMA_ON:
return "sRGB";
case ispc::TEXTURE_GAMMA_USD:
default:
return "auto";
}
}

} // namespace

RDL2_DSO_CLASS_BEGIN(UsdUVTexture, scene_rdl2::rdl2::Map)

public:
Expand Down Expand Up @@ -73,6 +95,9 @@ UsdUVTexture::update()
const std::string filename = get(attrFile);
const std::size_t udimPos = filename.find("<UDIM>");
const bool areWeAUdim = udimPos != std::string::npos;
const std::string sourceColorSpace =
sourceColorSpaceFromUsdEnum(get(attrSourceColorSpace),
get(attrSourceColorSpaceOverride));

const scene_rdl2::rdl2::SceneVariables &sv = getSceneClass().getSceneContext()->getSceneVariables();
mIspc.mFatalColor = asIspc(sv.get(scene_rdl2::rdl2::SceneVariables::sFatalColor));
Expand Down Expand Up @@ -103,6 +128,8 @@ UsdUVTexture::update()

if (needsUpdate ||
hasChanged(attrFile) ||
hasChanged(attrSourceColorSpace) ||
hasChanged(attrSourceColorSpaceOverride) ||
hasChanged(attrWrapS) ||
hasChanged(attrWrapT) ||
hasChanged(attrFallback)) {
Expand All @@ -111,6 +138,7 @@ UsdUVTexture::update()
sLogEventRegistry,
filename,
static_cast<ispc::TEXTURE_GammaMode>(get(attrSourceColorSpace)),
sourceColorSpace,
wrapS,
wrapT,
true, // use default/fallback color
Expand All @@ -135,12 +163,15 @@ UsdUVTexture::update()
}
if (needsUpdate ||
hasChanged(attrFile) ||
hasChanged(attrSourceColorSpace) ||
hasChanged(attrSourceColorSpaceOverride) ||
hasChanged(attrWrapS) ||
hasChanged(attrWrapT) ||
hasChanged(attrFallback)) {

if (!mTexture->update(filename,
static_cast<ispc::TEXTURE_GammaMode>(get(attrSourceColorSpace)),
sourceColorSpace,
wrapS,
wrapT,
true, // use default/fallback color
Expand Down Expand Up @@ -242,4 +273,3 @@ UsdUVTexture::sample(const scene_rdl2::rdl2::Map *self,
rgb = rgb * me->get(attrScale) + me->get(attrBias);
*sample = rgb;
}

7 changes: 7 additions & 0 deletions dso/map/UsdUVTexture/UsdUVTexture.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
"auto": "3"
},
"comment": "Flag indicating the color space in which the source texture is encoded. If set to auto, gamma correction will be applied if the images is not single channel."
},
"attrSourceColorSpaceOverride": {
"name": "source_color_space",
"label": "source color space override",
"type": "String",
"default": "\"\"",
"comment": "Optional OCIO source color-space override. Empty preserves the USD sourceColorSpace enum. Use 'auto' to apply the active OCIO file rules, 'raw' or 'data' to disable source conversion, or an explicit color-space name from the active OCIO config. When OCIO conversion is active, the legacy gamma mode is bypassed."
}
}
}
179 changes: 89 additions & 90 deletions lib/rendering/geom/PrimitiveUserData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ using scene_rdl2::logging::Logger;
namespace moonray {
namespace geom {

namespace {

bool
validRate(const scene_rdl2::rdl2::SceneObject* geometry,
const std::string& keyName,
AttributeRate rate)
{
if (rate != AttributeRate::RATE_UNKNOWN) {
return true;
}
Logger::warn(geometry->getName(), '.', keyName,
": skipping primitive attribute with invalid rate/count");
return false;
}

} // namespace

// These first two internal pickRate functions take an explicit rate.
// If the explicit rate is set to "auto" we fall back to the public
// pickRate function which guesses the rate based on the number of
Expand Down Expand Up @@ -126,34 +143,9 @@ pickRate(const scene_rdl2::rdl2::SceneObject* object,
return AttributeRate::RATE_VARYING;
}

// Pick one that fits. Tried in assumed largest->smallest order. Some geometry
// may produce a different order but it is probably ok that the interpolation
// guess is not the closest one. Also 1 always turns into constant even if others
// have counts of 1.
size_t best;
AttributeRate rate;
if (rates.faceVaryingCount > 1 && size > rates.faceVaryingCount) {
best = rates.faceVaryingCount;
rate = AttributeRate::RATE_FACE_VARYING;
} else if (rates.vertexCount > 1 && size > rates.vertexCount) {
best = rates.vertexCount;
rate = AttributeRate::RATE_VERTEX;
} else if (rates.varyingCount > 1 && size > rates.varyingCount) {
best = rates.varyingCount;
rate = AttributeRate::RATE_VARYING;
} else if (rates.uniformCount > 1 && size > rates.uniformCount) {
best = rates.uniformCount;
rate = AttributeRate::RATE_UNIFORM;
} else if (rates.partCount > 1 && size > rates.partCount) {
best = rates.partCount;
rate = AttributeRate::RATE_PART;
} else {
best = 1;
rate = AttributeRate::RATE_CONSTANT;
}

Logger::warn(object->getName(), '.', keyName, ": invalid size ", size, " truncated to ", best);
return rate;
Logger::warn(object->getName(), '.', keyName, ": invalid size ", size,
" does not match any primitive attribute rate");
return AttributeRate::RATE_UNKNOWN;
}

bool sizeCheck(const scene_rdl2::rdl2::SceneObject* object,
Expand Down Expand Up @@ -192,26 +184,28 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
std::vector<scene_rdl2::rdl2::Bool> data(constData.begin(),
constData.end());

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates),
std::move(data));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(data));
}
}

if (userData->hasIntData()) {
shading::TypedAttributeKey<scene_rdl2::rdl2::Int> key(userData->getIntKey());
scene_rdl2::rdl2::IntVector data = userData->getIntValues();

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates),
std::move(data));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(data));
}
}

{
Expand All @@ -231,27 +225,29 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
samples[1].size() :
size0;

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates),
std::move(samples));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(samples));
}
}
}

if (userData->hasStringData()) {
shading::TypedAttributeKey<std::string> key(userData->getStringKey());
scene_rdl2::rdl2::StringVector data = userData->getStringValues();
primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates),
std::move(data));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
data.size(),
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(data));
}
}

{
Expand All @@ -271,14 +267,15 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
samples[1].size() :
size0;

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates),
std::move(samples));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(samples));
}
}
}

Expand All @@ -299,14 +296,15 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
samples[1].size() :
size0;

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates),
std::move(samples));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(samples));
}
}
}

Expand All @@ -327,14 +325,15 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
samples[1].size() :
size0;

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates),
std::move(samples));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(samples));
}
}
}

Expand All @@ -355,19 +354,19 @@ processArbitraryData(const scene_rdl2::rdl2::SceneObject* geometry,
samples[1].size() :
size0;

primitiveAttributeTable.addAttribute(key,
pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates),
std::move(samples));
AttributeRate rate = pickRate(geometry,
explicitRate,
key.getName(),
size0,
size1,
rates);
if (validRate(geometry, key.getName(), rate)) {
primitiveAttributeTable.addAttribute(key, rate, std::move(samples));
}
}
}
}
}

} // namespace geom
} // namespace moonray

Loading