Revision: 36671 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36671 Author: blendix Date: 2011-05-13 14:32:08 +0000 (Fri, 13 May 2011) Log Message: ----------- Cycles: color space control for image/environment texture nodes. Ideally would be automated but need to think about how to do this, not so simply in a node system. But guideline for now is, for color textures set to sRGB, for things like bump or roughness map, set to Linear.
Modified Paths: -------------- branches/cycles/intern/cycles/blender/blender_shader.cpp branches/cycles/intern/cycles/kernel/osl/nodes/node_environment_texture.osl branches/cycles/intern/cycles/kernel/osl/nodes/node_image_texture.osl branches/cycles/intern/cycles/kernel/svm/svm.h branches/cycles/intern/cycles/kernel/svm/svm_image.h branches/cycles/intern/cycles/render/nodes.cpp branches/cycles/intern/cycles/render/nodes.h branches/cycles/source/blender/editors/space_node/drawnode.c branches/cycles/source/blender/makesdna/DNA_node_types.h branches/cycles/source/blender/makesrna/intern/rna_nodetree.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_environment.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_image.c Modified: branches/cycles/intern/cycles/blender/blender_shader.cpp =================================================================== --- branches/cycles/intern/cycles/blender/blender_shader.cpp 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/blender/blender_shader.cpp 2011-05-13 14:32:08 UTC (rev 36671) @@ -282,15 +282,17 @@ /* todo: handle generated/builtin images */ if(b_image) image->filename = blender_absolute_path(b_data, b_image, b_image.filepath()); + image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()]; node = image; break; } case BL::ShaderNode::type_TEX_ENVIRONMENT: { - BL::ShaderNodeTexEnvironment b_environment_node(b_node); - BL::Image b_image(b_environment_node.image()); + BL::ShaderNodeTexEnvironment b_env_node(b_node); + BL::Image b_image(b_env_node.image()); EnvironmentTextureNode *env = new EnvironmentTextureNode(); if(b_image) env->filename = blender_absolute_path(b_data, b_image, b_image.filepath()); + env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()]; node = env; break; } Modified: branches/cycles/intern/cycles/kernel/osl/nodes/node_environment_texture.osl =================================================================== --- branches/cycles/intern/cycles/kernel/osl/nodes/node_environment_texture.osl 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/kernel/osl/nodes/node_environment_texture.osl 2011-05-13 14:32:08 UTC (rev 36671) @@ -21,8 +21,12 @@ shader node_environment_texture( vector Vector = P, string filename = "", + string color_space = "sRGB", output color Color = color(0.0, 0.0, 0.0)) { Color = (color)environment(filename, Vector); + + if(color_space == "sRGB") + Color = color_srgb_to_scene_linear(Color); } Modified: branches/cycles/intern/cycles/kernel/osl/nodes/node_image_texture.osl =================================================================== --- branches/cycles/intern/cycles/kernel/osl/nodes/node_image_texture.osl 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/kernel/osl/nodes/node_image_texture.osl 2011-05-13 14:32:08 UTC (rev 36671) @@ -21,8 +21,12 @@ shader node_image_texture( point Vector = P, string filename = "", + string color_space = "sRGB", output color Color = color(0.0, 0.0, 0.0)) { Color = (color)texture(filename, Vector[0], 1.0-Vector[1], "wrap", "periodic"); + + if(color_space == "sRGB") + Color = color_srgb_to_scene_linear(Color); } Modified: branches/cycles/intern/cycles/kernel/svm/svm.h =================================================================== --- branches/cycles/intern/cycles/kernel/svm/svm.h 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/kernel/svm/svm.h 2011-05-13 14:32:08 UTC (rev 36671) @@ -190,9 +190,9 @@ else if(node.x == NODE_TEX_NOISE_V) svm_node_tex_noise_v(sd, stack, node.y, node.z); else if(node.x == NODE_TEX_IMAGE) - svm_node_tex_image(kg, sd, stack, node.y, node.z, node.w); + svm_node_tex_image(kg, sd, stack, node); else if(node.x == NODE_TEX_ENVIRONMENT) - svm_node_tex_environment(kg, sd, stack, node.y, node.z, node.w); + svm_node_tex_environment(kg, sd, stack, node); else if(node.x == NODE_TEX_SKY) svm_node_tex_sky(kg, sd, stack, node.y, node.z); else if(node.x == NODE_TEX_BLEND) Modified: branches/cycles/intern/cycles/kernel/svm/svm_image.h =================================================================== --- branches/cycles/intern/cycles/kernel/svm/svm_image.h 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/kernel/svm/svm_image.h 2011-05-13 14:32:08 UTC (rev 36671) @@ -140,22 +140,40 @@ return r; } -__device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint id, uint co_offset, uint out_offset) +__device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { + uint id = node.y; + uint co_offset, out_offset, srgb; + + decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL); + float3 co = stack_load_float3(stack, co_offset); float4 f = svm_image_texture(kg, id, co.x, co.y); + float3 r = make_float3(f.x, f.y, f.z); - stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); + if(srgb) + r = color_srgb_to_scene_linear(r); + + stack_store_float3(stack, out_offset, r); } -__device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint id, uint co_offset, uint out_offset) +__device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { + uint id = node.y; + uint co_offset, out_offset, srgb; + + decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL); + float3 co = stack_load_float3(stack, co_offset); float u = (atan2f(co.y, co.x) + M_PI_F)/(2*M_PI_F); float v = atan2f(co.z, hypotf(co.x, co.y))/M_PI_F + 0.5f; float4 f = svm_image_texture(kg, id, u, v); + float3 r = make_float3(f.x, f.y, f.z); - stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); + if(srgb) + r = color_srgb_to_scene_linear(r); + + stack_store_float3(stack, out_offset, r); } CCL_NAMESPACE_END Modified: branches/cycles/intern/cycles/render/nodes.cpp =================================================================== --- branches/cycles/intern/cycles/render/nodes.cpp 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/render/nodes.cpp 2011-05-13 14:32:08 UTC (rev 36671) @@ -27,12 +27,25 @@ /* Image Texture */ +static ShaderEnum color_space_init() +{ + ShaderEnum enm; + + enm.insert("Linear", 0); + enm.insert("sRGB", 1); + + return enm; +} + +ShaderEnum ImageTextureNode::color_space_enum = color_space_init(); + ImageTextureNode::ImageTextureNode() : ShaderNode("image_texture") { image_manager = NULL; slot = -1; filename = ""; + color_space = ustring("sRGB"); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_COORDINATE); add_output("Color", SHADER_SOCKET_COLOR); @@ -65,7 +78,12 @@ if(slot != -1) { compiler.stack_assign(vector_in); - compiler.add_node(NODE_TEX_IMAGE, slot, vector_in->stack_offset, color_out->stack_offset); + compiler.add_node(NODE_TEX_IMAGE, + slot, + compiler.encode_uchar4( + vector_in->stack_offset, + color_out->stack_offset, + color_space_enum[color_space])); } else { /* image not found */ @@ -77,17 +95,21 @@ void ImageTextureNode::compile(OSLCompiler& compiler) { compiler.parameter("filename", filename.c_str()); + compiler.parameter("color_space", color_space.c_str()); compiler.add(this, "node_image_texture"); } /* Environment Texture */ +ShaderEnum EnvironmentTextureNode::color_space_enum = color_space_init(); + EnvironmentTextureNode::EnvironmentTextureNode() : ShaderNode("environment_texture") { image_manager = NULL; slot = -1; filename = ""; + color_space = ustring("sRGB"); add_input("Vector", SHADER_SOCKET_VECTOR, ShaderInput::POSITION); add_output("Color", SHADER_SOCKET_COLOR); @@ -120,7 +142,12 @@ if(slot != -1) { compiler.stack_assign(vector_in); - compiler.add_node(NODE_TEX_ENVIRONMENT, slot, vector_in->stack_offset, color_out->stack_offset); + compiler.add_node(NODE_TEX_ENVIRONMENT, + slot, + compiler.encode_uchar4( + vector_in->stack_offset, + color_out->stack_offset, + color_space_enum[color_space])); } else { /* image not found */ @@ -132,6 +159,7 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler) { compiler.parameter("filename", filename.c_str()); + compiler.parameter("color_space", color_space.c_str()); compiler.add(this, "node_environment_texture"); } Modified: branches/cycles/intern/cycles/render/nodes.h =================================================================== --- branches/cycles/intern/cycles/render/nodes.h 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/intern/cycles/render/nodes.h 2011-05-13 14:32:08 UTC (rev 36671) @@ -39,6 +39,9 @@ ImageManager *image_manager; int slot; string filename; + ustring color_space; + + static ShaderEnum color_space_enum; }; class EnvironmentTextureNode : public ShaderNode { @@ -50,6 +53,9 @@ ImageManager *image_manager; int slot; string filename; + ustring color_space; + + static ShaderEnum color_space_enum; }; class SkyTextureNode : public ShaderNode { Modified: branches/cycles/source/blender/editors/space_node/drawnode.c =================================================================== --- branches/cycles/source/blender/editors/space_node/drawnode.c 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/source/blender/editors/space_node/drawnode.c 2011-05-13 14:32:08 UTC (rev 36671) @@ -400,6 +400,7 @@ { //uiItemR(layout, ptr, "image", 0, "", ICON_NONE); uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); + uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); } static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) Modified: branches/cycles/source/blender/makesdna/DNA_node_types.h =================================================================== --- branches/cycles/source/blender/makesdna/DNA_node_types.h 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/source/blender/makesdna/DNA_node_types.h 2011-05-13 14:32:08 UTC (rev 36671) @@ -355,11 +355,11 @@ } NodeTexSky; typedef struct NodeTexImage { - int pad; + int color_space; } NodeTexImage; typedef struct NodeTexEnvironment { - int pad; + int color_space; } NodeTexEnvironment; typedef struct NodeTexBlend { @@ -499,6 +499,10 @@ #define SHD_WOOD_BAND_NOISE 2 #define SHD_WOOD_RING_NOISE 3 +/* image/environment texture */ +#define SHD_COLORSPACE_LINEAR 0 +#define SHD_COLORSPACE_SRGB 1 + /* blur node */ #define CMP_NODE_BLUR_ASPECT_NONE 0 #define CMP_NODE_BLUR_ASPECT_Y 1 Modified: branches/cycles/source/blender/makesrna/intern/rna_nodetree.c =================================================================== --- branches/cycles/source/blender/makesrna/intern/rna_nodetree.c 2011-05-13 14:29:07 UTC (rev 36670) +++ branches/cycles/source/blender/makesrna/intern/rna_nodetree.c 2011-05-13 14:32:08 UTC (rev 36671) @@ -1044,6 +1044,11 @@ static void def_sh_tex_environment(StructRNA *srna) { + static const EnumPropertyItem prop_color_space_items[]= { + {SHD_COLORSPACE_SRGB, "SRGB", 0, "sRGB", "Image is in sRGB color space"}, @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs