Commit: e3abcd6723afe24eabf2a332112e4c7a74cceae3
Author: Lukas Stockner
Date:   Thu Oct 8 03:31:15 2015 +0200
Branches: master
https://developer.blender.org/rBe3abcd6723afe24eabf2a332112e4c7a74cceae3

Cycles: Add an interpolation option to environment textures

This commit exposes the interpolation parameter for environment textures 
(requested by DolpheenDream on IRC), just as it already is for image textures.

Reviewers: sergey

Differential Revision: https://developer.blender.org/D1544

===================================================================

M       intern/cycles/blender/blender_shader.cpp
M       intern/cycles/kernel/shaders/node_environment_texture.osl
M       intern/cycles/render/nodes.cpp
M       intern/cycles/render/nodes.h
M       source/blender/editors/space_node/drawnode.c
M       source/blender/makesdna/DNA_node_types.h
M       source/blender/makesrna/intern/rna_nodetree.c

===================================================================

diff --git a/intern/cycles/blender/blender_shader.cpp 
b/intern/cycles/blender/blender_shader.cpp
index fe62890..30b14b8 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -640,11 +640,12 @@ static ShaderNode *add_node(Scene *scene,
                        if(b_image.is_updated()) {
                                
scene->image_manager->tag_reload_image(env->filename,
                                                                       
env->builtin_data,
-                                                                      
INTERPOLATION_LINEAR,
+                                                                      
(InterpolationType)b_env_node.interpolation(),
                                                                       
EXTENSION_REPEAT);
                        }
                }
                env->color_space = 
EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
+               env->interpolation = 
(InterpolationType)b_env_node.interpolation();
                env->projection = 
EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()];
                get_tex_mapping(&env->tex_mapping, 
b_env_node.texture_mapping());
                node = env;
diff --git a/intern/cycles/kernel/shaders/node_environment_texture.osl 
b/intern/cycles/kernel/shaders/node_environment_texture.osl
index 14f0226..3a0b782 100644
--- a/intern/cycles/kernel/shaders/node_environment_texture.osl
+++ b/intern/cycles/kernel/shaders/node_environment_texture.osl
@@ -45,6 +45,7 @@ shader node_environment_texture(
        vector Vector = P,
        string filename = "",
        string projection = "Equirectangular",
+       string interpolation = "linear",
        string color_space = "sRGB",
        int is_float = 1,
        int use_alpha = 1,
@@ -64,7 +65,7 @@ shader node_environment_texture(
                p = environment_texture_direction_to_mirrorball(p);
 
        /* todo: use environment for better texture filtering of 
equirectangular */
-       Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", 
"alpha", Alpha);
+       Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", 
"interp", interpolation, "alpha", Alpha);
 
        if (use_alpha) {
                Color = color_unpremultiply(Color, Alpha);
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 1c32644..fccb815 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -182,6 +182,21 @@ static ShaderEnum image_projection_init()
        return enm;
 }
 
+static const char* get_osl_interpolation_parameter(InterpolationType 
interpolation)
+{
+       switch (interpolation) {
+               case INTERPOLATION_CLOSEST:
+                       return "closest";
+               case INTERPOLATION_CUBIC:
+                       return "cubic";
+               case INTERPOLATION_SMART:
+                       return "smart";
+               case INTERPOLATION_LINEAR:
+               default:
+                       return "linear";
+       }
+}
+
 ShaderEnum ImageTextureNode::color_space_enum = color_space_init();
 ShaderEnum ImageTextureNode::projection_enum = image_projection_init();
 
@@ -362,22 +377,7 @@ void ImageTextureNode::compile(OSLCompiler& compiler)
        compiler.parameter("projection_blend", projection_blend);
        compiler.parameter("is_float", is_float);
        compiler.parameter("use_alpha", !alpha_out->links.empty());
-
-       switch (interpolation) {
-               case INTERPOLATION_CLOSEST:
-                       compiler.parameter("interpolation", "closest");
-                       break;
-               case INTERPOLATION_CUBIC:
-                       compiler.parameter("interpolation", "cubic");
-                       break;
-               case INTERPOLATION_SMART:
-                       compiler.parameter("interpolation", "smart");
-                       break;
-               case INTERPOLATION_LINEAR:
-               default:
-                       compiler.parameter("interpolation", "linear");
-                       break;
-       }
+       compiler.parameter("interpolation", 
get_osl_interpolation_parameter(interpolation));
 
        switch(extension) {
                case EXTENSION_EXTEND:
@@ -421,6 +421,7 @@ EnvironmentTextureNode::EnvironmentTextureNode()
        filename = "";
        builtin_data = NULL;
        color_space = ustring("Color");
+       interpolation = INTERPOLATION_LINEAR;
        projection = ustring("Equirectangular");
        animated = false;
 
@@ -434,7 +435,7 @@ EnvironmentTextureNode::~EnvironmentTextureNode()
        if(image_manager) {
                image_manager->remove_image(filename,
                                            builtin_data,
-                                           INTERPOLATION_LINEAR,
+                                           interpolation,
                                            EXTENSION_REPEAT);
        }
 }
@@ -477,7 +478,7 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
                                                0,
                                                is_float_bool,
                                                is_linear,
-                                               INTERPOLATION_LINEAR,
+                                               interpolation,
                                                EXTENSION_REPEAT,
                                                use_alpha);
                is_float = (int)is_float_bool;
