[Bf-blender-cvs] [4e71eb53d16] hair_guides hair_guides_grooming: Fix hair fiber vertex shaders and bring them closer to the particle hair shader.
Lukas Tönne
noreply at git.blender.org
Wed Jun 6 21:41:23 CEST 2018
Commit: 4e71eb53d16a3ced27635cddcb877fbd54f639de
Author: Lukas Tönne
Date: Wed Jun 6 20:39:42 2018 +0100
Branches: hair_guides hair_guides_grooming
https://developer.blender.org/rB4e71eb53d16a3ced27635cddcb877fbd54f639de
Fix hair fiber vertex shaders and bring them closer to the particle hair shader.
===================================================================
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/draw/engines/eevee/shaders/hair_lib.glsl
M source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
M source/blender/draw/intern/draw_hair_fibers.c
===================================================================
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index 6f5ca45ffbc..04edf50cc41 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -611,6 +611,7 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, E
"#define CLIP_PLANES\n");
char *hair_fiber_vert_str = BLI_string_joinN(
+ datatoc_common_hair_lib_glsl,
datatoc_hair_lib_glsl,
datatoc_prepass_vert_glsl);
diff --git a/source/blender/draw/engines/eevee/shaders/hair_lib.glsl b/source/blender/draw/engines/eevee/shaders/hair_lib.glsl
index 8f06f1177c6..10d1c1b61c9 100644
--- a/source/blender/draw/engines/eevee/shaders/hair_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/hair_lib.glsl
@@ -147,17 +147,12 @@ void deform_fiber(DeformParams params,
/*===================================*/
/* Hair Interpolation */
-#define FIBER_RIBBON
-
uniform sampler2D fiber_data;
uniform int fiber_start;
uniform int strand_map_start;
uniform int strand_vertex_start;
-uniform float ribbon_width;
-uniform vec2 viewport_size;
-
#define INDEX_INVALID -1
vec2 read_texdata(int offset)
@@ -220,7 +215,7 @@ void get_fiber_data(int fiber_index, out ivec4 parent_index, out vec4 parent_wei
pos = vec3(e.rg, f.r);
}
-void interpolate_parent_curve_full(int index, float curve_param, out vec3 co, out vec3 nor, out vec3 tang, out vec3 rootco)
+void interpolate_parent_curve(int index, float curve_param, out vec3 co, out vec3 nor, out vec3 tang, out vec3 rootco)
{
int start, count;
get_strand_data(index, start, count);
@@ -249,13 +244,6 @@ void interpolate_parent_curve_full(int index, float curve_param, out vec3 co, ou
tang = mix(tang0, tang1, lerpfac);
}
-void interpolate_parent_curve(int index, float curve_param, out vec3 co, out vec3 tang)
-{
- vec3 nor;
- vec3 rootco;
- interpolate_parent_curve_full(index, curve_param, co, nor, tang, rootco);
-}
-
void interpolate_vertex(int fiber_index, float curve_param,
out vec3 co, out vec3 tang,
out mat4 target_matrix)
@@ -271,27 +259,27 @@ void interpolate_vertex(int fiber_index, float curve_param,
if (parent_index.x != INDEX_INVALID) {
vec3 pco, pnor, ptang, prootco;
- interpolate_parent_curve_full(parent_index.x, curve_param, pco, pnor, ptang, prootco);
+ interpolate_parent_curve(parent_index.x, curve_param, pco, pnor, ptang, prootco);
co += parent_weight.x * pco;
tang += parent_weight.x * normalize(ptang);
target_matrix = mat4_from_vectors(pnor, ptang, pco + prootco);
}
if (parent_index.y != INDEX_INVALID) {
- vec3 pco, ptang;
- interpolate_parent_curve(parent_index.y, curve_param, pco, ptang);
+ vec3 pco, pnor, ptang, prootco;
+ interpolate_parent_curve(parent_index.x, curve_param, pco, pnor, ptang, prootco);
co += parent_weight.y * pco;
tang += parent_weight.y * normalize(ptang);
}
if (parent_index.z != INDEX_INVALID) {
- vec3 pco, ptang;
- interpolate_parent_curve(parent_index.z, curve_param, pco, ptang);
+ vec3 pco, pnor, ptang, prootco;
+ interpolate_parent_curve(parent_index.x, curve_param, pco, pnor, ptang, prootco);
co += parent_weight.z * pco;
tang += parent_weight.z * normalize(ptang);
}
if (parent_index.w != INDEX_INVALID) {
- vec3 pco, ptang;
- interpolate_parent_curve(parent_index.w, curve_param, pco, ptang);
+ vec3 pco, pnor, ptang, prootco;
+ interpolate_parent_curve(parent_index.x, curve_param, pco, pnor, ptang, prootco);
co += parent_weight.w * pco;
tang += parent_weight.w * normalize(ptang);
}
@@ -300,33 +288,37 @@ void interpolate_vertex(int fiber_index, float curve_param,
tang = normalize(tang);
}
-void hair_fiber_get_vertex(int fiber_index, float curve_param, mat4 ModelViewMatrix, out vec3 pos, out vec3 nor, out vec2 view_offset)
+void hair_fiber_get_vertex(
+ int fiber_index, float curve_param,
+ bool is_persp, vec3 camera_pos, vec3 camera_z,
+ out vec3 pos, out vec3 tang, out vec3 binor,
+ out float time, out float thickness, out float thick_time)
{
- vec3 target_loc;
mat4 target_matrix;
- interpolate_vertex(fiber_index, curve_param, pos, nor, target_matrix);
-
+ interpolate_vertex(fiber_index, curve_param, pos, tang, target_matrix);
+
+ vec3 camera_vec = (is_persp) ? pos - camera_pos : -camera_z;
+ binor = normalize(cross(camera_vec, tang));
+
DeformParams deform_params;
deform_params.taper = 2.0;
deform_params.clump.thickness = 0.15;
deform_params.curl.radius = 0.1;
deform_params.curl.angle = 0.2;
// TODO define proper curve scale, independent of subdivision!
- //deform_fiber(deform_params, curve_param, 1.0, target_matrix, pos, nor);
-
-#ifdef FIBER_RIBBON
- float ribbon_side = (float(gl_VertexID % 2) - 0.5) * ribbon_width;
- {
- vec4 view_nor = ModelViewMatrix * vec4(nor, 0.0);
- view_offset = vec2(view_nor.y, -view_nor.x);
- float L = length(view_offset);
- if (L > 0.0) {
- view_offset *= ribbon_side / (L * viewport_size);
- }
+ //deform_fiber(deform_params, curve_param, 1.0, target_matrix, pos, tang);
+
+ time = curve_param;
+ thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time);
+
+ // TODO use the uniform for hairThicknessRes
+ int hairThicknessRes = 2;
+ if (hairThicknessRes > 1) {
+ thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
+ thick_time = thickness * (thick_time * 2.0 - 1.0);
+
+ pos += binor * thick_time;
}
-#else
- view_offset = vec2(0.0);
-#endif
}
#endif /*HAIR_SHADER_FIBERS*/
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 ae825683ef8..702978adfd7 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -2,10 +2,10 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform mat4 ModelViewMatrix;
+uniform mat4 ModelViewMatrixInverse;
uniform mat3 WorldNormalMatrix;
#ifndef ATTRIB
uniform mat3 NormalMatrix;
-uniform mat4 ModelMatrixInverse;
#endif
#ifdef HAIR_SHADER
@@ -48,25 +48,28 @@ flat out int hairStrandID;
void main()
{
#ifdef HAIR_SHADER
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
#ifdef HAIR_SHADER_FIBERS
- vec3 pos;
- vec3 nor;
- vec2 view_offset;
- hair_fiber_get_vertex(fiber_index, curve_param, ModelViewMatrix, pos, nor, view_offset);
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
- gl_Position.xy += view_offset * gl_Position.w;
+ vec3 pos, tang, binor;
+ hair_fiber_get_vertex(
+ fiber_index, curve_param,
+ is_persp, ModelViewMatrixInverse[3].xyz, ModelViewMatrixInverse[2].xyz,
+ pos, tang, binor,
+ hairTime, hairThickness, hairThickTime);
+ vec3 nor = cross(binor, tang);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
- viewNormal = normalize(NormalMatrix * nor);
- worldNormal = normalize(WorldNormalMatrix * nor);
+ hairTangent = (ModelMatrix * vec4(tang, 0.0)).xyz;
+ worldNormal = (ModelMatrix * vec4(nor, 0.0)).xyz;
+ viewNormal = normalize(mat3(ViewMatrix) * worldNormal);
#else
hairStrandID = hair_get_strand_id();
vec3 pos, binor;
hair_get_pos_tan_binor_time(
- (ProjectionMatrix[3][3] == 0.0),
- ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
+ is_persp, ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
pos, hairTangent, binor, hairTime, hairThickness, hairThickTime);
gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
diff --git a/source/blender/draw/intern/draw_hair_fibers.c b/source/blender/draw/intern/draw_hair_fibers.c
index 8e48083f4f2..263522538d2 100644
--- a/source/blender/draw/intern/draw_hair_fibers.c
+++ b/source/blender/draw/intern/draw_hair_fibers.c
@@ -74,11 +74,6 @@ static DRWShadingGroup *drw_shgroup_create_hair_fibers_ex(
BLI_assert(0);
}
- DRW_shgroup_uniform_vec2(shgrp, "viewport_size", DRW_viewport_size_get(), 1);
- //DRW_shgroup_uniform_float(shgrp, "ribbon_width", &tsettings->hair_draw_size, 1);
- static float test = 2.5f;
- DRW_shgroup_uniform_float(shgrp, "ribbon_width", &test, 1);
-
if (!hsys->draw_texture_cache) {
hsys->draw_texture_cache = DRW_texture_create_2D(fiber_buffer->width, fiber_buffer->height,
GPU_RG32F, 0, fiber_buffer->data);
More information about the Bf-blender-cvs
mailing list