Commit: ad228f8e46cd34e23065d2100ae61d9c2126fae3
Author: Nick Wu
Date:   Thu May 24 09:49:17 2018 +0800
Branches: soc-2018-npr
https://developer.blender.org/rBad228f8e46cd34e23065d2100ae61d9c2126fae3

Edge thinning shader ok

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

M       source/blender/draw/engines/lanpr/NUL_TNS.h
M       source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
M       source/blender/draw/engines/lanpr/shaders/lanpr_image_peel.fragment
M       source/blender/draw/engines/lanpr/shaders/lanpr_snake_edge.fragment

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

diff --git a/source/blender/draw/engines/lanpr/NUL_TNS.h 
b/source/blender/draw/engines/lanpr/NUL_TNS.h
index 0509520a7bb..f2cea88c7ee 100644
--- a/source/blender/draw/engines/lanpr/NUL_TNS.h
+++ b/source/blender/draw/engines/lanpr/NUL_TNS.h
@@ -16,11 +16,14 @@ typedef struct LANPR_PassList {
        struct DRWPass *color_pass;
        struct DRWPass *normal_pass;
        struct DRWPass *edge_intermediate;
+       struct DRWPass *edge_thinning;
+       struct DRWPass *edge_thinning_2;
 } LANPR_PassList;
 
 typedef struct LANPR_FramebufferList {
        struct GPUFrameBuffer *passes;
        struct GPUFrameBuffer *edge_intermediate;
+       struct GPUFrameBuffer *edge_thinning;
        struct GPUFrameBuffer *on_screen;
        //and something...
 } LANPR_FramebufferList;
@@ -35,6 +38,8 @@ typedef struct LANPR_TextureList {
 typedef struct LANPR_PrivateData {
        DRWShadingGroup *multipass_shgrp;
        DRWShadingGroup *edge_detect_shgrp;
+       DRWShadingGroup *edge_thinning_shgrp;
+       DRWShadingGroup *edge_thinning_shgrp_2;
 } LANPR_PrivateData;
 
 typedef struct LANPR_StorageList {
diff --git a/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c 
b/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
index ce6fdedb4e2..7d0c4a20495 100644
--- a/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
+++ b/source/blender/draw/engines/lanpr/NUL_TNS_EdgeRendering.c
@@ -14,6 +14,7 @@ extern char datatoc_common_fullscreen_vert_glsl[];
 extern char datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl[];
 extern char datatoc_lanpr_snake_multichannel_fragment[];
 extern char datatoc_lanpr_snake_edge_fragment[];
+extern char datatoc_lanpr_image_peel_fragment[];
 
 //==============================================================[ ATLAS / DPIX 
]
 
@@ -28,6 +29,7 @@ extern char datatoc_lanpr_snake_edge_fragment[];
 typedef struct LANPROneTimeInit{
     GPUShader* multichannel_shader;
        GPUShader* edge_detect_shader;
+       GPUShader* edge_thinning_shader;
        void* ved;
 } LANPROneTimeInit;
 
@@ -73,6 +75,16 @@ static void lanpr_engine_init(void *ved){
                GPU_ATTACHMENT_LEAVE
        });
 
+       GPU_framebuffer_ensure_config(&fbl->edge_thinning, {
+               GPU_ATTACHMENT_TEXTURE(txl->depth),
+               GPU_ATTACHMENT_TEXTURE(txl->color),
+               GPU_ATTACHMENT_LEAVE,
+               GPU_ATTACHMENT_LEAVE,
+               GPU_ATTACHMENT_LEAVE,
+               GPU_ATTACHMENT_LEAVE,
+               GPU_ATTACHMENT_LEAVE
+       });
+
 
        if (!OneTime.multichannel_shader) {
        OneTime.multichannel_shader = 
@@ -87,6 +99,13 @@ static void lanpr_engine_init(void *ved){
                        datatoc_common_fullscreen_vert_glsl,
                        datatoc_lanpr_snake_edge_fragment,NULL,NULL,NULL);
 
+    }
+       if (!OneTime.edge_thinning_shader) {
+       OneTime.edge_thinning_shader = 
+               GPU_shader_create(
+                       datatoc_common_fullscreen_vert_glsl,
+                       datatoc_lanpr_image_peel_fragment,NULL,NULL,NULL);
+
     }
 
 }
