[Bf-blender-cvs] [fed6c1a970f] master: Fix T62876: Camera Background Images

Jeroen Bakker noreply at git.blender.org
Fri Jun 21 09:56:52 CEST 2019


Commit: fed6c1a970f1df14da7c5fd4dfaf84371efcbe5d
Author: Jeroen Bakker
Date:   Tue Apr 2 16:05:22 2019 +0200
Branches: master
https://developer.blender.org/rBfed6c1a970f1df14da7c5fd4dfaf84371efcbe5d

Fix T62876: Camera Background Images

Migrate old legacy code to the draw mamager/object mode. The old legacy
version did not work with wireframe. By migrating the code
to modern draw manager code we have mode control on the drawing process.

Still background images do not work with OIT, the cause seems to be that the transparent pixels are treated as background pixels.
Also There are some artifacts when working with Holdouts and DoF, this
is because the draw engines do not pass the correct alpha values.

Reviewers: fclem, brecht

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

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

M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/draw/modes/paint_texture_mode.c
A	source/blender/draw/modes/shaders/common_colormanagement_lib.glsl
A	source/blender/draw/modes/shaders/object_camera_image_frag.glsl
A	source/blender/draw/modes/shaders/object_camera_image_vert.glsl
M	source/blender/draw/modes/shaders/object_empty_image_frag.glsl
M	source/blender/draw/modes/shaders/paint_texture_frag.glsl
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/makesdna/DNA_movieclip_types.h
M	source/blender/makesrna/intern/rna_camera.c

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

diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index c377223d14b..6bc83f8dd09 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -67,6 +67,8 @@
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
+#include "GPU_texture.h"
+
 #ifdef WITH_OPENEXR
 #  include "intern/openexr/openexr_multi.h"
 #endif
@@ -1353,6 +1355,17 @@ static void free_buffers(MovieClip *clip)
     IMB_free_anim(clip->anim);
     clip->anim = NULL;
   }
