Revision: 52412
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52412
Author:   blendix
Date:     2012-11-20 17:40:21 +0000 (Tue, 20 Nov 2012)
Log Message:
-----------
Fix #33177: OSL render difference with missing textures and HSV nodes.

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/osl/osl_globals.h
    trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
    trunk/blender/intern/cycles/kernel/osl/osl_services.h
    trunk/blender/intern/cycles/kernel/shaders/node_brightness.osl
    trunk/blender/intern/cycles/kernel/shaders/node_hsv.osl
    trunk/blender/intern/cycles/render/osl.cpp

Modified: trunk/blender/intern/cycles/kernel/osl/osl_globals.h
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_globals.h        2012-11-20 
17:40:10 UTC (rev 52411)
+++ trunk/blender/intern/cycles/kernel/osl/osl_globals.h        2012-11-20 
17:40:21 UTC (rev 52412)
@@ -43,6 +43,7 @@
 
        /* shading system */
        OSL::ShadingSystem *ss;
+       OSL::TextureSystem *ts;
        OSLRenderServices *services;
 
        /* shader states */

Modified: trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_services.cpp     2012-11-20 
17:40:10 UTC (rev 52411)
+++ trunk/blender/intern/cycles/kernel/osl/osl_services.cpp     2012-11-20 
17:40:21 UTC (rev 52412)
@@ -649,6 +649,80 @@
        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 &center,
                                          float radius, int max_points, bool 
sort,
                                          size_t *out_indices, float 
*out_distances, int derivs_offset)

Modified: trunk/blender/intern/cycles/kernel/osl/osl_services.h
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_services.h       2012-11-20 
17:40:10 UTC (rev 52411)
+++ trunk/blender/intern/cycles/kernel/osl/osl_services.h       2012-11-20 
17:40:21 UTC (rev 52412)
@@ -84,6 +84,23 @@
        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;

Modified: trunk/blender/intern/cycles/kernel/shaders/node_brightness.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_brightness.osl      
2012-11-20 17:40:10 UTC (rev 52411)
+++ trunk/blender/intern/cycles/kernel/shaders/node_brightness.osl      
2012-11-20 17:40:21 UTC (rev 52412)
@@ -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);
 }
 

Modified: trunk/blender/intern/cycles/kernel/shaders/node_hsv.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_hsv.osl     2012-11-20 
17:40:10 UTC (rev 52411)
+++ trunk/blender/intern/cycles/kernel/shaders/node_hsv.osl     2012-11-20 
17:40:21 UTC (rev 52412)
@@ -27,7 +27,6 @@
        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 @@
 
        Color = hsv_to_rgb(Color);
 
-       ColorOut = mix(Color, ColorIn, t);
+       ColorOut = mix(ColorIn, Color, Fac);
 }
 

Modified: trunk/blender/intern/cycles/render/osl.cpp
===================================================================
--- trunk/blender/intern/cycles/render/osl.cpp  2012-11-20 17:40:10 UTC (rev 
52411)
+++ trunk/blender/intern/cycles/render/osl.cpp  2012-11-20 17:40:21 UTC (rev 
52412)
@@ -88,6 +88,7 @@
 
        /* 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 @@
        /* clear shader engine */
        og->use = false;
        og->ss = NULL;
+       og->ts = NULL;
 
        og->surface_state.clear();
        og->volume_state.clear();
@@ -334,7 +336,7 @@
        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";

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to