Eevee: CodeStyle: Fix naming and confusion about the hairs vectors.

This commit is contained in:
Clément Foucault 2018-06-01 23:10:23 +02:00
parent 0736460dfb
commit 4430bd3644
5 changed files with 22 additions and 33 deletions

View File

@ -178,30 +178,18 @@ void CLOSURE_NAME(
vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
#ifdef HAIR_SHADER
vec3 B = normalize(cross(worldNormal, hairTangent));
float cos_theta;
if (hairThicknessRes == 1) {
/* Random normal distribution on the hair surface. */
vec3 T = normalize(worldNormal); /* meh, TODO fix worldNormal misnaming. */
vec3 B = normalize(cross(V, T));
N = cross(T, B); /* Normal facing view */
/* We want a cosine distribution. */
float cos_theta = rand.x * 2.0 - 1.0;
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
N = N * sin_theta + B * cos_theta;
# ifdef CLOSURE_GLOSSY
/* Hair random normal does not work with SSR :(.
* It just create self reflection feedback (which is beautifful btw)
* but not correct. */
ssr_id = NO_SSR; /* Force bypass */
# endif
/* Random cosine normal distribution on the hair surface. */
cos_theta = rand.x * 2.0 - 1.0;
}
else {
vec3 T = normalize(cross(hairTangent, worldNormal));
/* We want a cosine distribution. */
float cos_theta = hairThickTime / hairThickness;
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
N = normalize(hairTangent * cos_theta + T * sin_theta);
/* Shade as a cylinder. */
cos_theta = hairThickTime / hairThickness;
}
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
N = normalize(N * sin_theta + B * cos_theta);
#endif
/* ---------------------------------------------------------------- */

View File

@ -40,17 +40,18 @@ out float hairTime;
void main()
{
#ifdef HAIR_SHADER
vec3 pos, nor;
hair_get_pos_tan_nor_time(
vec3 pos, binor;
hair_get_pos_tan_binor_time(
(ProjectionMatrix[3][3] == 0.0),
ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, nor, hairTangent, hairTime, hairThickness, hairThickTime);
pos, hairTangent, binor, hairTime, hairThickness, hairThickTime);
gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
viewPosition = (ViewMatrix * vec4(pos, 1.0)).xyz;
worldPosition = pos;
worldNormal = nor;
viewNormal = normalize(mat3(ViewMatrixInverse) * nor);
hairTangent = normalize(hairTangent);
worldNormal = cross(binor, hairTangent);
viewNormal = normalize(mat3(ViewMatrix) * worldNormal);
#else
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;

View File

@ -15,11 +15,11 @@ void main()
{
#ifdef HAIR_SHADER
float time, thick_time, thickness;
vec3 pos, nor, binor;
hair_get_pos_tan_nor_time(
vec3 pos, tan, binor;
hair_get_pos_tan_binor_time(
(ProjectionMatrix[3][3] == 0.0),
ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, nor, binor, time, thickness, thick_time);
pos, tan, binor, time, thickness, thick_time);
gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
vec4 worldPosition = vec4(pos, 1.0);

View File

@ -134,9 +134,9 @@ float hair_shaperadius(float shape, float root, float tip, float time)
return (radius * (root - tip)) + tip;
}
void hair_get_pos_tan_nor_time(
void hair_get_pos_tan_binor_time(
bool is_persp, vec3 camera_pos, vec3 camera_z,
out vec3 wpos, out vec3 wtan, out vec3 wnor, out float time, out float thickness, out float thick_time)
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();
vec4 data = texelFetch(hairPointBuffer, id);
@ -151,7 +151,7 @@ void hair_get_pos_tan_nor_time(
}
vec3 camera_vec = (is_persp) ? wpos - camera_pos : -camera_z;
wnor = normalize(cross(camera_vec, wtan));
wbinor = normalize(cross(camera_vec, wtan));
thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
@ -159,7 +159,7 @@ void hair_get_pos_tan_nor_time(
thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
thick_time = thickness * (thick_time * 2.0 - 1.0);
wpos += wnor * thick_time;
wpos += wbinor * thick_time;
}
}

View File

@ -2485,7 +2485,7 @@ void node_hair_info(out float is_strand, out float intercept, out float thicknes
is_strand = 1.0;
intercept = hairTime;
thickness = hairThickness;
tangent = normalize(worldNormal); /* TODO fix naming */
tangent = normalize(hairTangent);
random = 0.0;
#else
is_strand = 0.0;