Fix T43755: Wireframe attribute doesn't work with displace
[blender.git] / intern / cycles / render / nodes.cpp
index 625b829ba2432697fea81664b57b9eda115de98f..7a39811cacd24b900ae62030d798ea243e508122 100644 (file)
@@ -174,8 +174,10 @@ static ShaderEnum image_projection_init()
 {
        ShaderEnum enm;
 
-       enm.insert("Flat", 0);
-       enm.insert("Box", 1);
+       enm.insert("Flat", NODE_IMAGE_PROJ_FLAT);
+       enm.insert("Box", NODE_IMAGE_PROJ_BOX);
+       enm.insert("Sphere", NODE_IMAGE_PROJ_SPHERE);
+       enm.insert("Tube", NODE_IMAGE_PROJ_TUBE);
 
        return enm;
 }
@@ -266,14 +268,15 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
                        tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset);
                }
 
-               if(projection == "Flat") {
+               if(projection != "Box") {
                        compiler.add_node(NODE_TEX_IMAGE,
                                slot,
                                compiler.encode_uchar4(
                                        vector_offset,
                                        color_out->stack_offset,
                                        alpha_out->stack_offset,
-                                       srgb));
+                                       srgb),
+                               projection_enum[projection]);
                }
                else {
                        compiler.add_node(NODE_TEX_IMAGE_BOX,
@@ -285,7 +288,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
                                        srgb),
                                __float_as_int(projection_blend));
                }
-       
+
                if(vector_offset != vector_in->stack_offset)
                        compiler.stack_clear_offset(vector_in->type, vector_offset);
        }
@@ -1946,6 +1949,8 @@ void EmissionNode::compile(OSLCompiler& compiler)
 BackgroundNode::BackgroundNode()
 : ShaderNode("background")
 {
+       special_type = SHADER_SPECIAL_TYPE_BACKGROUND;
+
        add_input("Color", SHADER_SOCKET_COLOR, make_float3(0.8f, 0.8f, 0.8f));
        add_input("Strength", SHADER_SOCKET_FLOAT, 1.0f);
        add_input("SurfaceMixWeight", SHADER_SOCKET_FLOAT, 0.0f, ShaderInput::USE_SVM);
@@ -2166,13 +2171,18 @@ GeometryNode::GeometryNode()
        add_output("Incoming", SHADER_SOCKET_VECTOR);
        add_output("Parametric", SHADER_SOCKET_POINT);
        add_output("Backfacing", SHADER_SOCKET_FLOAT);
+       add_output("Pointiness", SHADER_SOCKET_FLOAT);
 }
 
 void GeometryNode::attributes(Shader *shader, AttributeRequestSet *attributes)
 {
        if(shader->has_surface) {
-               if(!output("Tangent")->links.empty())
+               if(!output("Tangent")->links.empty()) {
                        attributes->add(ATTR_STD_GENERATED);
+               }
+               if(!output("Pointiness")->links.empty()) {
+                       attributes->add(ATTR_STD_POINTINESS);
+               }
        }
 
        ShaderNode::attributes(shader, attributes);
@@ -2182,11 +2192,16 @@ void GeometryNode::compile(SVMCompiler& compiler)
 {
        ShaderOutput *out;
        NodeType geom_node = NODE_GEOMETRY;
+       NodeType attr_node = NODE_ATTR;
 
-       if(bump == SHADER_BUMP_DX)
+       if(bump == SHADER_BUMP_DX) {
                geom_node = NODE_GEOMETRY_BUMP_DX;
-       else if(bump == SHADER_BUMP_DY)
+               attr_node = NODE_ATTR_BUMP_DX;
+       }
+       else if(bump == SHADER_BUMP_DY) {
                geom_node = NODE_GEOMETRY_BUMP_DY;
+               attr_node = NODE_ATTR_BUMP_DY;
+       }
        
        out = output("Position");
        if(!out->links.empty()) {
@@ -2229,6 +2244,15 @@ void GeometryNode::compile(SVMCompiler& compiler)
                compiler.stack_assign(out);
                compiler.add_node(NODE_LIGHT_PATH, NODE_LP_backfacing, out->stack_offset);
        }
+
+       out = output("Pointiness");
+       if(!out->links.empty()) {
+               compiler.stack_assign(out);
+               compiler.add_node(attr_node,
+                                 ATTR_STD_POINTINESS,
+                                 out->stack_offset,
+                                 NODE_ATTR_FLOAT);
+       }
 }
 
 void GeometryNode::compile(OSLCompiler& compiler)
@@ -2258,6 +2282,8 @@ TextureCoordinateNode::TextureCoordinateNode()
        add_output("Reflection", SHADER_SOCKET_NORMAL);
 
        from_dupli = false;
+       use_transform = false;
+       ob_tfm = transform_identity();
 }
 
 void TextureCoordinateNode::attributes(Shader *shader, AttributeRequestSet *attributes)