+
+  MovieClip_RuntimeGPUTexture *tex;
+  for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) {
+    for (int i = 0; i < TEXTARGET_COUNT; i++) {
+      if (tex->gputexture[i] != NULL) {
+        GPU_texture_free(tex->gputexture[i]);
+        tex->gputexture[i] = NULL;
+      }
+    }
+  }
+  BLI_freelistN(&clip->runtime.gputextures);
 }
 
 void BKE_movieclip_clear_cache(MovieClip *clip)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 541ebe8f01d..393f8f87a90 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2038,6 +2038,7 @@ void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
   for (; clip; clip = clip->id.next) {
     clip->cache = newmclipadr(fd, clip->cache);
     clip->tracking.camera.intrinsics = newmclipadr(fd, clip->tracking.camera.intrinsics);
+    BLI_freelistN(&clip->runtime.gputextures);
   }
 
   for (; sce; sce = sce->id.next) {
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 5a8a4d46ac9..8631a9f556b 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -249,6 +249,7 @@ data_to_c_simple(engines/workbench/shaders/workbench_volume_vert.glsl SRC)
 data_to_c_simple(engines/workbench/shaders/workbench_volume_frag.glsl SRC)
 data_to_c_simple(engines/workbench/shaders/workbench_world_light_lib.glsl SRC)
 
+data_to_c_simple(modes/shaders/common_colormanagement_lib.glsl SRC)
 data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
 data_to_c_simple(modes/shaders/common_hair_lib.glsl SRC)
 data_to_c_simple(modes/shaders/common_hair_refine_vert.glsl SRC)
@@ -295,6 +296,8 @@ data_to_c_simple(modes/shaders/overlay_face_orientation_vert.glsl SRC)
 data_to_c_simple(modes/shaders/overlay_face_wireframe_vert.glsl SRC)
 data_to_c_simple(modes/shaders/overlay_face_wireframe_geom.glsl SRC)
 data_to_c_simple(modes/shaders/overlay_face_wireframe_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_camera_image_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_camera_image_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_empty_axes_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_empty_image_frag.glsl SRC)
 data_to_c_simple(modes/shaders/object_empty_image_vert.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 6d1227bb0a8..ae3bf8cead6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -61,6 +61,7 @@ extern char datatoc_gpencil_edit_point_geom_glsl[];
 extern char datatoc_gpencil_edit_point_frag_glsl[];
 extern char datatoc_gpencil_blend_frag_glsl[];
 
+extern char datatoc_common_colormanagement_lib_glsl[];
 extern char datatoc_common_view_lib_glsl[];
 
 /* *********** STATIC *********** */
@@ -169,29 +170,37 @@ static void GPENCIL_create_shaders(void)
 {
   /* normal fill shader */
   if (!e_data.gpencil_fill_sh) {
-    e_data.gpencil_fill_sh = DRW_shader_create_with_lib(datatoc_gpencil_fill_vert_glsl,
-                                                        NULL,
-                                                        datatoc_gpencil_fill_frag_glsl,
-                                                        datatoc_common_view_lib_glsl,
-                                                        NULL);
+    e_data.gpencil_fill_sh = GPU_shader_create_from_arrays({
+        .vert =
+            (const char *[]){datatoc_common_view_lib_glsl, datatoc_gpencil_fill_vert_glsl, NULL},
+        .frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
+                                 datatoc_gpencil_fill_frag_glsl,
+                                 NULL},
+    });
   }
 
   /* normal stroke shader using geometry to display lines (line mode) */
   if (!e_data.gpencil_stroke_sh) {
-    e_data.gpencil_stroke_sh = DRW_shader_create_with_lib(datatoc_gpencil_stroke_vert_glsl,
-                                                          datatoc_gpencil_stroke_geom_glsl,
-                                                          datatoc_gpencil_stroke_frag_glsl,
-                                                          datatoc_common_view_lib_glsl,
-                                                          NULL);
+    e_data.gpencil_stroke_sh = GPU_shader_create_from_arrays({
+        .vert =
+            (const char *[]){datatoc_common_view_lib_glsl, datatoc_gpencil_stroke_vert_glsl, NULL},
+        .geom = (const char *[]){datatoc_gpencil_stroke_geom_glsl, NULL},
+        .frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
+                                 datatoc_gpencil_stroke_frag_glsl,
+                                 NULL},
+    });
   }
 
   /* dot/rectangle mode for normal strokes using geometry */
   if (!e_data.gpencil_point_sh) {
-    e_data.gpencil_point_sh = DRW_shader_create_with_lib(datatoc_gpencil_point_vert_glsl,
-                                                         datatoc_gpencil_point_geom_glsl,
-                                                         datatoc_gpencil_point_frag_glsl,
-                                                         datatoc_common_view_lib_glsl,
-                                                         NULL);
+    e_data.gpencil_point_sh = GPU_shader_create_from_arrays({
+        .vert =
+            (const char *[]){datatoc_common_view_lib_glsl, datatoc_gpencil_point_vert_glsl, NULL},
+        .geom = (const char *[]){datatoc_gpencil_point_geom_glsl, NULL},
+        .frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
+                                 datatoc_gpencil_point_frag_glsl,
+                                 NULL},
+    });
   }
   /* used for edit points or strokes with one point only */
   if (!e_data.gpencil_edit_point_sh) {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
index 1fdfd05332e..87bf116ff89 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
@@ -90,31 +90,6 @@ void set_color(in vec4 color,
   ocolor.a *= layer_opacity;
 }
 
-float linearrgb_to_srgb(float c)
-{
-  if (c < 0.0031308) {
-    return (c < 0.0) ? 0.0 : c * 12.92;
-  }
-  else {
-    return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
-  }
-}
-
-vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
-{
-  /* By convention image textures return scene linear colors, but
-   * grease pencil still works in srgb. */
-  vec4 color = texture(tex, co);
-  /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
-  if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
-    color.rgb = color.rgb / color.a;
-  }
-  color.r = linearrgb_to_srgb(color.r);
-  color.g = linearrgb_to_srgb(color.g);
-  color.b = linearrgb_to_srgb(color.b);
-  return color;
-}
-
 void main()
 {
   vec2 t_center = vec2(0.5, 0.5);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
index 7fed42aca0d..34777018a73 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
@@ -48,31 +48,6 @@ vec2 check_box_point(vec2 pt, vec2 radius)
   return rtn;
 }
 
-float linearrgb_to_srgb(float c)
-{
-  if (c < 0.0031308) {
-    return (c < 0.0) ? 0.0 : c * 12.92;
-  }
-  else {
-    return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
-  }
-}
-
-vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
-{
-  /* By convention image textures return scene linear colors, but
-   * grease pencil still works in srgb. */
-  vec4 color = texture(tex, co);
-  /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
-  if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
-    color.rgb = color.rgb / color.a;
-  }
-  color.r = linearrgb_to_srgb(color.r);
-  color.g = linearrgb_to_srgb(color.g);
-  color.b = linearrgb_to_srgb(color.b);
-  return color;
-}
-
 void main()
 {
   vec2 centered = mTexCoord - vec2(0.5);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index bc703d2a078..73baacb35d4 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -28,31 +28,6 @@ out vec4 fragColor;
 
 bool no_texture = (shading_type[0] == OB_SOLID) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR);
 
-float linearrgb_to_srgb(float c)
-{
-  if (c < 0.0031308) {
-    return (c < 0.0) ? 0.0 : c * 12.92;
-  }
-  else {
-    return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
-  }
-}
-
-vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
-{
-  /* By convention image textures return scene linear colors, but
-   * grease pencil still works in srgb. */
-  vec4 color = texture(tex, co);
-  /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
-  if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
-    color.rgb = color.rgb / color.a;
-  }
-  color.r = linearrgb_to_srgb(color.r);
-  color.g = linearrgb_to_srgb(color.g);
-  color.b = linearrgb_to_srgb(color.b);
-  return color;
-}
-
 void main()
 {
 
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 87366289bf7..7606fa91

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list