diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2019-05-02 16:45:31 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-03 16:42:49 +0300 |
commit | 68b15fc3ad4f74be192150d3a2fb35e7ef2d4edd (patch) | |
tree | 26c2aa7b37c3520417acf13b4a80c3023346b1c2 /intern/cycles/render/osl.cpp | |
parent | dba4684f82a179a5c8abdae5940bc7c35e65a1a7 (diff) |
Cycles: support loading images from arbitrary OpenColorIO color space
These are the internal changes to Cycles, for Blender integration there are no
functional changes in this commit.
Images are converted to scene linear color space on file load, and on reading
from the OpenImageIO texture cache. 8-bit images are compressed with the sRGB
transfer function to avoid precision loss while keeping memory usages low. This
also means that for common cases of 8-bit sRGB images no conversion happens at
all on image loading.
Initial patch by Lukas, completed by Brecht.
Differential Revision: https://developer.blender.org/D3491
Diffstat (limited to 'intern/cycles/render/osl.cpp')
-rw-r--r-- | intern/cycles/render/osl.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 5ee453275b9..a65c8e9f338 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -16,6 +16,7 @@ #include "device/device.h" +#include "render/colorspace.h" #include "render/graph.h" #include "render/light.h" #include "render/osl.h" @@ -1205,25 +1206,29 @@ void OSLCompiler::compile(Scene *scene, Shader *shader) osl_globals->bump_state.push_back(shader->osl_surface_bump_ref); } -void OSLCompiler::parameter_texture(const char *name, ustring filename, int svm_slot) +void OSLCompiler::parameter_texture(const char *name, ustring filename, ustring colorspace) { - if (svm_slot != -1) { - /* It's not so simple to pass custom attribute to the texture() function - * in order to make builtin images support more clear. So we use special - * file name which is "@i<slot_number>" and use that for lookup in - * in OSLRenderServices::texture(). */ - filename = string_printf("@i%d", svm_slot).c_str(); - osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::SVM, svm_slot)); - } - else { - osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO)); - } + /* Textured loaded through the OpenImageIO texture cache. For this + * case we need to do runtime color space conversion. */ + OSLTextureHandle *handle = new OSLTextureHandle(OSLTextureHandle::OIIO); + handle->processor = ColorSpaceManager::get_processor(colorspace); + osl_globals->textures.insert(filename, handle); + parameter(name, filename); +} +void OSLCompiler::parameter_texture(const char *name, int svm_slot) +{ + /* Texture loaded through SVM image texture system. We generate a unique + * name, which ends up being used in OSLRenderServices::get_texture_handle + * to get handle again. */ + ustring filename(string_printf("@i%d", svm_slot).c_str()); + osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::SVM, svm_slot)); parameter(name, filename); } void OSLCompiler::parameter_texture_ies(const char *name, int svm_slot) { + /* IES light textures stored in SVM. */ ustring filename(string_printf("@l%d", svm_slot).c_str()); osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::IES, svm_slot)); parameter(name, filename); @@ -1285,7 +1290,11 @@ void OSLCompiler::parameter_color_array(const char * /*name*/, const array<float void OSLCompiler::parameter_texture(const char * /* name */, ustring /* filename */, - int /* svm_slot */) + ustring /* colorspace */) +{ +} + +void OSLCompiler::parameter_texture(const char * /* name */, int /* svm_slot */) { } |