Skip to content

Commit

Permalink
Use explicit colorspace parameters in OSL texture calls (#1546)
Browse files Browse the repository at this point in the history
This change list adds the parameter "colorspace" to the texture call in OSL, for sampling color3/color4 textures. Previously this was supported under the covers, by token replacement that a custom OSL generator had to setup, and only done for the Arnold OSL generator.
  • Loading branch information
niklasharrysson authored Oct 4, 2023
1 parent 0bd0978 commit a79ddfb
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 10 deletions.
3 changes: 1 addition & 2 deletions libraries/stdlib/genosl/mx_image_color3.osl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ void mx_image_color3(textureresource file, string layer, color default_value, ve

color missingColor = default_value;
vector2 st = mx_transform_uv(texcoord);
out = texture(file.filename, st.x, st.y, "subimage", layer, "missingcolor", missingColor, "swrap", uaddressmode, "twrap", vaddressmode $extraTextureLookupArguments);
out = texture(file.filename, st.x, st.y, "subimage", layer, "missingcolor", missingColor, "swrap", uaddressmode, "twrap", vaddressmode, "colorspace", file.colorspace);
}

2 changes: 1 addition & 1 deletion libraries/stdlib/genosl/mx_image_color4.osl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void mx_image_color4(textureresource file, string layer, color4 default_value, v
vector2 st = mx_transform_uv(texcoord);
float alpha;
color rgb = texture(file.filename, st.x, st.y, "alpha", alpha, "subimage", layer,
"missingcolor", missingColor, "missingalpha", missingAlpha, "swrap", uaddressmode, "twrap", vaddressmode $extraTextureLookupArguments );
"missingcolor", missingColor, "missingalpha", missingAlpha, "swrap", uaddressmode, "twrap", vaddressmode, "colorspace", file.colorspace);

out = color4(rgb, alpha);
}
4 changes: 0 additions & 4 deletions source/MaterialXGenOsl/OslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
MATERIALX_NAMESPACE_BEGIN

const string OslShaderGenerator::TARGET = "genosl";
const string OslShaderGenerator::T_FILE_EXTRA_ARGUMENTS = "$extraTextureLookupArguments";

//
// OslShaderGenerator methods
Expand Down Expand Up @@ -161,9 +160,6 @@ OslShaderGenerator::OslShaderGenerator() :

// <!-- <surfacematerial> -->
registerImplementation("IM_surfacematerial_" + OslShaderGenerator::TARGET, MaterialNodeOsl::create);

// Extra arguments for texture lookups.
_tokenSubstitutions[T_FILE_EXTRA_ARGUMENTS] = EMPTY_STRING;
}

ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, GenContext& context) const
Expand Down
3 changes: 0 additions & 3 deletions source/MaterialXGenOsl/OslShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class MX_GENOSL_API OslShaderGenerator : public ShaderGenerator
void registerShaderMetadata(const DocumentPtr& doc, GenContext& context) const override;

protected:
// Extra file arguments for texture lookup call
static const string T_FILE_EXTRA_ARGUMENTS;

/// Create and initialize a new OSL shader for shader generation.
virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;

Expand Down

0 comments on commit a79ddfb

Please sign in to comment.