Commit: c4583135e7b38b89d9ed55b5cf1b42c9f1f9b659
Author: Nick Wu
Date:   Tue May 29 22:04:19 2018 +0800
Branches: soc-2018-npr
https://developer.blender.org/rBc4583135e7b38b89d9ed55b5cf1b42c9f1f9b659

line drawing in one batch, greatly improve performance. modified UI.

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

M       release/scripts/startup/bl_ui/properties_scene.py
M       source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
M       source/blender/makesdna/DNA_lanpr_types.h
M       source/blender/makesdna/DNA_scene_types.h
M       source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_scene.py 
b/release/scripts/startup/bl_ui/properties_scene.py
index f0ae8917900..4f1c19f61c2 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -456,43 +456,52 @@ class SCENE_PT_lanpr(SceneButtonsPanel, PropertyPanel, 
Panel):
         scene = context.scene
         lanpr = scene.lanpr
         layout.label(text="Global:")
-        layout.prop(lanpr, "enable_post_processing")
-        layout.label(text="Enter 0.0001 to 0.002:")
+        layout.prop(lanpr, "enable_vector_trace")
+
+        if lanpr.enable_vector_trace == "DISABLED":
+            layout.prop(lanpr, "display_thinning_result")
+
         layout.prop(lanpr, "depth_clamp")
-        layout.label(text="Enter 500 to 1000:")
         layout.prop(lanpr, "depth_strength")
-        layout.label(text="Enter 2:")
         layout.prop(lanpr, "normal_clamp")
-        layout.label(text="Enter 10:")
         layout.prop(lanpr, "normal_strength")
 
-        split = layout.split()
-        col = split.column()
-        col.label(text="Background Color:")
-        col.prop(lanpr, "background_color")
-        col = split.column()
-        col.label(text="Line Color:")
-        col.prop(lanpr, "line_color")
-        
-        layout.label(text="Thickness:")
-        layout.prop(lanpr, "line_thickness")
-        layout.label(text="Taper Settings:")
-        layout.prop(lanpr, "use_same_taper")
+        if lanpr.enable_vector_trace == "ENABLED":
 
-        if lanpr.use_same_taper == "DISABLED":
             split = layout.split()
             col = split.column()
-            col.label(text="Left:")
-            col.prop(lanpr,"taper_left_distance")
-            col.prop(lanpr,"taper_left_strength")
+            col.prop(lanpr, "background_color")
             col = split.column()
-            col.label(text="Right:")
-            col.prop(lanpr,"taper_right_distance")
-            col.prop(lanpr,"taper_right_strength")
-        else:
-            layout.prop(lanpr,"taper_left_distance")
-            layout.prop(lanpr,"taper_left_strength")
+            col.prop(lanpr, "line_color")
             
