Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/shaders/node_image_texture.osl
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | point map_to_sphere(vector dir) | ||||
| } | } | ||||
| return point(u, v, 0.0); | return point(u, v, 0.0); | ||||
| } | } | ||||
| color image_texture_lookup(string filename, | color image_texture_lookup(string filename, | ||||
| float u, | float u, | ||||
| float v, | float v, | ||||
| output float Alpha, | output float Alpha, | ||||
| int compress_as_srgb, | |||||
| int ignore_alpha, | int ignore_alpha, | ||||
| int unassociate_alpha, | int unassociate_alpha, | ||||
| int is_float, | int is_float, | ||||
| string interpolation, | string interpolation, | ||||
| string extension) | string extension) | ||||
| { | { | ||||
| color rgb = (color)texture( | color rgb = (color)texture( | ||||
| filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha); | filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha); | ||||
| if (ignore_alpha) { | if (ignore_alpha) { | ||||
| Alpha = 1.0; | Alpha = 1.0; | ||||
| } | } | ||||
| else if (unassociate_alpha) { | else if (unassociate_alpha) { | ||||
| rgb = color_unpremultiply(rgb, Alpha); | rgb = color_unpremultiply(rgb, Alpha); | ||||
| if (!is_float) | if (!is_float) | ||||
| rgb = min(rgb, 1.0); | rgb = min(rgb, 1.0); | ||||
| } | } | ||||
| if (compress_as_srgb) { | |||||
| rgb = color_srgb_to_scene_linear(rgb); | |||||
| } | |||||
| return rgb; | return rgb; | ||||
| } | } | ||||
| shader node_image_texture(int use_mapping = 0, | shader node_image_texture(int use_mapping = 0, | ||||
| matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | ||||
| point Vector = P, | point Vector = P, | ||||
| string filename = "", | string filename = "", | ||||
| string projection = "flat", | string projection = "flat", | ||||
| string interpolation = "smartcubic", | string interpolation = "smartcubic", | ||||
| string extension = "periodic", | string extension = "periodic", | ||||
| float projection_blend = 0.0, | float projection_blend = 0.0, | ||||
| int compress_as_srgb = 0, | |||||
| int ignore_alpha = 0, | int ignore_alpha = 0, | ||||
| int unassociate_alpha = 0, | int unassociate_alpha = 0, | ||||
| int is_float = 1, | int is_float = 1, | ||||
| output color Color = 0.0, | output color Color = 0.0, | ||||
| output float Alpha = 1.0) | output float Alpha = 1.0) | ||||
| { | { | ||||
| point p = Vector; | point p = Vector; | ||||
| if (use_mapping) | if (use_mapping) | ||||
| p = transform(mapping, p); | p = transform(mapping, p); | ||||
| if (projection == "flat") { | if (projection == "flat") { | ||||
| Color = image_texture_lookup(filename, | Color = image_texture_lookup(filename, | ||||
| p[0], | p[0], | ||||
| p[1], | p[1], | ||||
| Alpha, | Alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| } | } | ||||
| else if (projection == "box") { | else if (projection == "box") { | ||||
| /* object space normal */ | /* object space normal */ | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | else if (projection == "box") { | ||||
| float tmp_alpha; | float tmp_alpha; | ||||
| if (weight[0] > 0.0) { | if (weight[0] > 0.0) { | ||||
| Color += weight[0] * image_texture_lookup(filename, | Color += weight[0] * image_texture_lookup(filename, | ||||
| p[1], | p[1], | ||||
| p[2], | p[2], | ||||
| tmp_alpha, | tmp_alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| Alpha += weight[0] * tmp_alpha; | Alpha += weight[0] * tmp_alpha; | ||||
| } | } | ||||
| if (weight[1] > 0.0) { | if (weight[1] > 0.0) { | ||||
| Color += weight[1] * image_texture_lookup(filename, | Color += weight[1] * image_texture_lookup(filename, | ||||
| p[0], | p[0], | ||||
| p[2], | p[2], | ||||
| tmp_alpha, | tmp_alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| Alpha += weight[1] * tmp_alpha; | Alpha += weight[1] * tmp_alpha; | ||||
| } | } | ||||
| if (weight[2] > 0.0) { | if (weight[2] > 0.0) { | ||||
| Color += weight[2] * image_texture_lookup(filename, | Color += weight[2] * image_texture_lookup(filename, | ||||
| p[1], | p[1], | ||||
| p[0], | p[0], | ||||
| tmp_alpha, | tmp_alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| Alpha += weight[2] * tmp_alpha; | Alpha += weight[2] * tmp_alpha; | ||||
| } | } | ||||
| } | } | ||||
| else if (projection == "sphere") { | else if (projection == "sphere") { | ||||
| point projected = map_to_sphere(texco_remap_square(p)); | point projected = map_to_sphere(texco_remap_square(p)); | ||||
| Color = image_texture_lookup(filename, | Color = image_texture_lookup(filename, | ||||
| projected[0], | projected[0], | ||||
| projected[1], | projected[1], | ||||
| Alpha, | Alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| } | } | ||||
| else if (projection == "tube") { | else if (projection == "tube") { | ||||
| point projected = map_to_tube(texco_remap_square(p)); | point projected = map_to_tube(texco_remap_square(p)); | ||||
| Color = image_texture_lookup(filename, | Color = image_texture_lookup(filename, | ||||
| projected[0], | projected[0], | ||||
| projected[1], | projected[1], | ||||
| Alpha, | Alpha, | ||||
| compress_as_srgb, | |||||
| ignore_alpha, | ignore_alpha, | ||||
| unassociate_alpha, | unassociate_alpha, | ||||
| is_float, | is_float, | ||||
| interpolation, | interpolation, | ||||
| extension); | extension); | ||||
| } | } | ||||
| } | } | ||||