[Bf-blender-cvs] [26ceb98] strand_gpu: Use DynString to "include" shared code in the strand vert/geom/frag shaders.
Lukas Tönne
noreply at git.blender.org
Wed Jul 13 14:01:36 CEST 2016
Commit: 26ceb98ced0d6f88d8756d511614f989aea1ab71
Author: Lukas Tönne
Date: Tue Jul 12 08:09:08 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB26ceb98ced0d6f88d8756d511614f989aea1ab71
Use DynString to "include" shared code in the strand vert/geom/frag shaders.
This way we can avoid duplicate code for effects without going out of sync.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/intern/gpu_strands.c
A source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
M source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
A source/blender/gpu/shaders/gpu_shader_strand_util.glsl
M source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b396202..72a3b76 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -128,6 +128,8 @@ data_to_c_simple(shaders/gpu_shader_fx_lib.glsl SRC)
data_to_c_simple(shaders/gpu_shader_strand_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_strand_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_strand_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_strand_effects.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_strand_util.glsl SRC)
if(WITH_GAMEENGINE)
add_definitions(-DWITH_GAMEENGINE)
diff --git a/source/blender/gpu/intern/gpu_strands.c b/source/blender/gpu/intern/gpu_strands.c
index 8c7d341..7a2b648 100644
--- a/source/blender/gpu/intern/gpu_strands.c
+++ b/source/blender/gpu/intern/gpu_strands.c
@@ -63,53 +63,53 @@ struct GPUStrandsShader {
extern char datatoc_gpu_shader_strand_frag_glsl[];
extern char datatoc_gpu_shader_strand_geom_glsl[];
extern char datatoc_gpu_shader_strand_vert_glsl[];
+extern char datatoc_gpu_shader_strand_effects_glsl[];
+extern char datatoc_gpu_shader_strand_util_glsl[];
static char *codegen_vertex(void)
{
-#if 0
char *code;
DynStr *ds = BLI_dynstr_new();
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_util_glsl);
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_effects_glsl);
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_vert_glsl);
+
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
return code;
-#else
- return BLI_strdup(datatoc_gpu_shader_strand_vert_glsl);
-#endif
}
static char *codegen_geometry(void)
{
-#if 0
char *code;
DynStr *ds = BLI_dynstr_new();
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_util_glsl);
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_effects_glsl);
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_geom_glsl);
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
return code;
-#else
- return BLI_strdup(datatoc_gpu_shader_strand_geom_glsl);
-#endif
}
static char *codegen_fragment(void)
{
-#if 0
char *code;
DynStr *ds = BLI_dynstr_new();
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_util_glsl);
+ BLI_dynstr_append(ds, datatoc_gpu_shader_strand_frag_glsl);
+
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
return code;
-#else
- return BLI_strdup(datatoc_gpu_shader_strand_frag_glsl);
-#endif
}
GPUStrandsShader *GPU_strand_shader_get(struct Strands *strands,
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl b/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
new file mode 100644
index 0000000..2726207
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_strand_effects.glsl
@@ -0,0 +1,33 @@
+uniform float clumping_factor;
+uniform float clumping_shape;
+uniform float curl_shape;
+
+/* 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)
+{
+ float taper = pow(t, 1.0 / clumping_shape);
+ float factor = taper * clumping_factor;
+ location -= offset * factor;
+}
+
+/* Hair 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)
+{
+ float factor = pow(t, 1.0 / curl_shape);
+ //location -= rotation * vec3(root_distance.xy, 0.0) * taper * ;
+}
+
+void displace_vertex(inout vec3 location, in float t, vec3 offset, mat3 rotation, in vec2 root_distance)
+{
+#ifdef USE_EFFECT_CLUMPING
+ clumping(location, t, offset, rotation, root_distance);
+#endif
+#ifdef USE_EFFECT_CURL
+ curl(location, t, offset, rotation, root_distance);
+#endif
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
index 5793ead..88e0f8b 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_geom.glsl
@@ -16,10 +16,6 @@ out vec3 fColor;
uniform usamplerBuffer control_curves;
uniform samplerBuffer control_points;
-uniform float clumping_factor;
-uniform float clumping_shape;
-uniform float curl_shape;
-
bool is_valid_index(uint index)
{
return index < uint(0xFFFFFFFF);
@@ -34,36 +30,6 @@ void emit_vertex(in vec3 location, in vec3 tangent)
EmitVertex();
}
-/* 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)
-{
- float taper = pow(t, 1.0 / clumping_shape);
- float factor = taper * clumping_factor;
- location -= offset * factor;
-}
-
-/* Hair 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)
-{
- float factor = pow(t, 1.0 / curl_shape);
- //location -= rotation * vec3(root_distance.xy, 0.0) * taper * ;
-}
-
-void displace_vertex(inout vec3 location, in float t, vec3 offset, mat3 rotation, in vec2 root_distance)
-{
-#ifdef USE_EFFECT_CLUMPING
- clumping(location, t, offset, rotation, root_distance);
-#endif
-#ifdef USE_EFFECT_CURL
- curl(location, t, offset, rotation, root_distance);
-#endif
-}
-
void main()
{
vec3 root = gl_in[0].gl_Position.xyz;
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_util.glsl b/source/blender/gpu/shaders/gpu_shader_strand_util.glsl
new file mode 100644
index 0000000..433e24d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_strand_util.glsl
@@ -0,0 +1,6 @@
+mat3 mat3_emu(mat4 m4) {
+ return mat3(
+ m4[0][0], m4[0][1], m4[0][2],
+ m4[1][0], m4[1][1], m4[1][2],
+ m4[2][0], m4[2][1], m4[2][2]);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl b/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
index e1b5742..d549d7f 100644
--- a/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_strand_vert.glsl
@@ -28,17 +28,8 @@ uniform samplerBuffer fiber_tangent;
uniform usamplerBuffer fiber_control_index;
uniform samplerBuffer fiber_control_weight;
uniform samplerBuffer fiber_root_distance;
-
-uniform float clumping_factor;
-uniform float clumping_shape;
-uniform float curl_shape;
#endif
-void interpolate_vertex()
-{
-
-}
-
void main()
{
#ifdef USE_GEOMSHADER
@@ -56,6 +47,7 @@ void main()
vec3 loc = vec3(0.0, 0.0, 0.0);
vec3 tangent = vec3(0.0, 0.0, 0.0);
+ vec3 offset0;
for (int k = 0; k < 4; ++k) {
if (!control_valid[k])
continue;
@@ -66,6 +58,8 @@ void main()
vec3 croot = texelFetch(control_points, int(verts_begin)).xyz;
vec3 offset = root - croot;
+ if (k == 0)
+ offset0 = offset;
float segment = curve_param * float(num_verts);
int idx0 = min(int(segment), num_verts - 2);
@@ -79,8 +73,10 @@ void main()
tangent += control_weight[k] * (cloc1 - cloc0);
}
+ displace_vertex(loc, curve_param, offset0, mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0), vec2(0.0, 0.0));
+
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(loc, 1.0);
- fPosition = (gl_ModelViewMatrix * gl_Vertex).xyz;
+ fPosition = mat3_emu(gl_ModelViewMatrix) * loc;
fTangent = gl_NormalMatrix * tangent;
fColor = vec3(curve_param, 1.0 - curve_param, 0.0);
#endif
More information about the Bf-blender-cvs
mailing list