+            layout.label(text="Thickness:")
+            layout.prop(lanpr, "line_thickness")
+
+            layout.label(text="Effect Settings:")
+
+            layout.prop(lanpr, "use_same_taper")
+
+            if lanpr.use_same_taper == "DISABLED":
+                split = layout.split()
+                col = split.column()
+                col.label(text="Left:")
+                col.prop(lanpr,"taper_left_distance")
+                col.prop(lanpr,"taper_left_strength")
+                col = split.column()
+                col.label(text="Right:")
+                col.prop(lanpr,"taper_right_distance")
+                col.prop(lanpr,"taper_right_strength")
+            else:
+                layout.prop(lanpr,"taper_left_distance")
+                layout.prop(lanpr,"taper_left_strength") 
+
+            layout.prop(lanpr, "enable_tip_extend")
+            if lanpr.enable_tip_extend == "ENABLED":
+                layout.prop(lanpr,"extend_length")
+        
+        else: #disabled vectorization
+            layout.label(text="Adjust values to avoid large pure white 
regions!")
+                
 
 
 
diff --git a/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c 
b/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
index 562636ed669..8500fe02768 100644
--- a/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
+++ b/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
@@ -69,7 +69,7 @@ static void lanpr_engine_init(void *ved){
        DRW_texture_ensure_fullscreen_2D(&txl->depth, GPU_DEPTH_COMPONENT32F, 
DRW_TEX_FILTER | DRW_TEX_MIPMAP);
        DRW_texture_ensure_fullscreen_2D(&txl->color, GPU_RGBA16F, 
DRW_TEX_FILTER | DRW_TEX_MIPMAP);
        DRW_texture_ensure_fullscreen_2D(&txl->normal, GPU_RGBA16F, 
DRW_TEX_FILTER | DRW_TEX_MIPMAP);
-    DRW_texture_ensure_fullscreen_2D(&txl->edge_intermediate, GPU_RGBA8, 
DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+    DRW_texture_ensure_fullscreen_2D(&txl->edge_intermediate, GPU_RGBA16F, 
DRW_TEX_FILTER | DRW_TEX_MIPMAP);
        
        GPU_framebuffer_ensure_config(&fbl->passes, {
                GPU_ATTACHMENT_TEXTURE(txl->depth),
@@ -435,45 +435,66 @@ void lanpr_texture_to_ndc(int x,int y, int w,int h, 
float* x_ndc, float* y_ndc){
        *y_ndc = tnsLinearItp(-1,1, (float)y/(float)h);
 }
 
-Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd, LANPR_LineStrip* ls){
-       int Count = ls->point_count;
+void lanpr_count_drawing_elements(LANPR_PrivateData* pd, int* vert_count, int* 
index_adjacent_count){
+    int v_count=0;
+       int e_count=0;
+       LANPR_LineStrip* ls;
+       for (ls = (LANPR_LineStrip *)(pd->line_strips.first); ls; ls = 
(LANPR_LineStrip *)(ls->Item.next)) {
+               v_count += (ls->point_count);
+               e_count += ((ls->point_count - 1) * 4);
+       }
+       *vert_count = v_count;
+       *index_adjacent_count = e_count;
+}
+
+Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd){
+       LANPR_LineStrip* ls;
+       LANPR_LineStripPoint* lsp, *plsp;
        int i;
-       LANPR_LineStripPoint* lsp,*plsp;
        u32bit *Index_adjacent;
        float* Verts;
        float* Lengths;
        float TotalLength=0;
+       int v_count,e_count;
+
+       lanpr_count_drawing_elements(pd,&v_count,&e_count);
 
-       Index_adjacent = MEM_callocN(sizeof(unsigned int) * (Count - 1) * 4, 
"Index_adjacent buffer pre alloc");
-       Verts = MEM_callocN(sizeof(float) * Count * 2, "Verts buffer pre 
alloc");
-       Lengths = MEM_callocN(sizeof(float)* Count, "Length buffer pre alloc");
+       //Index_adjacent = MEM_callocN(sizeof(unsigned int) * e_count, 
"Index_adjacent buffer pre alloc");
+       Verts = MEM_callocN(sizeof(float) * v_count * 2, "Verts buffer pre 
alloc");
+       Lengths = MEM_callocN(sizeof(float)* v_count, "Length buffer pre 
alloc");
 
        Gwn_IndexBufBuilder elb;
-       GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINES_ADJ, (Count - 1) * 4, Count, 
true);
-
-       for (i = 0; i < Count-1; i++) {
-               Index_adjacent[i * 4 + 0] = i - 1;
-               Index_adjacent[i * 4 + 1] = i;
-               Index_adjacent[i * 4 + 2] = i + 1;
-               Index_adjacent[i * 4 + 3] = i + 2;
-               GWN_indexbuf_add_line_adj_verts(&elb, (i-1<0?0:i-1), i, i+1, 
(i+2>=Count-1?Count-1:i+2));
-       }
-       Index_adjacent[0] = 0;
-       Index_adjacent[(Count - 1) * 4 - 1] = Count-1;
-
-       i = 0;
-       float xf,yf;
-       for (lsp = (LANPR_LineStripPoint *)(ls->points.first); lsp; lsp = 
(LANPR_LineStripPoint *)(lsp->Item.next)) {
-               lanpr_texture_to_ndc(lsp->P[0],lsp->P[1],pd->width, pd->height, 
&xf,&yf);
-               Verts[i * 2 + 0] = xf;
-               Verts[i * 2 + 1] = yf;
-               if (plsp = (LANPR_LineStripPoint *)(lsp->Item.prev)) {
-                       TotalLength += tMatDist2v(plsp->P, lsp->P);
-                       Lengths[i] = TotalLength;
+       GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINES_ADJ, e_count, v_count, true);
+
+       int vert_offset=0;
+
+       for (ls = (LANPR_LineStrip *)(pd->line_strips.first); ls; ls = 
(LANPR_LineStrip *)(ls->Item.next)) {
+               for (i = 0; i < ls->point_count-1; i++) {
+                       int v1 = i+vert_offset-1;
+                       int v2 = i+vert_offset;
+                       int v3 = i+vert_offset+1;
+                       int v4 = i+vert_offset+2;
+                       if(v1<0) v1=0;
+                       if(v4>= v_count) v4 = v_count -1;
+                       GWN_indexbuf_add_line_adj_verts(&elb, v1,v2,v3,v4);
+               }
+
+               i = 0;
+               float xf,yf;
+               for (lsp = (LANPR_LineStripPoint *)(ls->points.first); lsp; lsp 
= (LANPR_LineStripPoint *)(lsp->Item.next)) {
+                       lanpr_texture_to_ndc(lsp->P[0],lsp->P[1],pd->width, 
pd->height, &xf,&yf);
+                       Verts[vert_offset*2 + i * 2 + 0] = xf;
+                       Verts[vert_offset*2 + i * 2 + 1] = yf;
+                       if (plsp = (LANPR_LineStripPoint *)(lsp->Item.prev)) {
+                               TotalLength += tMatDist2v(plsp->P, lsp->P);
+                               Lengths[vert_offset + i] = TotalLength;
+                       }
+                       i++;
                }
-               i++;
+               ls->total_length = TotalLength;
+
+               vert_offset+=(ls->point_count);
        }
-       ls->total_length = TotalLength;
 
        static Gwn_VertFormat format = { 0 };
        static struct { uint pos, uvs; } attr_id;
@@ -483,14 +504,13 @@ Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd, 
LANPR_LineStrip* ls){
        }
 
        Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
-       GWN_vertbuf_data_alloc(vbo, Count);
+       GWN_vertbuf_data_alloc(vbo, v_count);
 
-       for (int i = 0; i < Count; ++i) {
+       for (int i = 0; i < v_count; ++i) {
                GWN_vertbuf_attr_set(vbo, attr_id.pos, i, &Verts[i*2]);
                GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, &Lengths[i]);
        }
 
-       MEM_freeN(Index_adjacent);
        MEM_freeN(Verts);
        MEM_freeN(Lengths);
        
@@ -525,36 +545,49 @@ static void lanpr_draw_scene(void *vedata)
 
        stl->g_data->znear = camera? ((Camera*)camera->data)->clipsta:0.1;
     stl->g_data->zfar = camera? ((Camera*)camera->data)->clipend:100;
-       stl->g_data->normal_clamp =    draw_ctx->scene->lanpr.normal_clamp;
-       stl->g_data->normal_strength = draw_ctx->scene->lanpr.normal_strength;
-       stl->g_data->depth_clamp =     draw_ctx->scene->lanpr.depth_clamp;
-       stl->g_data->depth_strength =  draw_ctx->scene->lanpr.depth_strength;
-
-       GPU_framebuffer_bind(fbl->edge_intermediate);
+       stl->g_data->normal_clamp =    lanpr->normal_clamp;
+       stl->g_data->normal_strength = lanpr->normal_strength;
+       stl->g_data->depth_clamp =     lanpr->depth_clamp;
+       stl->g_data->depth_strength =  lanpr->depth_strength;
        //GPU_framebuffer_clear(fbl->edge_intermediate, clear_bits, clear_col, 
clear_depth, clear_stencil);
-       
-       DRW_draw_pass(psl->edge_intermediate);
-       
-    stl->g_data->stage = 0;
-    GPU_framebuffer_bind(fbl->edge_thinning);
-       clear_bits = GPU_COLOR_BIT;
-       GPU_framebuffer_clear(fbl->edge_thinning, clear_bits, clear_col, 
clear_depth, clear_stencil);
-    DRW_draw_pass(psl->edge_thinning);
-
-       stl->g_data->stage = 1;
        GPU_framebuffer_bind(fbl->edge_intermediate);
-       //GPU_framebuffer_clear(fbl->edge_intermediate, clear_bits, clear_col, 
clear_depth, clear_stencil);
-    DRW_draw_pass(psl->edge_thinning_2);
+       DRW_draw_pass(psl->edge_intermediate);
 
-       stl->g_data->stage = 0;
-    GPU_framebuffer_bind(fbl->edge_thinning);
-       GPU_framebuffer_clear(fbl->edge_thinning, clear_bits, clear_col, 
clear_depth, clear_stencil);
-    DRW_draw_pass(psl->edge_thinning);
+       if((!lanpr->enable_vector_trace) && (!lanpr->display_thinning_result)){
+               GPU_framebuffer_bind(dfbl->default_fb);
+               DRW_transform_to_display(txl->edge_intermediate);
+               return;
+       }
 
-       stl->g_data->stage = 1;
-       GPU_framebuffer_bind(fbl->edge_intermediate);


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to