[Bf-blender-cvs] [1942c2c] strand_gpu: Implementation of Curl effect for vertex displacement.
Lukas Tönne
noreply at git.blender.org
Wed Jul 13 14:01:42 CEST 2016
Commit: 1942c2c2cf0e2a1b0708b87329be1a13897248bc
Author: Lukas Tönne
Date: Wed Jul 13 14:01:01 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB1942c2c2cf0e2a1b0708b87329be1a13897248bc
Implementation of Curl effect for vertex displacement.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/space_view3d/drawstrands.c
M source/blender/gpu/GPU_strands.h
M source/blender/gpu/intern/gpu_strands.c
M source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
M source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
M source/blender/gpu/shaders/gpu_shader_strand_util.glsl
M source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_strands.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 0319e6c..80df40b 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -893,6 +893,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.prop(md, "show_fibers", text="Fibers")
col.prop(md, "subdivisions")
col.prop(md, "use_geometry_shader")
+ col.prop(md, "debug_value")
col.separator()
@@ -902,15 +903,18 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
layout.separator()
box = layout.box()
- box.prop(md, "use_clumping_effect")
- if md.use_clumping_effect:
- box.prop(md, "clumping_factor")
- box.prop(md, "clumping_shape")
+ box.prop(md, "use_clump_effect")
+ if md.use_clump_effect:
+ box.prop(md, "clump_thickness")
+ box.prop(md, "clump_shape")
box = layout.box()
box.prop(md, "use_curl_effect")
if md.use_curl_effect:
- pass
+ box.prop(md, "curl_thickness")
+ box.prop(md, "curl_shape")
+ box.prop(md, "curl_radius")
+ box.prop(md, "curl_length")
def SUBSURF(self, layout, ob, md):
layout.row().prop(md, "subdivision_type", expand=True)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 2e902f9..3dc0f1e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5284,6 +5284,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
smd->edit = NULL;
smd->gpu_buffer = NULL;
+
+ smd->debug_value = 0; /* reset */
}
}
}
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index d76b4a6..531a2e1 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -82,8 +82,8 @@ static GPUStrands_ShaderModel get_shader_model(int smd_shader_model)
static int get_effects(int smd_effects)
{
GPUStrands_Effects effects = 0;
- if (smd_effects & MOD_STRANDS_EFFECT_CLUMPING)
- effects |= GPU_STRAND_EFFECT_CLUMPING;
+ if (smd_effects & MOD_STRANDS_EFFECT_CLUMP)
+ effects |= GPU_STRAND_EFFECT_CLUMP;
if (smd_effects & MOD_STRANDS_EFFECT_CURL)
effects |= GPU_STRAND_EFFECT_CURL;
@@ -95,7 +95,9 @@ static void bind_strands_shader(GPUStrandsShader *shader, RegionView3D *rv3d,
{
GPU_strand_shader_bind_uniforms(shader, ob->obmat, rv3d->viewmat);
GPU_strand_shader_bind(shader, rv3d->viewmat, rv3d->viewinv,
- smd->clumping_factor, smd->clumping_shape);
+ smd->clump_thickness, smd->clump_shape,
+ smd->curl_thickness, smd->curl_shape, smd->curl_radius, smd->curl_length,
+ smd->debug_value);
}
void draw_strands(Scene *scene, View3D *UNUSED(v3d), RegionView3D *rv3d,
diff --git a/source/blender/gpu/GPU_strands.h b/source/blender/gpu/GPU_strands.h
index f72ab7f..016bd4c 100644
--- a/source/blender/gpu/GPU_strands.h
+++ b/source/blender/gpu/GPU_strands.h
@@ -49,7 +49,7 @@ typedef enum GPUStrands_ShaderModel {
} GPUStrands_ShaderModel;
typedef enum GPUStrands_Effects {
- GPU_STRAND_EFFECT_CLUMPING = (1 << 0),
+ GPU_STRAND_EFFECT_CLUMP = (1 << 0),
GPU_STRAND_EFFECT_CURL = (1 << 1),
} GPUStrands_Effects;
@@ -63,7 +63,9 @@ void GPU_strand_shader_free(struct GPUStrandsShader *gpu_shader);
void GPU_strand_shader_bind(
GPUStrandsShader *gpu_shader,
float viewmat[4][4], float viewinv[4][4],
- float clumping_factor, float clumping_shape);
+ float clump_thickness, float clump_shape,
+ float curl_thickness, float curl_shape, float curl_radius, float curl_length,
+ int debug_value);
void GPU_strand_shader_bind_uniforms(
GPUStrandsShader *gpu_shader,
float obmat[4][4], float viewmat[4][4]);
diff --git a/source/blender/gpu/intern/gpu_strands.c b/source/blender/gpu/intern/gpu_strands.c
index 37737f7..1d49442 100644
--- a/source/blender/gpu/intern/gpu_strands.c
+++ b/source/blender/gpu/intern/gpu_strands.c
@@ -152,7 +152,7 @@ GPUStrandsShader *GPU_strand_shader_get(struct Strands *strands,
"#define SHADING_MARSCHNER\n");
break;
}
- if (effects & GPU_STRAND_EFFECT_CLUMPING)
+ if (effects & GPU_STRAND_EFFECT_CLUMP)
defines_cur += BLI_snprintf(defines_cur, MAX_DEFINES - (defines_cur - defines),
"#define USE_EFFECT_CLUMPING\n");
if (effects & GPU_STRAND_EFFECT_CURL)
@@ -286,15 +286,22 @@ void GPU_strand_shader_free(struct GPUStrandsShader *gpu_shader)
void GPU_strand_shader_bind(GPUStrandsShader *strand_shader,
float viewmat[4][4], float viewinv[4][4],
- float clumping_factor, float clumping_shape)
+ float clump_thickness, float clump_shape,
+ float curl_thickness, float curl_shape, float curl_radius, float curl_length,
+ int debug_value)
{
GPUShader *shader = strand_shader->shader;
if (!shader)
return;
GPU_shader_bind(shader);
- glUniform1f(GPU_shader_get_uniform(shader, "clumping_factor"), clumping_factor);
- glUniform1f(GPU_shader_get_uniform(shader, "clumping_shape"), clumping_shape);
+ glUniform1f(GPU_shader_get_uniform(shader, "clump_thickness"), clump_thickness);
+ glUniform1f(GPU_shader_get_uniform(shader, "clump_shape"), clump_shape);
+ glUniform1f(GPU_shader_get_uniform(shader, "curl_thickness"), curl_thickness);
+ glUniform1f(GPU_shader_get_uniform(shader, "curl_shape"), curl_shape);
+ glUniform1f(GPU_shader_get_uniform(shader, "curl_radius"), curl_radius);
+ glUniform1f(GPU_shader_get_uniform(shader, "curl_length"), curl_length);
+ glUniform1i(GPU_shader_get_uniform(shader, "debug_value"), debug_value);
strand_shader->bound = true;
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl b/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
index 2726207..7078b7e 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
@@ -1,33 +1,78 @@
-uniform float clumping_factor;
-uniform float clumping_shape;
+uniform int debug_value;
+
+uniform float clump_thickness;
+uniform float clump_shape;
+uniform float curl_thickness;
uniform float curl_shape;
+uniform float curl_radius;
+uniform float curl_length;
+
+/* Note: The deformer functions below calculate a new location vector
+ * as well as a new direction (aka "normal"), using the partial derivatives of the transformation.
+ *
+ * Each transformation function can depend on the location L as well as the curve parameter t:
+ *
+ * Lnew = f(L, t)
+ * => dLnew/dt = del f/del L * dL/dt + del f/del t
+ *
+ * The first term is the Jacobian of the function f, dL/dt is the original direction vector.
+ * Some more information can be found here:
+ * http://http.developer.nvidia.com/GPUGems/gpugems_ch42.html
+ */
/* Hairs tend to stick together and run in parallel.
* The effect increases with distance from the root,
* as the stresses pulling fibers apart decrease.
*/
-void clumping(inout vec3 location, in float t, vec3 offset, mat3 rotation, in vec2 root_distance)
+void clumping(inout vec3 loc, inout vec3 nor, in float t, in float tscale, in vec3 target_loc, in mat3 target_frame)
{
- float taper = pow(t, 1.0 / clumping_shape);
- float factor = taper * clumping_factor;
- location -= offset * factor;
+ float taper = pow(t, 1.0 / clump_shape);
+ float factor = (1.0 - clump_thickness) * taper;
+
+ vec3 nloc = mix(loc, target_loc, factor);
+ vec3 nnor;
+ if (t > 0.0) {
+ nnor = normalize(nor * (1.0 - factor)
+ + (target_loc - loc) * factor / (t * clump_shape));
+ }
+ else
+ nnor = nor;
+
+ loc = nloc;
+ nor = nnor;
}
-/* Hair often don't have a circular cross section, but are somewhat flattened.
+/* Hairs often don't have a circular cross section, but are somewhat flattened.
* This creates the local bending which results in the typical curly hair geometry.
*/
-void curl(inout vec3 location, in float t, vec3 offset, mat3 rotation, in vec2 root_distance)
+void curl(inout vec3 loc, inout vec3 nor, in float t, in float tscale, in vec3 target_loc, in mat3 target_frame)
{
- float factor = pow(t, 1.0 / curl_shape);
- //location -= rotation * vec3(root_distance.xy, 0.0) * taper * ;
+ float taper = pow(t, 1.0 / curl_shape);
+ float factor = (1.0 - curl_thickness) * taper;
+
+ float angle = 2.0*M_PI * t * tscale / curl_length;
+ vec3 curlvec = target_frame * vec3(cos(angle), sin(angle), 0.0) * curl_radius;
+
+ vec3 nloc = mix(loc, target_loc + curlvec, factor);
+ vec3 nnor;
+ if (t > 0.0) {
+ nnor = normalize(nor * (1.0 - factor)
+ + vec3(-curlvec.y, curlvec.x, 0.0) * 2.0*M_PI * tscale / curl_length
+ + (target_loc + curlvec - loc) * factor / (t * clump_shape));
+ }
+ else
+ nnor = nor;
+
+ loc = nloc;
+ nor = nnor;
}
-void displace_vertex(inout vec3 location, in float t, vec3 offset, mat3 rotation, in vec2 root_distance)
+void displace_vertex(inout vec3 loc, inout vec3 nor, in float t, in float tscale, in vec3 target_loc, in mat3 target_frame)
{
#ifdef USE_EFFECT_CLUMPING
- clumping(location, t, offset, rotation, root_distance);
+ clumping(loc, nor, t, tscale, target_loc, target_frame);
#endif
#ifdef USE_EFFECT_CURL
- curl(location, t, offset, rotation, root_distance);
+ curl(loc, nor, t, tscale, target_loc, target_frame);
#endif
}
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
index 35019fd..4d87fdf 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
@@ -74,36 +74,30 @@ void main()
dt[k] = float(num_cverts[k] - 1) / float(num_verts - 1);
}
- vec3 loc = root;
- displace_vertex(loc, 0.0, offset[0], vRotation[0], v_root_dis
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list