Cycles: Support UDIMs with OSL shading
This commit is contained in:
parent
6657fcc783
commit
fa5e28ab08
Notes:
blender-bot
2023-11-06 00:48:59 +01:00
Referenced by issue #72390, Improve UDIM functionality
|
@ -63,11 +63,21 @@ color image_texture_lookup(string filename,
|
|||
int ignore_alpha,
|
||||
int unassociate_alpha,
|
||||
int is_float,
|
||||
int is_tiled,
|
||||
string interpolation,
|
||||
string extension)
|
||||
{
|
||||
/* Flip the y coordinate, but preserve UDIM tiles. */
|
||||
float flip_v;
|
||||
if (is_tiled) {
|
||||
float v_i = (int) v;
|
||||
flip_v = v_i + (1.0 - (v - v_i));
|
||||
}
|
||||
else {
|
||||
flip_v = 1.0 - v;
|
||||
}
|
||||
color rgb = (color)texture(
|
||||
filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
|
||||
filename, u, flip_v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
|
||||
|
||||
if (ignore_alpha) {
|
||||
Alpha = 1.0;
|
||||
|
@ -97,6 +107,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
int compress_as_srgb = 0,
|
||||
int ignore_alpha = 0,
|
||||
int unassociate_alpha = 0,
|
||||
int is_tiled = 0,
|
||||
int is_float = 1,
|
||||
output color Color = 0.0,
|
||||
output float Alpha = 1.0)
|
||||
|
@ -115,6 +126,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
is_tiled,
|
||||
interpolation,
|
||||
extension);
|
||||
}
|
||||
|
@ -193,6 +205,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
0,
|
||||
interpolation,
|
||||
extension);
|
||||
Alpha += weight[0] * tmp_alpha;
|
||||
|
@ -206,6 +219,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
0,
|
||||
interpolation,
|
||||
extension);
|
||||
Alpha += weight[1] * tmp_alpha;
|
||||
|
@ -219,6 +233,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
0,
|
||||
interpolation,
|
||||
extension);
|
||||
Alpha += weight[2] * tmp_alpha;
|
||||
|
@ -234,6 +249,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
0,
|
||||
interpolation,
|
||||
extension);
|
||||
}
|
||||
|
@ -247,6 +263,7 @@ shader node_image_texture(int use_mapping = 0,
|
|||
ignore_alpha,
|
||||
unassociate_alpha,
|
||||
is_float,
|
||||
0,
|
||||
interpolation,
|
||||
extension);
|
||||
}
|
||||
|
|
|
@ -504,11 +504,14 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
|
|||
if (slots.size() == 0) {
|
||||
ImageMetaData metadata;
|
||||
if (builtin_data == NULL) {
|
||||
image_manager->get_image_metadata(filename.string(), NULL, colorspace, metadata);
|
||||
string tile_name = filename.string();
|
||||
if (is_tiled) {
|
||||
tile_name = string_printf(tile_name.c_str(), 1001);
|
||||
}
|
||||
image_manager->get_image_metadata(tile_name, NULL, colorspace, metadata);
|
||||
slots.push_back(-1);
|
||||
}
|
||||
else {
|
||||
/* TODO(lukas): OSL UDIMs */
|
||||
int slot = image_manager->add_image(filename.string(),
|
||||
builtin_data,
|
||||
animated,
|
||||
|
@ -526,8 +529,17 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
|
|||
}
|
||||
|
||||
if (slots[0] == -1) {
|
||||
ustring texture_name = filename;
|
||||
if (is_tiled) {
|
||||
size_t udim_pos = filename.rfind("%04d");
|
||||
if (udim_pos != string::npos) {
|
||||
string texture_name_str = filename.string();
|
||||
texture_name_str.replace(udim_pos, 4, "<UDIM>");
|
||||
texture_name = ustring(texture_name_str);
|
||||
}
|
||||
}
|
||||
compiler.parameter_texture(
|
||||
"filename", filename, compress_as_srgb ? u_colorspace_raw : known_colorspace);
|
||||
"filename", texture_name, compress_as_srgb ? u_colorspace_raw : known_colorspace);
|
||||
}
|
||||
else {
|
||||
compiler.parameter_texture("filename", slots[0]);
|
||||
|
@ -543,6 +555,7 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
|
|||
compiler.parameter("ignore_alpha", alpha_type == IMAGE_ALPHA_IGNORE);
|
||||
compiler.parameter("unassociate_alpha", !alpha_out->links.empty() && unassociate_alpha);
|
||||
compiler.parameter("is_float", is_float);
|
||||
compiler.parameter("is_tiled", is_tiled);
|
||||
compiler.parameter(this, "interpolation");
|
||||
compiler.parameter(this, "extension");
|
||||
|
||||
|
|
Loading…
Reference in New Issue