@@ -546,7 +547,7 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler)
                                                        0,
                                                        is_float_bool,
                                                        is_linear,
-                                                       INTERPOLATION_LINEAR,
+                                                       interpolation,
                                                        EXTENSION_REPEAT,
                                                        use_alpha);
                        is_float = (int)is_float_bool;
@@ -564,6 +565,9 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler)
                compiler.parameter("color_space", "Linear");
        else
                compiler.parameter("color_space", "sRGB");
+
+       compiler.parameter("interpolation", 
get_osl_interpolation_parameter(interpolation));
+
        compiler.parameter("is_float", is_float);
        compiler.parameter("use_alpha", !alpha_out->links.empty());
        compiler.add(this, "node_environment_texture");
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 5065e68..39709c2 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -116,6 +116,7 @@ public:
        void *builtin_data;
        ustring color_space;
        ustring projection;
+       InterpolationType interpolation;
        bool animated;
 
        static ShaderEnum color_space_enum;
diff --git a/source/blender/editors/space_node/drawnode.c 
b/source/blender/editors/space_node/drawnode.c
index ab58746..64b0653 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -857,6 +857,7 @@ static void node_shader_buts_tex_environment(uiLayout 
*layout, bContext *C, Poin
        node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr);
 
        uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
+       uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE);
        uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
 }
 
@@ -898,6 +899,7 @@ static void node_shader_buts_tex_environment_ex(uiLayout 
*layout, bContext *C, P
        }
 
        uiItemR(layout, ptr, "color_space", 0, IFACE_("Color Space"), 
ICON_NONE);
+       uiItemR(layout, ptr, "interpolation", 0, IFACE_("Interpolation"), 
ICON_NONE);
        uiItemR(layout, ptr, "projection", 0, IFACE_("Projection"), ICON_NONE);
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h 
b/source/blender/makesdna/DNA_node_types.h
index 32f766e..1176ce1 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -748,6 +748,8 @@ typedef struct NodeTexEnvironment {
        ImageUser iuser;
        int color_space;
        int projection;
+       int interpolation;
+       int pad;
 } NodeTexEnvironment;
 
 typedef struct NodeTexGradient {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c 
b/source/blender/makesrna/intern/rna_nodetree.c
index 9c93b8e..a51dffb 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3548,17 +3548,29 @@ static void def_sh_tex_sky(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static const EnumPropertyItem sh_tex_prop_color_space_items[] = {
+       {SHD_COLORSPACE_COLOR, "COLOR", 0, "Color",
+                              "Image contains color data, and will be 
converted to linear color for rendering"},
+       {SHD_COLORSPACE_NONE, "NONE", 0, "Non-Color Data",
+                             "Image contains non-color data, for example a 
displacement or normal map, "
+                             "and will not be converted"},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static const EnumPropertyItem sh_tex_prop_interpolation_items[] = {
+       {SHD_INTERP_LINEAR,  "Linear", 0, "Linear",
+                            "Linear interpolation"},
+       {SHD_INTERP_CLOSEST, "Closest", 0, "Closest",
+                            "No interpolation (sample closest texel)"},
+       {SHD_INTERP_CUBIC,   "Cubic", 0, "Cubic",
+                            "Cubic interpolation (CPU only)"},
+       {SHD_INTERP_SMART,   "Smart", 0, "Smart",
+                            "Bicubic when magnifying, else bilinear (OSL 
only)"},
+       {0, NULL, 0, NULL, NULL}
+};
+
 static void def_sh_tex_environment(StructRNA *srna)
 {
-       static const EnumPropertyItem prop_color_space_items[] = {
-               {SHD_COLORSPACE_COLOR, "COLOR", 0, "Color",
-                                      "Image contains color data, and will be 
converted to linear color for rendering"},
-               {SHD_COLORSPACE_NONE, "NONE", 0, "Non-Color Data",
-                                     "Image contains non-color data, for 
example a displacement or normal map, "
-                                     "and will not be converted"},
-               {0, NULL, 0, NULL, NULL}
-       };
-
        static const EnumPropertyItem prop_projection_items[] = {
                {SHD_PROJ_EQUIRECTANGULAR, "EQUIRECTANGULAR", 0, 
"Equirectangular",
                                           "Equirectangular or 
latitude-longitude projection"},
@@ -3580,7 +3592,7 @@ static void def_sh_tex_environment(StructRNA *srna)
        def_sh_tex(srna);
 
        prop = RNA_def_property(srna, "color_space", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_items(prop, prop_color_space_items);
+       RNA_def_property_enum_items(prop, sh_tex_prop_color_space_items);
        RNA_def_property_enum_default(prop, SHD_COLORSPACE_COLOR);
        RNA_def_property_ui_text(prop, "Color Space", "Image file color space");
        RNA_def_property_update(prop, 0, "rna_Node_update");
@@ -3590,6 +3602,11 @@ static void def_sh_tex_environment(StructRNA *srna)
        RNA_def_property_ui_text(prop, "Projection", "Projection of the input 
image");
        RNA_def_property_update(prop, 0, "rna_Node_update");
 
+       prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, sh_tex_prop_interpolation_items);
+       RNA_def_property_ui_text(prop, "Interpolation", "Texture 
interpolation");
+       RNA_def_property_update(prop, 0, "

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to