[Bf-blender-cvs] [0c1c69d8df4] blender2.8: Eevee: Hair: Remove old hack and replace by new hack.
Clément Foucault
noreply at git.blender.org
Sun May 13 22:36:42 CEST 2018
Commit: 0c1c69d8df45ce59ca59cdb1c8aebcb93926f0d1
Author: Clément Foucault
Date: Sun May 13 22:20:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0c1c69d8df45ce59ca59cdb1c8aebcb93926f0d1
Eevee: Hair: Remove old hack and replace by new hack.
This is a hack to properly shade wire hairs. Use stochastic sampling and
let TAA solve the noise.
At least it's way more correct than the previous hack.
===================================================================
M source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
M source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
index 62f4c0c1c93..198a05ccf97 100644
--- a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
@@ -423,31 +423,3 @@ vec3 light_translucent(LightData ld, vec3 W, vec3 N, vec4 l_vector, float scale)
return vis;
#endif
}
-
-#ifdef HAIR_SHADER
-void light_hair_common(
- LightData ld, vec3 N, vec3 V, vec4 l_vector, vec3 norm_view,
- out float occlu_trans, out float occlu,
- out vec3 norm_lamp, out vec3 view_vec)
-{
- const float transmission = 0.3; /* Uniform internal scattering factor */
-
- vec3 lamp_vec;
-
- if (ld.l_type == SUN || ld.l_type == AREA) {
- lamp_vec = ld.l_forward;
- }
- else {
- lamp_vec = -l_vector.xyz;
- }
-
- norm_lamp = cross(lamp_vec, N);
- norm_lamp = normalize(cross(N, norm_lamp)); /* Normal facing lamp */
-
- /* Rotate view vector onto the cross(tangent, light) plane */
- view_vec = normalize(norm_lamp * dot(norm_view, V) + N * dot(N, V));
-
- occlu = (dot(norm_view, norm_lamp) * 0.5 + 0.5);
- occlu_trans = transmission + (occlu * (1.0 - transmission)); /* Includes transmission component */
-}
-#endif
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index 88fde8929cb..d777f9f5397 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -168,15 +168,19 @@ void CLOSURE_NAME(
vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
+#ifdef HAIR_SHADER
+ /* 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 */
+
+ N = N * abs(rand.z) + B * rand.y;
+#endif
+
/* ---------------------------------------------------------------- */
/* -------------------- SCENE LAMPS LIGHTING ---------------------- */
/* ---------------------------------------------------------------- */
-#ifdef HAIR_SHADER
- vec3 norm_view = cross(V, N);
- norm_view = normalize(cross(norm_view, N)); /* Normal facing view */
-#endif
-
for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) {
LightData ld = lights_data[i];
@@ -186,29 +190,6 @@ void CLOSURE_NAME(
vec3 l_color_vis = ld.l_color * light_visibility(ld, worldPosition, viewPosition, viewNormal, l_vector);
-#ifdef HAIR_SHADER
- vec3 norm_lamp, view_vec;
- float occlu_trans, occlu;
- light_hair_common(ld, N, V, l_vector, norm_view, occlu_trans, occlu, norm_lamp, view_vec);
-
- #ifdef CLOSURE_DIFFUSE
- out_diff += l_color_vis * light_diffuse(ld, -norm_lamp, V, l_vector) * occlu_trans;
- #endif
-
- #ifdef CLOSURE_SUBSURFACE
- out_trans += ld.l_color * light_translucent(ld, worldPosition, -norm_lamp, l_vector, sss_scale) * occlu_trans;
- #endif
-
- #ifdef CLOSURE_GLOSSY
- out_spec += l_color_vis * light_specular(ld, N, view_vec, l_vector, roughnessSquared, f0) * occlu * ld.l_spec;
- #endif
-
- #ifdef CLOSURE_CLEARCOAT
- out_spec += l_color_vis * light_specular(ld, C_N, view_vec, l_vector, C_roughnessSquared, f0) * C_intensity * occlu * ld.l_spec;
- #endif
-
-#else /* HAIR_SHADER */
-
#ifdef CLOSURE_DIFFUSE
out_diff += l_color_vis * light_diffuse(ld, N, V, l_vector);
#endif
@@ -224,15 +205,8 @@ void CLOSURE_NAME(
#ifdef CLOSURE_CLEARCOAT
out_spec += l_color_vis * light_specular(ld, C_N, V, l_vector, C_roughnessSquared, f0) * C_intensity * ld.l_spec;
#endif
-
-#endif /* HAIR_SHADER */
}
-#ifdef HAIR_SHADER
- N = -norm_view;
-#endif
-
-
/* ---------------------------------------------------------------- */
/* ---------------- SPECULAR ENVIRONMENT LIGHTING ----------------- */
More information about the Bf-blender-cvs
mailing list