From 86c7bf733124b2959c4586e2e315e6a4ad53f725 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 21 Jun 2013 13:05:10 +0000 Subject: [PATCH] Fix #35812: cycles image texture node not doing proper alpha handling of PNG images with open shading language enabled. --- intern/cycles/kernel/shaders/node_environment_texture.osl | 3 ++- intern/cycles/kernel/shaders/node_image_texture.osl | 6 +++--- intern/cycles/render/nodes.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/intern/cycles/kernel/shaders/node_environment_texture.osl b/intern/cycles/kernel/shaders/node_environment_texture.osl index bddef418c3d..230116d3d77 100644 --- a/intern/cycles/kernel/shaders/node_environment_texture.osl +++ b/intern/cycles/kernel/shaders/node_environment_texture.osl @@ -49,6 +49,7 @@ shader node_environment_texture( string projection = "Equirectangular", string color_space = "sRGB", int is_float = 1, + int use_alpha = 1, output color Color = 0.0, output float Alpha = 1.0) { @@ -67,7 +68,7 @@ shader node_environment_texture( /* todo: use environment for better texture filtering of equirectangular */ Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", "alpha", Alpha); - if (isconnected(Alpha)) { + if (use_alpha) { Color = color_unpremultiply(Color, Alpha); if (!is_float) diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl index 6ccc7ebc651..92c625e99c4 100644 --- a/intern/cycles/kernel/shaders/node_image_texture.osl +++ b/intern/cycles/kernel/shaders/node_image_texture.osl @@ -30,8 +30,9 @@ color image_texture_lookup(string filename, string color_space, float u, float v rgb = min(rgb, 1.0); } - if (color_space == "sRGB") + if (color_space == "sRGB") { rgb = color_srgb_to_scene_linear(rgb); + } return rgb; } @@ -45,6 +46,7 @@ shader node_image_texture( string projection = "Flat", float projection_blend = 0.0, int is_float = 1, + int use_alpha = 1, output color Color = 0.0, output float Alpha = 1.0) { @@ -53,8 +55,6 @@ shader node_image_texture( if (use_mapping) p = transform(mapping, p); - int use_alpha = isconnected(Alpha); - if (projection == "Flat") { Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha, is_float); } diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 74033d5c2fa..3672b893825 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -237,6 +237,8 @@ void ImageTextureNode::compile(SVMCompiler& compiler) void ImageTextureNode::compile(OSLCompiler& compiler) { + ShaderOutput *alpha_out = output("Alpha"); + tex_mapping.compile(compiler); if(is_float == -1) @@ -250,6 +252,7 @@ void ImageTextureNode::compile(OSLCompiler& compiler) compiler.parameter("projection", projection); compiler.parameter("projection_blend", projection_blend); compiler.parameter("is_float", is_float); + compiler.parameter("use_alpha", !alpha_out->links.empty()); compiler.add(this, "node_image_texture"); } @@ -358,6 +361,8 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler) void EnvironmentTextureNode::compile(OSLCompiler& compiler) { + ShaderOutput *alpha_out = output("Alpha"); + tex_mapping.compile(compiler); if(is_float == -1) @@ -370,6 +375,7 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler) else compiler.parameter("color_space", "sRGB"); compiler.parameter("is_float", is_float); + compiler.parameter("use_alpha", !alpha_out->links.empty()); compiler.add(this, "node_environment_texture"); }