@@ -2345,7 +2371,14 @@ void TextureCoordinateNode::compile(SVMCompiler& compiler)
        out = output("Object");
        if(!out->links.empty()) {
                compiler.stack_assign(out);
-               compiler.add_node(texco_node, NODE_TEXCO_OBJECT, out->stack_offset);
+               compiler.add_node(texco_node, NODE_TEXCO_OBJECT, out->stack_offset, use_transform);
+               if(use_transform) {
+                       Transform ob_itfm = transform_inverse(ob_tfm);
+                       compiler.add_node(ob_itfm.x);
+                       compiler.add_node(ob_itfm.y);
+                       compiler.add_node(ob_itfm.z);
+                       compiler.add_node(ob_itfm.w);
+               }
        }
 
        out = output("Camera");
@@ -2386,7 +2419,10 @@ void TextureCoordinateNode::compile(OSLCompiler& compiler)
                compiler.parameter("is_background", true);
        if(compiler.output_type() == SHADER_TYPE_VOLUME)
                compiler.parameter("is_volume", true);
-       
+       compiler.parameter("use_transform", use_transform);
+       Transform ob_itfm = transform_transpose(transform_inverse(ob_tfm));
+       compiler.parameter("object_itfm", ob_itfm);
+
        compiler.parameter("from_dupli", from_dupli);
 
        compiler.add(this, "node_texture_coordinate");
@@ -3541,14 +3577,34 @@ void WireframeNode::compile(SVMCompiler& compiler)
 {
        ShaderInput *size_in = input("Size");
        ShaderOutput *fac_out = output("Fac");
-
+       NodeBumpOffset bump_offset = NODE_BUMP_OFFSET_CENTER;
+       if(bump == SHADER_BUMP_DX) {
+               bump_offset = NODE_BUMP_OFFSET_DX;
+       }
+       else if(bump == SHADER_BUMP_DY) {
+               bump_offset = NODE_BUMP_OFFSET_DY;
+       }
        compiler.stack_assign(size_in);
        compiler.stack_assign(fac_out);
-       compiler.add_node(NODE_WIREFRAME, size_in->stack_offset, fac_out->stack_offset, use_pixel_size);
+       compiler.add_node(NODE_WIREFRAME,
+                         size_in->stack_offset,
+                         fac_out->stack_offset,
+                         compiler.encode_uchar4(use_pixel_size,
+                                                bump_offset,
+                                                0, 0));
 }
 
 void WireframeNode::compile(OSLCompiler& compiler)
 {
+       if(bump == SHADER_BUMP_DX) {
+               compiler.parameter("bump_offset", "dx");
+       }
+       else if(bump == SHADER_BUMP_DY) {
+               compiler.parameter("bump_offset", "dy");
+       }
+       else {
+               compiler.parameter("bump_offset", "center");
+       }
        compiler.parameter("use_pixel_size", use_pixel_size);
        compiler.add(this, "node_wireframe");
 }