[Bf-blender-cvs] [6eaf51ef3e5] master: DRW: Use USHORT for vertex color and upload them in linear color to the GPU

Clément Foucault noreply at git.blender.org
Fri Jan 17 16:29:21 CET 2020


Commit: 6eaf51ef3e5b7d37170473449bcda60bad025e67
Author: Clément Foucault
Date:   Fri Jan 17 16:05:19 2020 +0100
Branches: master
https://developer.blender.org/rB6eaf51ef3e5b7d37170473449bcda60bad025e67

DRW: Use USHORT for vertex color and upload them in linear color to the GPU

This way we remove the need for the srgb boolean uniform and a lot of code complexity. However, mesh update is going to be a bit slower.

I did not benchmark the performance impact.

This also fix a typo in draw_cache_impl_particles.c and fix hair not using vertex color in workbench.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D6610

===================================================================

M	source/blender/draw/engines/eevee/eevee_materials.c
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/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_extract.h
M	source/blender/draw/intern/draw_cache_extract_mesh.c
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/gpu/intern/gpu_codegen.c

===================================================================

diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index d0fe7c6637e..97d492d5dd5 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -1529,18 +1529,10 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
 
     if ((ob->dt >= OB_SOLID) || DRW_state_is_image_render()) {
       /* Get per-material split surface */
-      char *auto_layer_names;
-      int *auto_layer_is_srgb;
-      int auto_layer_count;
       struct GPUBatch **mat_geom = NULL;
 
       if (!use_sculpt_pbvh) {
-        mat_geom = DRW_cache_object_surface_material_get(ob,
-                                                         gpumat_array,
-                                                         materials_len,
-                                                         &auto_layer_names,
-                                                         &auto_layer_is_srgb,
-                                                         &auto_layer_count);
+        mat_geom = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len);
       }
 
       if (use_sculpt_pbvh) {
@@ -1577,28 +1569,6 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
           ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, mat_geom[i], oedata);
           ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, mat_geom[i], oedata);
 
-          char *name = auto_layer_names;
-          for (int j = 0; j < auto_layer_count; j++) {
-            /* TODO don't add these uniform when not needed (default pass shaders). */
-            /* FIXME: This is broken, as it overrides any autolayers srgb bool of the previous mesh
-             * that shares the same material.  */
-            if (shgrp_array[i]) {
-              DRW_shgroup_uniform_bool_copy(shgrp_array[i], name, auto_layer_is_srgb[j]);
-            }
-            if (shgrp_depth_array[i]) {
-              DRW_shgroup_uniform_bool_copy(shgrp_depth_array[i], name, auto_layer_is_srgb[j]);
-            }
-            if (shgrp_depth_clip_array[i]) {
-              DRW_shgroup_uniform_bool_copy(
-                  shgrp_depth_clip_array[i], name, auto_layer_is_srgb[j]);
-            }
-            /* Go to next layer name. */
-            while (*name != '\0') {
-              name++;
-            }
-            name += 1;
-          }
-
           /* Shadow Pass */
           struct GPUMaterial *gpumat;
           const bool use_gpumat = (ma_array[i]->use_nodes && ma_array[i]->nodetree);
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 04dd9ab85bb..0a3252f0b9b 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
@@ -4,13 +4,18 @@ in vec3 pos;
 in vec3 nor;
 in vec2 au; /* active texture layer */
 #  ifdef V3D_SHADING_VERTEX_COLOR
-in vec3 ac; /* active color */
+in vec4 ac; /* active color */
 #  endif
 #  define uv au
 #else /* HAIR_SHADER */
+
 #  ifdef V3D_SHADING_TEXTURE_COLOR
 uniform samplerBuffer au; /* active texture layer */
 #  endif
+#  ifdef V3D_SHADING_VERTEX_COLOR
+uniform samplerBuffer ac; /* active color layer */
+#  endif
+
 flat out float hair_rand;
 #endif /* HAIR_SHADER */
 
@@ -37,16 +42,6 @@ float integer_noise(int n)
   return (float(nn) / 1073741824.0);
 }
 
