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
This commit is contained in:
parent
3ab5075cf9
commit
e3abcd6723
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -116,6 +116,7 @@ public:
|
||||
void *builtin_data;
|
||||
ustring color_space;
|
||||
ustring projection;
|
||||
InterpolationType interpolation;
|
||||
bool animated;
|
||||
|
||||
static ShaderEnum color_space_enum;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -748,6 +748,8 @@ typedef struct NodeTexEnvironment {
|
||||
ImageUser iuser;
|
||||
int color_space;
|
||||
int projection;
|
||||
int interpolation;
|
||||
int pad;
|
||||
} NodeTexEnvironment;
|
||||
|
||||
typedef struct NodeTexGradient {
|
||||
|
@ -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, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_NEVER_NULL);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "iuser");
|
||||
@ -3600,15 +3617,6 @@ static void def_sh_tex_environment(StructRNA *srna)
|
||||
|
||||
static void def_sh_tex_image(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_FLAT, "FLAT", 0, "Flat",
|
||||
"Image is projected flat using the X and Y coordinates of the texture vector"},
|
||||
@ -3621,18 +3629,6 @@ static void def_sh_tex_image(StructRNA *srna)
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static const EnumPropertyItem 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 EnumPropertyItem prop_image_extension[] = {
|
||||
{SHD_IMAGE_EXTENSION_REPEAT, "REPEAT", 0, "Repeat", "Cause the image to repeat horizontally and vertically"},
|
||||
{SHD_IMAGE_EXTENSION_EXTEND, "EXTEND", 0, "Extend", "Extend by repeating edge pixels of the image"},
|
||||
@ -3653,7 +3649,7 @@ static void def_sh_tex_image(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");
|
||||
@ -3664,7 +3660,7 @@ static void def_sh_tex_image(StructRNA *srna)
|
||||
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, prop_interpolation_items);
|
||||
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, "rna_Node_update");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user