Fix #35306: cycles normal mapping not working with flat shading.

This commit is contained in:
Brecht Van Lommel
2013-05-11 09:31:58 +00:00
parent 18fda6d84c
commit 561cf26c2f
5 changed files with 33 additions and 11 deletions

View File

@@ -106,9 +106,16 @@ static void mikk_get_normal(const SMikkTSpaceContext *context, float N[3], const
{ {
MikkUserData *userdata = (MikkUserData*)context->m_pUserData; MikkUserData *userdata = (MikkUserData*)context->m_pUserData;
BL::MeshTessFace f = userdata->mesh.tessfaces[face_num]; BL::MeshTessFace f = userdata->mesh.tessfaces[face_num];
int4 vi = get_int4(f.vertices_raw()); float3 vN;
BL::MeshVertex v = userdata->mesh.vertices[vi[vert_num]];
float3 vN = get_float3(v.normal()); if(f.use_smooth()) {
int4 vi = get_int4(f.vertices_raw());
BL::MeshVertex v = userdata->mesh.vertices[vi[vert_num]];
vN = get_float3(v.normal());
}
else {
vN = get_float3(f.normal());
}
N[0] = vN.x; N[0] = vN.x;
N[1] = vN.y; N[1] = vN.y;

View File

@@ -76,6 +76,7 @@ ustring OSLRenderServices::u_geom_numpolyvertices("geom:numpolyvertices");
ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices"); ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices");
ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices"); ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices");
ustring OSLRenderServices::u_geom_name("geom:name"); ustring OSLRenderServices::u_geom_name("geom:name");
ustring OSLRenderServices::u_is_smooth("geom:is_smooth");
#ifdef __HAIR__ #ifdef __HAIR__
ustring OSLRenderServices::u_is_curve("geom:is_curve"); ustring OSLRenderServices::u_is_curve("geom:is_curve");
ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness"); ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness");
@@ -626,7 +627,10 @@ bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderD
ustring object_name = kg->osl->object_names[sd->object]; ustring object_name = kg->osl->object_names[sd->object];
return set_attribute_string(object_name, type, derivatives, val); return set_attribute_string(object_name, type, derivatives, val);
} }
else if (name == u_is_smooth) {
float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
return set_attribute_float(f, type, derivatives, val);
}
#ifdef __HAIR__ #ifdef __HAIR__
/* Hair Attributes */ /* Hair Attributes */
else if (name == u_is_curve) { else if (name == u_is_curve) {

View File

@@ -130,6 +130,7 @@ public:
static ustring u_geom_trianglevertices; static ustring u_geom_trianglevertices;
static ustring u_geom_polyvertices; static ustring u_geom_polyvertices;
static ustring u_geom_name; static ustring u_geom_name;
static ustring u_is_smooth;
static ustring u_is_curve; static ustring u_is_curve;
static ustring u_curve_thickness; static ustring u_curve_thickness;
static ustring u_curve_tangent_normal; static ustring u_curve_tangent_normal;

View File

@@ -33,15 +33,17 @@ shader node_normal_map(
vector tangent; vector tangent;
vector ninterp; vector ninterp;
float tangent_sign; float tangent_sign;
float is_smooth;
getattribute("geom:is_smooth", is_smooth);
if (!is_smooth)
ninterp = Ng;
// get _unnormalized_ interpolated normal and tangent // get _unnormalized_ interpolated normal and tangent
if (!getattribute(attr_name, tangent) || if (getattribute(attr_name, tangent) &&
!getattribute(attr_sign_name, tangent_sign) || getattribute(attr_sign_name, tangent_sign) &&
!getattribute("geom:N", ninterp)) (!is_smooth || getattribute("geom:N", ninterp)))
{ {
Normal = normal(0, 0, 0);
}
else {
// apply normal map // apply normal map
vector B = tangent_sign * cross(ninterp, tangent); vector B = tangent_sign * cross(ninterp, tangent);
Normal = normalize(mcolor[0] * tangent + mcolor[1] * B + mcolor[2] * ninterp); Normal = normalize(mcolor[0] * tangent + mcolor[1] * B + mcolor[2] * ninterp);
@@ -49,6 +51,9 @@ shader node_normal_map(
// transform to world space // transform to world space
Normal = normalize(transform("object", "world", Normal)); Normal = normalize(transform("object", "world", Normal));
} }
else {
Normal = normal(0, 0, 0);
}
} }
else if (space == "Object") else if (space == "Object")
Normal = normalize(transform("object", "world", vector(mcolor))); Normal = normalize(transform("object", "world", vector(mcolor)));

View File

@@ -261,7 +261,12 @@ __device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *stac
/* get _unnormalized_ interpolated normal and tangent */ /* get _unnormalized_ interpolated normal and tangent */
float3 tangent = primitive_attribute_float3(kg, sd, attr_elem, attr_offset, NULL, NULL); float3 tangent = primitive_attribute_float3(kg, sd, attr_elem, attr_offset, NULL, NULL);
float sign = primitive_attribute_float(kg, sd, attr_sign_elem, attr_sign_offset, NULL, NULL); float sign = primitive_attribute_float(kg, sd, attr_sign_elem, attr_sign_offset, NULL, NULL);
float3 normal = primitive_attribute_float3(kg, sd, attr_normal_elem, attr_normal_offset, NULL, NULL); float3 normal;
if(sd->shader & SHADER_SMOOTH_NORMAL)
normal = primitive_attribute_float3(kg, sd, attr_normal_elem, attr_normal_offset, NULL, NULL);
else
normal = sd->N;
/* apply normal map */ /* apply normal map */
float3 B = sign * cross(normal, tangent); float3 B = sign * cross(normal, tangent);