Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-05-17 19:17:14 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-05-17 19:17:23 +0300
commit0c4ce8e55e93c76c81f70db64dc8dee52b30a9f3 (patch)
tree73ede483d98e284882193b154b7c0d31db4aee36 /source
parentec3940ab0a05e99a01b74c1c7e834e3f448a5d48 (diff)
Eevee / Workbench: Fix hair normals
Hair normals were not behaving correctly. This corrects their looks and fix the node shader geometry that was showing the flat normal.
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl4
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl11
-rw-r--r--source/blender/draw/modes/shaders/common_hair_lib.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_geometry.c2
5 files changed, 10 insertions, 13 deletions
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 0a2785bafca..2b9a325e313 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -47,9 +47,7 @@ void main()
hairTime,
hairThickness,
hairThickTime);
-
- hairTangent = normalize(hairTangent);
- worldNormal = cross(binor, hairTangent);
+ worldNormal = cross(hairTangent, binor);
worldPosition = pos;
#else
worldPosition = point_object_to_world(pos);
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
index 5d4153999c0..7872c1380ed 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
@@ -46,12 +46,11 @@ vec3 srgb_to_linear_attr(vec3 c)
vec3 workbench_hair_hair_normal(vec3 tan, vec3 binor, float rand)
{
/* To "simulate" anisotropic shading, randomize hair normal per strand. */
- tan = normalize(tan);
- vec3 nor = normalize(cross(binor, tan));
- // nor = normalize(mix(nor, -tan, rand * 0.1));
- // float cos_theta = (rand * 2.0 - 1.0) * 0.2;
- // float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
- // nor = nor * sin_theta + binor * cos_theta;
+ vec3 nor = cross(tan, binor);
+ nor = normalize(mix(nor, -tan, rand * 0.1));
+ float cos_theta = (rand * 2.0 - 1.0) * 0.2;
+ float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta));
+ nor = nor * sin_theta + binor * cos_theta;
return nor;
}
diff --git a/source/blender/draw/modes/shaders/common_hair_lib.glsl b/source/blender/draw/modes/shaders/common_hair_lib.glsl
index 1c0a31c59fd..f9c3df34658 100644
--- a/source/blender/draw/modes/shaders/common_hair_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_hair_lib.glsl
@@ -160,9 +160,9 @@ void hair_get_pos_tan_binor_time(bool is_persp,
}
wpos = (hairDupliMatrix * vec4(wpos, 1.0)).xyz;
- wtan = mat3(hairDupliMatrix) * wtan;
+ wtan = -normalize(mat3(hairDupliMatrix) * wtan);
- vec3 camera_vec = (is_persp) ? wpos - camera_pos : -camera_z;
+ vec3 camera_vec = (is_persp) ? camera_pos - wpos : camera_z;
wbinor = normalize(cross(camera_vec, wtan));
thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 94770aa2ebf..b94a7d6cc0a 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2038,7 +2038,7 @@ void node_geometry(vec3 I,
position = worldPosition;
# ifndef VOLUMETRICS
- normal = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
+ normal = normalize(N);
vec3 B = dFdx(worldPosition);
vec3 T = dFdy(worldPosition);
true_normal = normalize(cross(B, T));
diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.c b/source/blender/nodes/shader/nodes/node_shader_geometry.c
index 6f97efe9f73..df9a8ac8318 100644
--- a/source/blender/nodes/shader/nodes/node_shader_geometry.c
+++ b/source/blender/nodes/shader/nodes/node_shader_geometry.c
@@ -51,7 +51,7 @@ static int node_shader_gpu_geometry(GPUMaterial *mat,
in,
out,
GPU_builtin(GPU_VIEW_POSITION),
- GPU_builtin(GPU_VIEW_NORMAL),
+ GPU_builtin(GPU_WORLD_NORMAL),
GPU_attribute(CD_ORCO, ""),
GPU_builtin(GPU_OBJECT_MATRIX),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX),