output normal Normal = NormalIn)
{
color mcolor = 2.0 * color(Color[0] - 0.5, Color[1] - 0.5, Color[2] - 0.5);
+ int is_backfacing = backfacing();
if (space == "tangent") {
vector tangent;
float is_smooth;
getattribute("geom:is_smooth", is_smooth);
- if (!is_smooth)
+ if (!is_smooth) {
ninterp = normalize(transform("world", "object", Ng));
+ /* the normal is already inverted, which is too soon for the math here */
+ if (is_backfacing) {
+ ninterp = -ninterp;
+ }
+ }
+
// get _unnormalized_ interpolated normal and tangent
if (getattribute(attr_name, tangent) &&
getattribute(attr_sign_name, tangent_sign) &&
Normal = normalize(vector(mcolor));
}
-
+
+ /* invert normal for backfacing polygons */
+ if (is_backfacing) {
+ Normal = -Normal;
+ }
+
if (Strength != 1.0)
Normal = normalize(NormalIn + (Normal - NormalIn) * max(Strength, 0.0));
}
float3 color = stack_load_float3(stack, color_offset);
color = 2.0f*make_float3(color.x - 0.5f, color.y - 0.5f, color.z - 0.5f);
+ bool is_backfacing = (ccl_fetch(sd, flag) & SD_BACKFACING) != 0;
float3 N;
if(space == NODE_NORMAL_MAP_TANGENT) {
}
else {
normal = ccl_fetch(sd, Ng);
+
+ /* the normal is already inverted, which is too soon for the math here */
+ if(is_backfacing) {
+ normal = -normal;
+ }
+
object_inverse_normal_transform(kg, sd, &normal);
}
N = safe_normalize(N);
}
+ /* invert normal for backfacing polygons */
+ if(is_backfacing) {
+ N = -N;
+ }
+
float strength = stack_load_float(stack, strength_offset);
if(strength != 1.0f) {