Cycles Hair:
authorThomas Dinges <blender@dingto.org>
Sat, 29 Dec 2012 01:57:32 +0000 (01:57 +0000)
committerThomas Dinges <blender@dingto.org>
Sat, 29 Dec 2012 01:57:32 +0000 (01:57 +0000)
* Implemented the Hair Info Node for OSL.

intern/cycles/kernel/osl/osl_services.cpp
intern/cycles/kernel/osl/osl_services.h
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/kernel/shaders/node_hair_info.osl [new file with mode: 0644]
intern/cycles/render/nodes.cpp

index 498d10f385bd48cf5c0eb13d76930f6528eac5de..64c4d10945242b0a9798f1701a7d42a6aaaf442a 100644 (file)
@@ -74,6 +74,12 @@ ustring OSLRenderServices::u_geom_numpolyvertices("geom:numpolyvertices");
 ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices");
 ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices");
 ustring OSLRenderServices::u_geom_name("geom:name");
+#ifdef __HAIR__
+ustring OSLRenderServices::u_curve_is_strand("curve:is_strand");
+ustring OSLRenderServices::u_curve_intercept("curve:intercept");
+ustring OSLRenderServices::u_curve_thickness("curve:thickness");
+ustring OSLRenderServices::u_curve_tangent_normal("curve:tangent_normal");
+#endif
 ustring OSLRenderServices::u_path_ray_length("path:ray_length");
 ustring OSLRenderServices::u_trace("trace");
 ustring OSLRenderServices::u_hit("hit");
@@ -593,6 +599,8 @@ bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderD
                float3 f = particle_angular_velocity(kg, particle_id);
                return set_attribute_float3(f, type, derivatives, val);
        }
+       
+       /* Geometry Attributes */
        else if (name == u_geom_numpolyvertices) {
                return set_attribute_int(3, type, derivatives, val);
        }
@@ -612,6 +620,26 @@ bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderD
                ustring object_name = kg->osl->object_names[sd->object];
                return set_attribute_string(object_name, type, derivatives, val);
        }
+       
+#ifdef __HAIR__
+       /* Hair Attributes */
+       else if (name == u_curve_is_strand) {
+               float f = !(sd->curve_seg == ~0);
+               return set_attribute_float(f, type, derivatives, val);
+       }
+       else if (name == u_curve_intercept) {
+               float f = intercept(kg, sd->curve_seg, sd->prim, sd->u);
+               return set_attribute_float(f, type, derivatives, val);
+       }
+       else if (name == u_curve_thickness) {
+               float f = 2 * hair_radius(kg, sd->curve_seg, sd->u);
+               return set_attribute_float(f, type, derivatives, val);
+       }
+       else if (name == u_curve_tangent_normal) {
+               float3 f = hair_tangent_normal(kg, sd);
+               return set_attribute_float3(f, type, derivatives, val);
+       }
+#endif
        else
                return false;
 }
index cd4a4163209a5f900937b52beff1b12af83089f1..9b7c9a423ffa90bdd5ad179c0c22976640880534 100644 (file)
@@ -130,6 +130,10 @@ public:
        static ustring u_geom_trianglevertices;
        static ustring u_geom_polyvertices;
        static ustring u_geom_name;
+       static ustring u_curve_is_strand;
+       static ustring u_curve_intercept;
+       static ustring u_curve_thickness;
+       static ustring u_curve_tangent_normal;
        static ustring u_path_ray_length;
        static ustring u_trace;
        static ustring u_hit;
index 70fc8610c985fb4c70034e0dce09ef227990a9d6..acae46f1615ac365d868b39ed94ab9faf3a74075 100644 (file)
@@ -27,6 +27,7 @@ set(SRC_OSL
        node_glass_bsdf.osl
        node_glossy_bsdf.osl
        node_gradient_texture.osl
+       node_hair_info.osl
        node_holdout.osl
        node_hsv.osl
        node_image_texture.osl
diff --git a/intern/cycles/kernel/shaders/node_hair_info.osl b/intern/cycles/kernel/shaders/node_hair_info.osl
new file mode 100644 (file)
index 0000000..a44fc67
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "stdosl.h"
+
+shader node_hair_info(
+       output float IsStrand = 0.0,
+       output float Intercept = 0.0,
+       output float Thickness = 0.0,
+       output normal TangentNormal = N)
+{
+       getattribute("curve:is_strand", IsStrand);
+       getattribute("curve:intercept", Intercept);
+       getattribute("curve:thickness", Thickness);
+       getattribute("curve:tangent_normal", TangentNormal);
+}
+
index 23d6432616c7df82a5f4154d1c9b0fcf1a314ffe..13e9ae81cf0e66de8ff122defe09bda92213d9ec 100644 (file)
@@ -2283,7 +2283,7 @@ void HairInfoNode::compile(SVMCompiler& compiler)
 
 void HairInfoNode::compile(OSLCompiler& compiler)
 {
-       compiler.add(this, "NODE_HAIR_INFO");
+       compiler.add(this, "node_hair_info");
 }
 
 /* Value */