Cycles: improve Anisotropic BSDF node, changing the Roughness U/V inputs to
Roughness, Anisotropy and Rotation. Also a fix for automatic tangents and OSL attribute handling. Meaning of new sockets explained in the documentation: http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/Shaders#Anisotropic
This commit is contained in:
@@ -32,7 +32,6 @@ shader node_geometry(
|
||||
{
|
||||
Position = P;
|
||||
Normal = NormalIn;
|
||||
Tangent = normalize(dPdu);
|
||||
TrueNormal = Ng;
|
||||
Incoming = I;
|
||||
Parametric = point(u, v, 0.0);
|
||||
@@ -46,5 +45,28 @@ shader node_geometry(
|
||||
Position += Dy(Position);
|
||||
Parametric += Dy(Parametric);
|
||||
}
|
||||
|
||||
/* first try to get tangent attribute */
|
||||
vector T;
|
||||
|
||||
if (getattribute("geom:tangent", T)) {
|
||||
/* ensure orthogonal and normalized (interpolation breaks it) */
|
||||
T = transform("object", "world", T);
|
||||
Tangent = cross(Normal, normalize(cross(T, Normal)));
|
||||
}
|
||||
else {
|
||||
point generated;
|
||||
|
||||
/* try to create spherical tangent from generated coordinates */
|
||||
if (getattribute("geom:generated", generated)) {
|
||||
T = vector(-(generated[1] - 0.5), (generated[0] - 0.5), 0.0);
|
||||
T = transform("object", "world", T);
|
||||
Tangent = cross(Normal, normalize(cross(T, Normal)));
|
||||
}
|
||||
else {
|
||||
/* otherwise use surface derivatives */
|
||||
Tangent = normalize(dPdu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,11 +20,32 @@
|
||||
|
||||
shader node_ward_bsdf(
|
||||
color Color = color(0.8, 0.8, 0.8),
|
||||
float RoughnessU = 0.0,
|
||||
float RoughnessV = 0.0,
|
||||
float Roughness = 0.0,
|
||||
float Anisotropy = 0.0,
|
||||
float Rotation = 0.0,
|
||||
normal Normal = N,
|
||||
normal Tangent = normalize(dPdu),
|
||||
output closure color BSDF = diffuse(Normal))
|
||||
{
|
||||
BSDF = Color * ward(Normal, normalize(dPdu), RoughnessU, RoughnessV);
|
||||
/* rotate tangent around normal */
|
||||
vector T = Tangent;
|
||||
|
||||
if(Rotation != 0.0)
|
||||
T = rotate(T, Rotation*2.0*M_PI, point(0.0, 0.0, 0.0), Normal);
|
||||
|
||||
/* compute roughness */
|
||||
float RoughnessU, RoughnessV;
|
||||
float aniso = clamp(Anisotropy, -0.99, 0.99);
|
||||
|
||||
if(aniso < 0.0) {
|
||||
RoughnessU = Roughness*(1.0 + aniso);
|
||||
RoughnessV = Roughness/(1.0 + aniso);
|
||||
}
|
||||
else {
|
||||
RoughnessU = Roughness/(1.0 - aniso);
|
||||
RoughnessV = Roughness*(1.0 - aniso);
|
||||
}
|
||||
|
||||
BSDF = Color * ward(Normal, T, RoughnessU, RoughnessV);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user