diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2019-04-02 17:05:22 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2019-06-21 10:53:51 +0300 |
commit | fed6c1a970f1df14da7c5fd4dfaf84371efcbe5d (patch) | |
tree | cab4653b8d57d41bca6f1c45ef94b2601f8ea97c /source/blender/draw/engines/gpencil | |
parent | a3a6cda8fb678432e0552d23b0226e8617f26e5f (diff) |
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
Diffstat (limited to 'source/blender/draw/engines/gpencil')
4 files changed, 24 insertions, 90 deletions
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() { |