[Bf-blender-cvs] [08a2c5f2249] blender2.8: Eevee: Add support for hair random property.

Clément Foucault noreply at git.blender.org
Sat Jun 2 21:22:34 CEST 2018


Commit: 08a2c5f2249c89a07cc6c37b28d13a611283ef73
Author: Clément Foucault
Date:   Sat Jun 2 09:25:23 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB08a2c5f2249c89a07cc6c37b28d13a611283ef73

Eevee: Add support for hair random property.

Do note that it does not match cycles implementation.

Also we could precompute the hash per strand before rendering but that would
suggest it's not per engine specific.

If we make the random value internal to blender then it won't be a matter
because other renderers will have access to the same value.

===================================================================

M	source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_material.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
index 704b039e0f6..a1890433b0f 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -143,6 +143,20 @@ vec2 mip_ratio_interp(float mip) {
 	float low_mip = floor(mip);
 	return mix(mipRatio[int(low_mip)], mipRatio[int(low_mip + 1.0)], mip - low_mip);
 }
+
+/* ------- RNG ------- */
+
+float wang_hash_noise(uint s)
+{
+	s = (s ^ 61u) ^ (s >> 16u);
+	s *= 9u;
+	s = s ^ (s >> 4u);
+	s *= 0x27d4eb2du;
+	s = s ^ (s >> 15u);
+
+	return fract(float(s) / 4294967296.0);
+}
+
 /* ------- Fast Math ------- */
 
 /* [Drobot2014a] Low Level Optimizations for GCN */
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 ad975957be9..daeef1dbf01 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -26,6 +26,7 @@ in vec3 hairTangent; /* world space */
 in float hairThickTime;
 in float hairThickness;
 in float hairTime;
+flat in int hairStrandID;
 
 uniform int hairThicknessRes = 1;
 #endif
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
index 611a561c750..58bcea7d605 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -35,11 +35,13 @@ out vec3 hairTangent;
 out float hairThickTime;
 out float hairThickness;
 out float hairTime;
+flat out int hairStrandID;
 #endif
 
 void main()
 {
 #ifdef HAIR_SHADER
+	hairStrandID = hair_get_strand_id();
 	vec3 pos, binor;
 	hair_get_pos_tan_binor_time(
 	        (ProjectionMatrix[3][3] == 0.0),
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 9c04aef894c..6f253a48f86 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2486,7 +2486,7 @@ void node_hair_info(out float is_strand, out float intercept, out float thicknes
 	intercept = hairTime;
 	thickness = hairThickness;
 	tangent = normalize(hairTangent);
-	random = 0.0;
+	random = wang_hash_noise(uint(hairStrandID)); /* TODO: could be precomputed per strand instead. */
 #else
 	is_strand = 0.0;
 	intercept = 0.0;



More information about the Bf-blender-cvs mailing list