diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-20 21:40:21 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-20 21:40:21 +0400 |
commit | fd619cd7f1fca63a9d19df4301a185c86ea6dc2c (patch) | |
tree | 0a9f143efe52eda35f3752991d368c5476422e2f /intern/cycles | |
parent | ab1b5af08d25b5c9bdb11110e4e8b607fdea3af5 (diff) |
Fix #33177: OSL render difference with missing textures and HSV nodes.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/osl/osl_globals.h | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 74 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.h | 17 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_brightness.osl | 29 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_hsv.osl | 3 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 4 |
6 files changed, 102 insertions, 26 deletions
diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h index 003e39ca3c3..ce283023c5c 100644 --- a/intern/cycles/kernel/osl/osl_globals.h +++ b/intern/cycles/kernel/osl/osl_globals.h @@ -43,6 +43,7 @@ struct OSLGlobals { /* shading system */ OSL::ShadingSystem *ss; + OSL::TextureSystem *ts; OSLRenderServices *services; /* shader states */ diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 54cbf49704f..e79c509b144 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -649,6 +649,80 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst return false; /* never called by OSL */ } +bool OSLRenderServices::texture(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, + float s, float t, float dsdx, float dtdx, + float dsdy, float dtdy, float *result) +{ + OSL::TextureSystem *ts = kernel_globals->osl.ts; + bool status = ts->texture(filename, options, s, t, dsdx, dtdx, dsdy, dtdy, result); + + if(!status) { + if(options.nchannels == 3 || options.nchannels == 4) { + result[0] = 1.0f; + result[1] = 0.0f; + result[2] = 1.0f; + + if(options.nchannels == 4) + result[3] = 1.0f; + } + } + + return status; +} + +bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, const OSL::Vec3 &P, + const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, + const OSL::Vec3 &dPdz, float *result) +{ + OSL::TextureSystem *ts = kernel_globals->osl.ts; + bool status = ts->texture3d(filename, options, P, dPdx, dPdy, dPdz, result); + + if(!status) { + if(options.nchannels == 3 || options.nchannels == 4) { + result[0] = 1.0f; + result[1] = 0.0f; + result[2] = 1.0f; + + if(options.nchannels == 4) + result[3] = 1.0f; + } + + } + + return status; +} + +bool OSLRenderServices::environment(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, const OSL::Vec3 &R, + const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result) +{ + OSL::TextureSystem *ts = kernel_globals->osl.ts; + bool status = ts->environment(filename, options, R, dRdx, dRdy, result); + + if(!status) { + if(options.nchannels == 3 || options.nchannels == 4) { + result[0] = 1.0f; + result[1] = 0.0f; + result[2] = 1.0f; + + if(options.nchannels == 4) + result[3] = 1.0f; + } + } + + return status; +} + +bool OSLRenderServices::get_texture_info(ustring filename, int subimage, + ustring dataname, + TypeDesc datatype, void *data) +{ + OSL::TextureSystem *ts = kernel_globals->osl.ts; + return ts->get_texture_info(filename, subimage, dataname, datatype, data); +} + int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er, float radius, int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset) diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h index ce62eaf8994..b5a7bbae7e5 100644 --- a/intern/cycles/kernel/osl/osl_services.h +++ b/intern/cycles/kernel/osl/osl_services.h @@ -84,6 +84,23 @@ public: bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name, TypeDesc type, void *val, bool derivatives); + bool texture(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, + float s, float t, float dsdx, float dtdx, + float dsdy, float dtdy, float *result); + + bool texture3d(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, const OSL::Vec3 &P, + const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, + const OSL::Vec3 &dPdz, float *result); + + bool environment(ustring filename, TextureOpt &options, + OSL::ShaderGlobals *sg, const OSL::Vec3 &R, + const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result); + + bool get_texture_info(ustring filename, int subimage, + ustring dataname, TypeDesc datatype, void *data); + struct TraceData { Ray ray; Intersection isect; diff --git a/intern/cycles/kernel/shaders/node_brightness.osl b/intern/cycles/kernel/shaders/node_brightness.osl index 8e9f5c9c796..b263d815566 100644 --- a/intern/cycles/kernel/shaders/node_brightness.osl +++ b/intern/cycles/kernel/shaders/node_brightness.osl @@ -20,32 +20,15 @@ shader node_brightness( color ColorIn = color(0.8, 0.8, 0.8), - float Brightness = 0.0, + float Bright = 0.0, float Contrast = 0.0, output color ColorOut = color(0.8, 0.8, 0.8)) { - float delta = Contrast * (1.0 / 200.0); - float a = 1.0 - delta * 2.0; - float b; + float a = 1.0 + Contrast; + float b = Bright - Contrast*0.5; - /* input value is a percentage */ - float bright_factor = Brightness / 100.0; - - /* - * The algorithm is by Werner D. Streidt - * (http://visca.com/ffactory/archives/5-99/msg00021.html) - * Extracted of OpenCV demhist.c - */ - - if (Contrast > 0.0) { - a = (a < 0.0 ? 1.0 / a : 0.0); - b = a * (bright_factor - delta); - } - else { - delta *= -1.0; - b = a * (bright_factor + delta); - } - - ColorOut = a * ColorIn + b; + ColorOut[0] = max(a*ColorIn[0] + b, 0.0); + ColorOut[1] = max(a*ColorIn[1] + b, 0.0); + ColorOut[2] = max(a*ColorIn[2] + b, 0.0); } diff --git a/intern/cycles/kernel/shaders/node_hsv.osl b/intern/cycles/kernel/shaders/node_hsv.osl index 8fd7a1612e8..0f4bedfb0f8 100644 --- a/intern/cycles/kernel/shaders/node_hsv.osl +++ b/intern/cycles/kernel/shaders/node_hsv.osl @@ -27,7 +27,6 @@ shader node_hsv( color ColorIn = color(0.0, 0.0, 0.0), output color ColorOut = color(0.0, 0.0, 0.0)) { - float t = clamp(Fac, 0.0, 1.0); color Color = rgb_to_hsv(ColorIn); // remember: fmod doesn't work for negative numbers @@ -38,6 +37,6 @@ shader node_hsv( Color = hsv_to_rgb(Color); - ColorOut = mix(Color, ColorIn, t); + ColorOut = mix(ColorIn, Color, Fac); } diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index d2600541efc..c5ecddcfc15 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -88,6 +88,7 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene /* setup shader engine */ og->ss = ss; + og->ts = ts; og->services = services; int background_id = scene->shader_manager->get_shader_id(scene->default_background); og->background_state = og->surface_state[background_id & SHADER_MASK]; @@ -118,6 +119,7 @@ void OSLShaderManager::device_free(Device *device, DeviceScene *dscene) /* clear shader engine */ og->use = false; og->ss = NULL; + og->ts = NULL; og->surface_state.clear(); og->volume_state.clear(); @@ -334,7 +336,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output) while((i = sname.find(" ")) != string::npos) sname.replace(i, 1, ""); - /* if output exists with the same name, add "In" suffix */ + /* if input exists with the same name, add "Out" suffix */ foreach(ShaderInput *input, node->inputs) { if (strcmp(input->name, output->name)==0) { sname += "Out"; |