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
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-07-08 11:45:58 +0300
committerJeroen Bakker <jeroen@blender.org>2022-07-08 11:45:58 +0300
commit314ccaa29918742f594e80eaee22c63bd2c294c4 (patch)
treed406664c9b78cdbdc7ff714931635dc7efa16204
parentfab4b3f463f6a605cc77e5e994031b043a827ed7 (diff)
-rw-r--r--source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl37
-rw-r--r--source/blender/draw/intern/shaders/common_hair_lib.glsl75
2 files changed, 49 insertions, 63 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl
index 104f74b6305..f9ec475d21f 100644
--- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl
@@ -30,32 +30,33 @@ uint outline_colorid_get(void)
void main()
{
bool is_persp = (drw_view.winmat[3][3] == 0.0);
- float time, thick_time, thickness;
- vec3 center_world_pos, world_pos, tan, binor;
-
- hair_get_pos_tan_binor_time_ex(is_persp,
- ModelMatrixInverse,
- drw_view.viewinv[3].xyz,
- drw_view.viewinv[2].xyz,
- center_world_pos,
- world_pos,
- tan,
- binor,
- time,
- thickness,
- thick_time);
+ float time, thickness;
+ vec3 center_wpos, tan, binor;
+ hair_get_center_pos_tan_binor_time(is_persp,
+ ModelMatrixInverse,
+ drw_view.viewinv[3].xyz,
+ drw_view.viewinv[2].xyz,
+ center_wpos,
+ tan,
+ binor,
+ time,
+ thickness);
+ vec3 world_pos;
if (hairThicknessRes > 1) {
- /* Recalculate the thickness, thicktime, worldpos taken into account the outline. */
- float outline_width = point_world_to_ndc(center_world_pos).w * 1.25 *
+ /* Calculate the thickness, thicktime, worldpos taken into account the outline. */
+ float outline_width = point_world_to_ndc(center_wpos).w * 1.25 *
drw_view.viewport_size_inverse.y * drw_view.wininv[1][1];
thickness += outline_width;
- thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
+ float thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
thick_time = thickness * (thick_time * 2.0 - 1.0);
/* Take object scale into account.
* NOTE: This only works fine with uniform scaling. */
float scale = 1.0 / length(mat3(ModelMatrixInverse) * binor);
- world_pos = center_world_pos + binor * thick_time * scale;
+ world_pos = center_wpos + binor * thick_time * scale;
+ }
+ else {
+ world_pos = center_wpos;
}
gl_Position = point_world_to_ndc(world_pos);
diff --git a/source/blender/draw/intern/shaders/common_hair_lib.glsl b/source/blender/draw/intern/shaders/common_hair_lib.glsl
index 3ffd15b32e7..b82df4a51dc 100644
--- a/source/blender/draw/intern/shaders/common_hair_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_hair_lib.glsl
@@ -164,61 +164,43 @@ float hair_shaperadius(float shape, float root, float tip, float time)
in float dummy;
# endif
-void hair_get_pos_tan_binor_time_ex(bool is_persp,
- mat4 invmodel_mat,
- vec3 camera_pos,
- vec3 camera_z,
- out vec3 orig_wpos,
- out vec3 wpos,
- out vec3 wtan,
- out vec3 wbinor,
- out float time,
- out float thickness,
- out float thick_time)
+void hair_get_center_pos_tan_binor_time(bool is_persp,
+ mat4 invmodel_mat,
+ vec3 camera_pos,
+ vec3 camera_z,
+ out vec3 wpos,
+ out vec3 wtan,
+ out vec3 wbinor,
+ out float time,
+ out float thickness)
{
int id = hair_get_base_id();
vec4 data = texelFetch(hairPointBuffer, id);
- orig_wpos = data.point_position;
+ wpos = data.point_position;
time = data.point_time;
# if defined(OS_MAC) && defined(GPU_OPENGL)
/* Generate a dummy read to avoid the driver bug with shaders having no
* vertex reads on macOS (T60171) */
- orig_wpos.y += dummy * 0.0;
+ wpos.y += dummy * 0.0;
# endif
if (time == 0.0) {
/* Hair root */
- wtan = texelFetch(hairPointBuffer, id + 1).point_position - orig_wpos;
+ wtan = texelFetch(hairPointBuffer, id + 1).point_position - wpos;
}
else {
- wtan = orig_wpos - texelFetch(hairPointBuffer, id - 1).point_position;
+ wtan = wpos - texelFetch(hairPointBuffer, id - 1).point_position;
}
mat4 obmat = hairDupliMatrix;
- orig_wpos = (obmat * vec4(orig_wpos, 1.0)).xyz;
+ wpos = (obmat * vec4(wpos, 1.0)).xyz;
wtan = -normalize(mat3(obmat) * wtan);
- vec3 camera_vec = (is_persp) ? camera_pos - orig_wpos : 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);
- float scale;
- if (hairThicknessRes > 1) {
- thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
- thick_time = thickness * (thick_time * 2.0 - 1.0);
-
- /* Take object scale into account.
- * NOTE: This only works fine with uniform scaling. */
- scale = 1.0 / length(mat3(invmodel_mat) * wbinor);
- }
- else {
- /* NOTE: Ensures 'hairThickTime' is initialized -
- * avoids undefined behavior on certain macOS configurations. */
- thick_time = 0.0;
- scale = 1.0;
- }
- wpos = orig_wpos + wbinor * thick_time * scale;
}
void hair_get_pos_tan_binor_time(bool is_persp,
@@ -232,18 +214,21 @@ void hair_get_pos_tan_binor_time(bool is_persp,
out float thickness,
out float thick_time)
{
- vec3 orig_wpos;
- hair_get_pos_tan_binor_time_ex(is_persp,
- invmodel_mat,
- camera_pos,
- camera_z,
- orig_wpos,
- wpos,
- wtan,
- wbinor,
- time,
- thickness,
- thick_time);
+ hair_get_center_pos_tan_binor_time(
+ is_persp, invmodel_mat, camera_pos, camera_z, wpos, wtan, wbinor, time, thickness);
+ if (hairThicknessRes > 1) {
+ thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1);
+ thick_time = thickness * (thick_time * 2.0 - 1.0);
+ /* Take object scale into account.
+ * NOTE: This only works fine with uniform scaling. */
+ float scale = 1.0 / length(mat3(invmodel_mat) * wbinor);
+ wpos += wbinor * thick_time * scale;
+ }
+ else {
+ /* NOTE: Ensures 'hairThickTime' is initialized -
+ * avoids undefined behavior on certain macOS configurations. */
+ thick_time = 0.0;
+ }
}
float hair_get_customdata_float(const samplerBuffer cd_buf)