Fix T57891: Radius of strip hair doesn't scale with object scale

Note that this only works fine with uniformly scaled objects.
Otherwise, the hair thickness will vary in a weird way depending on viewing
angles.
This commit is contained in:
2018-11-19 18:24:08 +01:00
parent 86e0d13218
commit 566a4a96cb
4 changed files with 11 additions and 2 deletions

View File

@@ -52,6 +52,7 @@ void main()
vec3 pos, binor;
hair_get_pos_tan_binor_time(
(ProjectionMatrix[3][3] == 0.0),
ModelMatrixInverse,
ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, hairTangent, binor, hairTime, hairThickness, hairThickTime);

View File

@@ -1,6 +1,7 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
#ifdef CLIP_PLANES
/* keep in sync with DRWManager.view_data */
@@ -20,6 +21,7 @@ void main()
vec3 pos, tan, binor;
hair_get_pos_tan_binor_time(
(ProjectionMatrix[3][3] == 0.0),
ModelMatrixInverse,
ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, tan, binor, time, thickness, thick_time);

View File

@@ -1,4 +1,5 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelMatrixInverse;
uniform mat4 ProjectionMatrix;
uniform mat4 ViewProjectionMatrix;
uniform mat4 ViewMatrixInverse;
@@ -41,6 +42,7 @@ void main()
vec3 pos, tan, binor;
hair_get_pos_tan_binor_time(
(ProjectionMatrix[3][3] == 0.0),
ModelMatrixInverse,
ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, tan, binor, time, thickness, thick_time);
/* To "simulate" anisotropic shading, randomize hair normal per strand. */

View File

@@ -135,7 +135,7 @@ float hair_shaperadius(float shape, float root, float tip, float time)
}
void hair_get_pos_tan_binor_time(
bool is_persp, vec3 camera_pos, vec3 camera_z,
bool is_persp, mat4 invmodel_mat, vec3 camera_pos, vec3 camera_z,
out vec3 wpos, out vec3 wtan, out vec3 wbinor, out float time, out float thickness, out float thick_time)
{
int id = hair_get_base_id();
@@ -159,7 +159,11 @@ void hair_get_pos_tan_binor_time(
thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
thick_time = thickness * (thick_time * 2.0 - 1.0);
wpos += wbinor * thick_time;
/* Take object scale into account.
* NOTE: This only works fine with uniform scaling. */
float scale = 1.0 / length(mat3(invmodel_mat) * wbinor);
wpos += wbinor * thick_time * scale;
}
}