@@ -100,10 +119,16 @@ static void lanpr_engine_free(void){
     LANPR_PassList *psl = ((LANPR_Data *)vedata)->psl;
 
        DRW_pass_free(psl->color_pass);
+       DRW_pass_free(psl->edge_intermediate);
+
+       GPU_framebuffer_free(fbl->passes);
+       GPU_framebuffer_free(fbl->edge_intermediate);
+       GPU_framebuffer_free(fbl->edge_thinning);
 
        DRW_texture_free(txl->depth);
        DRW_texture_free(txl->color);
        DRW_texture_free(txl->normal);
+       DRW_texture_free(txl->edge_intermediate);
 }
 
 static void lanpr_cache_init(void *vedata){
@@ -118,21 +143,30 @@ static void lanpr_cache_init(void *vedata){
                stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
        }
 
-       {
-               psl->color_pass = DRW_pass_create("Color Pass", 
DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WRITE_DEPTH);
-               stl->g_data->multipass_shgrp = 
DRW_shgroup_create(OneTime.multichannel_shader, psl->color_pass);
-       }
+
+       psl->color_pass = DRW_pass_create("Color Pass", DRW_STATE_WRITE_COLOR | 
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WRITE_DEPTH);
+       stl->g_data->multipass_shgrp = 
DRW_shgroup_create(OneTime.multichannel_shader, psl->color_pass);
+
 
        struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
 
-       {
-               psl->edge_intermediate = DRW_pass_create("Edge Detection", 
DRW_STATE_WRITE_COLOR);
-               stl->g_data->edge_detect_shgrp = 
DRW_shgroup_create(OneTime.edge_detect_shader, psl->edge_intermediate);
-               DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample0", &txl->depth);
-               DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample1", &txl->color);
-               DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample2", &txl->normal);
-               DRW_shgroup_call_add(stl->g_data->edge_detect_shgrp, quad, 
NULL);
-       }
+
+       psl->edge_intermediate = DRW_pass_create("Edge Detection", 
DRW_STATE_WRITE_COLOR);
+       stl->g_data->edge_detect_shgrp = 
DRW_shgroup_create(OneTime.edge_detect_shader, psl->edge_intermediate);
+       DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample0", &txl->depth);
+       DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample1", &txl->color);
+       DRW_shgroup_uniform_texture_ref(stl->g_data->edge_detect_shgrp, 
"TexSample2", &txl->normal);
+       DRW_shgroup_call_add(stl->g_data->edge_detect_shgrp, quad, NULL);
+
+       psl->edge_thinning = DRW_pass_create("Edge Thinning Stage 1", 
DRW_STATE_WRITE_COLOR);
+       stl->g_data->edge_thinning_shgrp = 
DRW_shgroup_create(OneTime.edge_thinning_shader, psl->edge_thinning);
+       DRW_shgroup_uniform_texture_ref(stl->g_data->edge_thinning_shgrp, 
"TexSample0", &txl->edge_intermediate);
+       DRW_shgroup_call_add(stl->g_data->edge_thinning_shgrp, quad, NULL);
+
+       psl->edge_thinning_2 = DRW_pass_create("Edge Thinning Stage 2", 
DRW_STATE_WRITE_COLOR);
+       stl->g_data->edge_thinning_shgrp_2 = 
DRW_shgroup_create(OneTime.edge_thinning_shader, psl->edge_thinning_2);
+       DRW_shgroup_uniform_texture_ref(stl->g_data->edge_thinning_shgrp_2, 
"TexSample0", &txl->color);
+       DRW_shgroup_call_add(stl->g_data->edge_thinning_shgrp_2, quad, NULL);
 }
 
 static void lanpr_cache_populate(void *vedata, Object *ob){
@@ -203,6 +237,18 @@ static void lanpr_draw_scene(void *vedata)
 
        DRW_draw_pass(psl->edge_intermediate);
 
+    int stage = 0;
+    GPU_framebuffer_bind(fbl->edge_thinning);
+       GPU_framebuffer_clear(fbl->edge_thinning, clear_bits, clear_col, 
clear_depth, clear_stencil);
+       DRW_shgroup_uniform_int(stl->g_data->edge_thinning_shgrp, "Stage", 
&stage, 1);
+    DRW_draw_pass(psl->edge_thinning);
+
+       stage = 1;
+       GPU_framebuffer_bind(fbl->edge_intermediate);
+       //GPU_framebuffer_clear(fbl->edge_intermediate, clear_bits, clear_col, 
clear_depth, clear_stencil);
+       DRW_shgroup_uniform_int(stl->g_data->edge_thinning_shgrp_2, "Stage", 
&stage, 1);
+    DRW_draw_pass(psl->edge_thinning_2);
+
        GPU_framebuffer_bind(dfbl->default_fb);
        
        DRW_transform_to_display(txl->edge_intermediate);
diff --git 
a/source/blender/draw/engines/lanpr/shaders/lanpr_image_peel.fragment 
b/source/blender/draw/engines/lanpr/shaders/lanpr_image_peel.fragment
index d2b7d500d03..0b80af3ed9b 100644
--- a/source/blender/draw/engines/lanpr/shaders/lanpr_image_peel.fragment
+++ b/source/blender/draw/engines/lanpr/shaders/lanpr_image_peel.fragment
@@ -1,10 +1,7 @@
-#version 330
-in vec4 fColor;
-in vec2 fUV;
-uniform sampler2DMS TexSample0;
-uniform int uValue0;
 
-#define Stage uValue0
+in vec4 uvcoordsvar;
+uniform sampler2D TexSample0;
+uniform int Stage;
 
 int  decisions[256] = int[](0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1,
                             1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,
@@ -36,8 +33,8 @@ int PickPixel(ivec2 sp){
 
 void main(){
 
-    ivec2 texSize = textureSize(TexSample0);
-    ivec2 sp = ivec2(fUV * texSize);
+    ivec2 texSize = textureSize(TexSample0,0);
+    ivec2 sp = ivec2(uvcoordsvar.xy * texSize);
        vec4 OriginalColor = texelFetch(TexSample0, sp, 0);
 
        int p2 = PickPixel(sp+ivec2( 0,+1));
diff --git 
a/source/blender/draw/engines/lanpr/shaders/lanpr_snake_edge.fragment 
b/source/blender/draw/engines/lanpr/shaders/lanpr_snake_edge.fragment
index e106d3b3b95..6272c80193e 100644
--- a/source/blender/draw/engines/lanpr/shaders/lanpr_snake_edge.fragment
+++ b/source/blender/draw/engines/lanpr/shaders/lanpr_snake_edge.fragment
@@ -71,6 +71,8 @@ vec4 DetectEdge(sampler2D tex, float clamp, float strength){
         float g3 = sqrt(pow(gx3, 2.0) + pow(gy3, 2.0)); 
      
         float value = max(max(g1,g2),g3);
+
+        value=value>1?value:0;
         return vec4(vec3(value),1);
 
         //if(value<clamp) value=0;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to