[Bf-blender-cvs] [28f11d30ddc] hair_guides_grooming: Support hair fiber drawing in the workbench engine.
Lukas Tönne
noreply at git.blender.org
Sun Jun 10 09:09:31 CEST 2018
Commit: 28f11d30ddc750e472dd22fdd949833ae3fb0ede
Author: Lukas Tönne
Date: Sun Jun 10 08:09:11 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB28f11d30ddc750e472dd22fdd949833ae3fb0ede
Support hair fiber drawing in the workbench engine.
===================================================================
M source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
M source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
M source/blender/draw/engines/workbench/workbench_deferred.c
M source/blender/draw/engines/workbench/workbench_forward.c
M source/blender/draw/engines/workbench/workbench_materials.c
M source/blender/draw/engines/workbench/workbench_private.h
===================================================================
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 702978adfd7..fbcdfd66572 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -8,16 +8,14 @@ uniform mat3 WorldNormalMatrix;
uniform mat3 NormalMatrix;
#endif
-#ifdef HAIR_SHADER
-
+#ifndef HAIR_SHADER
+in vec3 pos;
+in vec3 nor;
+#else
#ifdef HAIR_SHADER_FIBERS
in int fiber_index;
in float curve_param;
#endif
-
-#else
-in vec3 pos;
-in vec3 nor;
#endif
out vec3 worldPosition;
@@ -50,7 +48,7 @@ void main()
#ifdef HAIR_SHADER
bool is_persp = (ProjectionMatrix[3][3] == 0.0);
-#ifdef HAIR_SHADER_FIBERS
+# ifdef HAIR_SHADER_FIBERS
vec3 pos, tang, binor;
hair_fiber_get_vertex(
fiber_index, curve_param,
@@ -65,7 +63,7 @@ void main()
hairTangent = (ModelMatrix * vec4(tang, 0.0)).xyz;
worldNormal = (ModelMatrix * vec4(nor, 0.0)).xyz;
viewNormal = normalize(mat3(ViewMatrix) * worldNormal);
-#else
+# else
hairStrandID = hair_get_strand_id();
vec3 pos, binor;
hair_get_pos_tan_binor_time(
@@ -78,15 +76,15 @@ void main()
hairTangent = normalize(hairTangent);
worldNormal = cross(binor, hairTangent);
viewNormal = normalize(mat3(ViewMatrix) * worldNormal);
-#endif
+# endif
-#else
+#else /* HAIR_SHADER */
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
worldNormal = normalize(WorldNormalMatrix * nor);
viewNormal = normalize(NormalMatrix * nor);
-#endif
+#endif /* HAIR_SHADER */
/* Used for planar reflections */
gl_ClipDistance[0] = dot(vec4(worldPosition, 1.0), ClipPlanes[0]);
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 82443e7336b..fb051bddb1c 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
@@ -2,6 +2,7 @@ uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 ViewProjectionMatrix;
uniform mat4 ViewMatrixInverse;
+uniform mat4 ModelViewMatrixInverse;
uniform mat3 NormalMatrix;
#ifndef HAIR_SHADER
@@ -13,6 +14,10 @@ in vec2 uv;
uniform samplerBuffer u; /* active texture layer */
# endif
flat out float hair_rand;
+# ifdef HAIR_SHADER_FIBERS
+in int fiber_index;
+in float curve_param;
+# endif
#endif /* HAIR_SHADER */
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
@@ -34,27 +39,42 @@ float integer_noise(int n)
void main()
{
#ifdef HAIR_SHADER
-# ifdef OB_TEXTURE
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+
+# ifdef HAIR_SHADER_FIBERS
+ vec2 uv = vec2(0.0); /* TODO */
+ float time, thick_time, thickness;
+ vec3 pos, tang, binor;
+ hair_fiber_get_vertex(
+ fiber_index, curve_param,
+ is_persp, ModelViewMatrixInverse[3].xyz, ModelViewMatrixInverse[2].xyz,
+ pos, tang, binor,
+ time, thickness, thick_time);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ hair_rand = integer_noise(fiber_index);
+# else
+# ifdef OB_TEXTURE
vec2 uv = hair_get_customdata_vec2(u);
-# endif
+# endif
float time, thick_time, thickness;
- vec3 pos, tan, binor;
+ vec3 pos, tang, binor;
hair_get_pos_tan_binor_time(
- (ProjectionMatrix[3][3] == 0.0),
- ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
- pos, tan, binor, time, thickness, thick_time);
- /* To "simulate" anisotropic shading, randomize hair normal per strand. */
+ is_persp, ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
+ pos, tang, binor, time, thickness, thick_time);
+ gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
hair_rand = integer_noise(hair_get_strand_id());
- tan = normalize(tan);
- vec3 nor = normalize(cross(binor, tan));
- nor = normalize(mix(nor, -tan, hair_rand * 0.10));
+# endif
+ /* To "simulate" anisotropic shading, randomize hair normal per strand. */
+ tang = normalize(tang);
+ vec3 nor = normalize(cross(binor, tang));
+ nor = normalize(mix(nor, -tang, hair_rand * 0.10));
float cos_theta = (hair_rand*2.0 - 1.0) * 0.20;
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));
nor = nor * sin_theta + binor * cos_theta;
- gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
-#else
+#else /* HAIR_SHADER */
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-#endif
+#endif /* HAIR_SHADER */
+
#ifdef OB_TEXTURE
uv_interp = uv;
#endif
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index c4fa82d39b7..3aea1b31a5a 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -32,9 +32,11 @@
#include "BLI_utildefines.h"
#include "BLI_rand.h"
+#include "BKE_groom.h"
#include "BKE_node.h"
#include "BKE_particle.h"
+#include "DNA_groom_types.h"
#include "DNA_image_types.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
@@ -85,6 +87,7 @@ static struct {
/* Shaders */
extern char datatoc_common_hair_lib_glsl[];
+extern char datatoc_hair_lib_glsl[];
extern char datatoc_workbench_prepass_vert_glsl[];
extern char datatoc_workbench_prepass_frag_glsl[];
@@ -149,6 +152,7 @@ static char *workbench_build_prepass_vert(void)
DynStr *ds = BLI_dynstr_new();
BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl);
+ BLI_dynstr_append(ds, datatoc_hair_lib_glsl);
BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl);
str = BLI_dynstr_get_cstring(ds);
@@ -171,17 +175,17 @@ static char *workbench_build_cavity_frag(void)
return str;
}
-static void ensure_deferred_shaders(WORKBENCH_PrivateData *wpd, int index, int drawtype, bool is_hair)
+static void ensure_deferred_shaders(WORKBENCH_PrivateData *wpd, int index, int drawtype, DRWShaderHairType hair_type)
{
if (e_data.prepass_sh_cache[index] == NULL) {
- char *defines = workbench_material_build_defines(wpd, drawtype, is_hair);
+ char *defines = workbench_material_build_defines(wpd, drawtype, hair_type);
char *composite_frag = workbench_build_composite_frag(wpd);
char *prepass_vert = workbench_build_prepass_vert();
char *prepass_frag = workbench_build_prepass_frag();
e_data.prepass_sh_cache[index] = DRW_shader_create(
prepass_vert, NULL,
prepass_frag, defines);
- if (drawtype == OB_SOLID && !is_hair) {
+ if (drawtype == OB_SOLID && hair_type == DRW_SHADER_HAIR_NONE) {
e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines);
}
MEM_freeN(prepass_vert);
@@ -193,20 +197,26 @@ static void ensure_deferred_shaders(WORKBENCH_PrivateData *wpd, int index, int d
static void select_deferred_shaders(WORKBENCH_PrivateData *wpd)
{
- int index_solid = workbench_material_get_shader_index(wpd, OB_SOLID, false);
- int index_solid_hair = workbench_material_get_shader_index(wpd, OB_SOLID, true);
- int index_texture = workbench_material_get_shader_index(wpd, OB_TEXTURE, false);
- int index_texture_hair = workbench_material_get_shader_index(wpd, OB_TEXTURE, true);
-
- ensure_deferred_shaders(wpd, index_solid, OB_SOLID, false);
- ensure_deferred_shaders(wpd, index_solid_hair, OB_SOLID, true);
- ensure_deferred_shaders(wpd, index_texture, OB_TEXTURE, false);
- ensure_deferred_shaders(wpd, index_texture_hair, OB_TEXTURE, true);
+ int index_solid = workbench_material_get_shader_index(wpd, OB_SOLID, DRW_SHADER_HAIR_NONE);
+ int index_solid_hair = workbench_material_get_shader_index(wpd, OB_SOLID, DRW_SHADER_HAIR_PARTICLES);
+ int index_solid_hair_fibers = workbench_material_get_shader_index(wpd, OB_SOLID, DRW_SHADER_HAIR_FIBERS);
+ int index_texture = workbench_material_get_shader_index(wpd, OB_TEXTURE, DRW_SHADER_HAIR_NONE);
+ int index_texture_hair = workbench_material_get_shader_index(wpd, OB_TEXTURE, DRW_SHADER_HAIR_PARTICLES);
+ int index_texture_hair_fibers = workbench_material_get_shader_index(wpd, OB_TEXTURE, DRW_SHADER_HAIR_FIBERS);
+
+ ensure_deferred_shaders(wpd, index_solid, OB_SOLID, DRW_SHADER_HAIR_NONE);
+ ensure_deferred_shaders(wpd, index_solid_hair, OB_SOLID, DRW_SHADER_HAIR_PARTICLES);
+ ensure_deferred_shaders(wpd, index_solid_hair_fibers, OB_SOLID, DRW_SHADER_HAIR_FIBERS);
+ ensure_deferred_shaders(wpd, index_texture, OB_TEXTURE, DRW_SHADER_HAIR_NONE);
+ ensure_deferred_shaders(wpd, index_texture_hair, OB_TEXTURE, DRW_SHADER_HAIR_PARTICLES);
+ ensure_deferred_shaders(wpd, index_texture_hair_fibers, OB_TEXTURE, DRW_SHADER_HAIR_FIBERS);
wpd->prepass_solid_sh = e_data.prepass_sh_cache[index_solid];
wpd->prepass_solid_hair_sh = e_data.prepass_sh_cache[index_solid_hair];
+ wpd->prepass_solid_hair_fibers_sh = e_data.prepass_sh_cache[index_solid_hair_fibers];
wpd->prepass_texture_sh = e_data.prepass_sh_cache[index_texture];
wpd->prepass_texture_hair_sh = e_data.prepass_sh_cache[index_texture_hair];
+ wpd->prepass_texture_hair_fibers_sh = e_data.prepass_sh_cache[index_texture_hair_fibers];
wpd->composite_sh = e_data.composite_sh_cache[index_solid];
}
@@ -656,6 +666,47 @@ static void workbench_cache_populate_particles(WORKBENCH_Data *vedata, Object *o
}
}
+static void workbench_cache_populate_groom(WORKBENCH_Data *vedata, Object *ob)
+{
+ const Groom *groom = ob->data;
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_PassList *psl = vedata->psl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ Image *image = NULL;
+ Material *mat = give_current_material(ob, groom->material_index);
+ int mat_drawtype = OB_SOLID;
+
+ if (wpd->drawtype == OB_TEXTURE) {
+ ED_object_get_active_image(ob, groom->material_index, &image, NULL, NULL, NULL);
+ /* use OB_SOLID when no texture could be determined */
+ if (image) {
+ mat_drawtype = OB_TEXTURE;
+ }
+ }
+
+ WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, mat_drawtype);
+ struct GPUShader *shader = (mat_drawt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list