-#ifdef V3D_SHADING_VERTEX_COLOR
-vec3 srgb_to_linear_attr(vec3 c)
-{
-  c = max(c, vec3(0.0));
-  vec3 c1 = c * (1.0 / 12.92);
-  vec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));
-  return mix(c1, c2, step(vec3(0.04045), c));
-}
-#endif
-
 vec3 workbench_hair_hair_normal(vec3 tan, vec3 binor, float rand)
 {
   /* To "simulate" anisotropic shading, randomize hair normal per strand. */
@@ -90,7 +85,9 @@ void main()
 
 #ifdef V3D_SHADING_VERTEX_COLOR
 #  ifndef HAIR_SHADER
-  vertexColor = srgb_to_linear_attr(ac);
+  vertexColor = ac.rgb;
+#  else
+  vertexColor = hair_get_customdata_vec4(ac).rgb;
 #  endif
 #endif
 
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index 1af9357e015..86ed1f0b4c3 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -1138,8 +1138,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
         struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
         memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len);
 
-        geoms = DRW_cache_object_surface_material_get(
-            ob, gpumat_array, materials_len, NULL, NULL, NULL);
+        geoms = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len);
         for (int i = 0; i < materials_len; i++) {
           if (geoms != NULL && geoms[i] != NULL) {
             Material *mat = give_current_material(ob, i + 1);
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index ae001f8d10c..3b588868a94 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -756,7 +756,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
         memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len);
 
         struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get(
-            ob, gpumat_array, materials_len, NULL, NULL, NULL);
+            ob, gpumat_array, materials_len);
         if (mat_geom) {
           for (int i = 0; i < materials_len; i++) {
             if (mat_geom[i] == NULL) {
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 4d10e781e79..a0e4af8fc8d 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -826,25 +826,11 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob)
 
 GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob,
                                                  struct GPUMaterial **gpumat_array,
-                                                 uint gpumat_array_len,
-                                                 char **auto_layer_names,
-                                                 int **auto_layer_is_srgb,
-                                                 int *auto_layer_count)
+                                                 uint gpumat_array_len)
 {
-  if (auto_layer_names != NULL) {
-    *auto_layer_names = NULL;
-    *auto_layer_is_srgb = NULL;
-    *auto_layer_count = 0;
-  }
-
   switch (ob->type) {
     case OB_MESH:
-      return DRW_cache_mesh_surface_shaded_get(ob,
-                                               gpumat_array,
-                                               gpumat_array_len,
-                                               auto_layer_names,
-                                               auto_layer_is_srgb,
-                                               auto_layer_count);
+      return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
     case OB_CURVE:
       return DRW_cache_curve_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
     case OB_SURF:
@@ -2733,18 +2719,10 @@ GPUBatch *DRW_cache_mesh_surface_edges_get(Object *ob)
 /* Return list of batches with length equal to max(1, totcol). */
 GPUBatch **DRW_cache_mesh_surface_shaded_get(Object *ob,
                                              struct GPUMaterial **gpumat_array,
-                                             uint gpumat_array_len,
-                                             char **auto_layer_names,
-                                             int **auto_layer_is_srgb,
-                                             int *auto_layer_count)
+                                             uint gpumat_array_len)
 {
   BLI_assert(ob->type == OB_MESH);
-  return DRW_mesh_batch_cache_get_surface_shaded(ob->data,
-                                                 gpumat_array,
-                                                 gpumat_array_len,
-                                                 auto_layer_names,
-                                                 auto_layer_is_srgb,
-                                                 auto_layer_count);
+  return DRW_mesh_batch_cache_get_surface_shaded(ob->data, gpumat_array, gpumat_array_len);
 }
 
 /* Return list of batches with length equal to max(1, totcol). */
@@ -2895,8 +2873,7 @@ GPUBatch **DRW_cache_curve_surface_shaded_get(Object *ob,
   struct Curve *cu = ob->data;
   struct Mesh *mesh_eval = ob->runtime.mesh_eval;
   if (mesh_eval != NULL) {
-    return DRW_mesh_batch_cache_get_surface_shaded(
-        mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+    return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
   }
   else {
     return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
@@ -3036,8 +3013,7 @@ GPUBatch **DRW_cache_text_surface_shaded_get(Object *ob,
     return NULL;
   }
   if (mesh_eval != NULL) {
-    return DRW_mesh_batch_cache_get_surface_shaded(
-        mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+    return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
   }
   else {
     return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
@@ -3131,8 +3107,7 @@ GPUBatch **DRW_cache_surf_surface_shaded_get(Object *ob,
   struct Curve *cu = ob->data;
   struct Mesh *mesh_eval = ob->runtime.mesh_eval;
   if (mesh_eval != NULL) {
-    return DRW_mesh_batch_cache_get_surface_shaded(
-        mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+    return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
   }
   else {
     return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
diff --git a/source/blender/draw/intern/draw_cache.h b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list