diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index e8243a4ae34..e85e5752dda 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -146,6 +146,15 @@ std::list SHADER_CACHE; /** \name Shader * \{ */ +void string_replace_all(std::string &haystack, const std::string &needle, const std::string &other) +{ + size_t i = 0, index; + while ((index = haystack.find(needle, i)) != std::string::npos) { + haystack.replace(index, needle.size(), other); + i = index + other.size(); + } +} + static bool createGPUShader(OCIO_GPUShader &shader, OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shaderdesc_to_scene_linear, @@ -174,6 +183,17 @@ static bool createGPUShader(OCIO_GPUShader &shader, } } + /* Comparison operator in Metal returns per-element comparison and returns a vector of booleans. + * Need a special syntax to see if two vec3 are matched. + * + * NOTE: The replacement is optimized for transforming code generated by + * GradingPrimaryTransform. A more general approach is possible, but for now prefer processing + * speed. + * + * NOTE: The syntax works for all backends Blender supports. */ + string_replace_all( + source, "if ( gamma != vec3(1., 1., 1.) )", "if (! all(equal(gamma, vec3(1., 1., 1.))) )"); + StageInterfaceInfo iface("OCIO_Interface", ""); iface.smooth(Type::VEC2, "texCoord_interp");