Eevee / Workbench: Fix hair normals
Hair normals were not behaving correctly. This corrects their looks and fix the node shader geometry that was showing the flat normal.
This commit is contained in:
@@ -47,9 +47,7 @@ void main()
|
|||||||
hairTime,
|
hairTime,
|
||||||
hairThickness,
|
hairThickness,
|
||||||
hairThickTime);
|
hairThickTime);
|
||||||
|
worldNormal = cross(hairTangent, binor);
|
||||||
hairTangent = normalize(hairTangent);
|
|
||||||
worldNormal = cross(binor, hairTangent);
|
|
||||||
worldPosition = pos;
|
worldPosition = pos;
|
||||||
#else
|
#else
|
||||||
worldPosition = point_object_to_world(pos);
|
worldPosition = point_object_to_world(pos);
|
||||||
|
|||||||
@@ -46,12 +46,11 @@ vec3 srgb_to_linear_attr(vec3 c)
|
|||||||
vec3 workbench_hair_hair_normal(vec3 tan, vec3 binor, float rand)
|
vec3 workbench_hair_hair_normal(vec3 tan, vec3 binor, float rand)
|
||||||
{
|
{
|
||||||
/* To "simulate" anisotropic shading, randomize hair normal per strand. */
|
/* To "simulate" anisotropic shading, randomize hair normal per strand. */
|
||||||
tan = normalize(tan);
|
vec3 nor = cross(tan, binor);
|
||||||
vec3 nor = normalize(cross(binor, tan));
|
nor = normalize(mix(nor, -tan, rand * 0.1));
|
||||||
// nor = normalize(mix(nor, -tan, rand * 0.1));
|
float cos_theta = (rand * 2.0 - 1.0) * 0.2;
|
||||||
// float cos_theta = (rand * 2.0 - 1.0) * 0.2;
|
float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
|
||||||
// float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
|
nor = nor * sin_theta + binor * cos_theta;
|
||||||
// nor = nor * sin_theta + binor * cos_theta;
|
|
||||||
return nor;
|
return nor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,9 +160,9 @@ void hair_get_pos_tan_binor_time(bool is_persp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
wpos = (hairDupliMatrix * vec4(wpos, 1.0)).xyz;
|
wpos = (hairDupliMatrix * vec4(wpos, 1.0)).xyz;
|
||||||
wtan = mat3(hairDupliMatrix) * wtan;
|
wtan = -normalize(mat3(hairDupliMatrix) * wtan);
|
||||||
|
|
||||||
vec3 camera_vec = (is_persp) ? wpos - camera_pos : -camera_z;
|
vec3 camera_vec = (is_persp) ? camera_pos - wpos : camera_z;
|
||||||
wbinor = normalize(cross(camera_vec, wtan));
|
wbinor = normalize(cross(camera_vec, wtan));
|
||||||
|
|
||||||
thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
|
thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
|
||||||
|
|||||||
@@ -2038,7 +2038,7 @@ void node_geometry(vec3 I,
|
|||||||
|
|
||||||
position = worldPosition;
|
position = worldPosition;
|
||||||
# ifndef VOLUMETRICS
|
# ifndef VOLUMETRICS
|
||||||
normal = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
|
normal = normalize(N);
|
||||||
vec3 B = dFdx(worldPosition);
|
vec3 B = dFdx(worldPosition);
|
||||||
vec3 T = dFdy(worldPosition);
|
vec3 T = dFdy(worldPosition);
|
||||||
true_normal = normalize(cross(B, T));
|
true_normal = normalize(cross(B, T));
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ static int node_shader_gpu_geometry(GPUMaterial *mat,
|
|||||||
in,
|
in,
|
||||||
out,
|
out,
|
||||||
GPU_builtin(GPU_VIEW_POSITION),
|
GPU_builtin(GPU_VIEW_POSITION),
|
||||||
GPU_builtin(GPU_VIEW_NORMAL),
|
GPU_builtin(GPU_WORLD_NORMAL),
|
||||||
GPU_attribute(CD_ORCO, ""),
|
GPU_attribute(CD_ORCO, ""),
|
||||||
GPU_builtin(GPU_OBJECT_MATRIX),
|
GPU_builtin(GPU_OBJECT_MATRIX),
|
||||||
GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
|
GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
|
||||||
|
|||||||
Reference in New Issue
Block a user