Fix T63435 Incorrect fresnel and normals for hair strands on EEVEE
authorClément Foucault <foucault.clem@gmail.com>
Thu, 2 May 2019 12:32:12 +0000 (14:32 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Thu, 2 May 2019 12:32:41 +0000 (14:32 +0200)
source/blender/draw/engines/eevee/eevee_materials.c
source/blender/gpu/intern/gpu_codegen.c
source/blender/gpu/shaders/gpu_shader_material.glsl

index fa76703..456f4bd 100644 (file)
@@ -1881,6 +1881,13 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata,
 
               shgrp = DRW_shgroup_material_hair_create(ob, psys, md, psl->material_pass, gpumat);
 
+              if (!use_diffuse && !use_glossy && !use_refract) {
+                /* FIXME: Small hack to avoid issue when utilTex is needed for
+                 * world_normals_get and none of the bsdfs that need it are present.
+                 * This can try to bind utilTex even if not needed. */
+                DRW_shgroup_uniform_texture(shgrp, "utilTex", e_data.util_tex);
+              }
+
               add_standard_uniforms(shgrp,
                                     sldata,
                                     vedata,
index aef6833..a77bba5 100644 (file)
@@ -892,7 +892,13 @@ static char *code_generate_fragment(GPUMaterial *material,
     BLI_dynstr_append(ds, "\t#define invlocaltoviewmat ModelViewMatrixInverse\n");
   }
   if (builtins & GPU_VIEW_NORMAL) {
+    BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
+    BLI_dynstr_append(ds, "\tvec3 n;\n");
+    BLI_dynstr_append(ds, "\tworld_normals_get(n);\n");
+    BLI_dynstr_append(ds, "\tvec3 facingnormal = transform_direction(ViewMatrix, n);\n");
+    BLI_dynstr_append(ds, "#else\n");
     BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? viewNormal: -viewNormal;\n");
+    BLI_dynstr_append(ds, "#endif\n");
   }
   if (builtins & GPU_VIEW_POSITION) {
     BLI_dynstr_append(ds, "\t#define viewposition viewPosition\n");
index c64623e..cf7a83e 100644 (file)
@@ -3407,7 +3407,7 @@ void world_normals_get(out vec3 N)
     /* Shade as a cylinder. */
     cos_theta = hairThickTime / hairThickness;
   }
-  float sin_theta = sqrt(max(0.0, 1.0f - cos_theta * cos_theta));
+  float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
   N = normalize(worldNormal * sin_theta + B * cos_theta);
 #  else
   N = gl_FrontFacing ? worldNormal : -worldNormal;