Commit: 51a60c9990bb52c72e20675a3d3a09288d647a95
Author: Antonio Vazquez
Date:   Thu Feb 8 11:07:42 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB51a60c9990bb52c72e20675a3d3a09288d647a95

Fix render pixel size

The calculation must be equal to the viewport, because using the camera pixel 
size, the result is not correct.

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

M       source/blender/draw/engines/gpencil/gpencil_engine.c
M       source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index d2b09509556..5b98d15da6f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -300,12 +300,7 @@ static void GPENCIL_cache_init(void *vedata)
                        stl->storage->pixsize = DRW_viewport_pixelsize_get();
                }
                else {
-                       const float *viewport_size = DRW_viewport_size_get();
-                       CameraParams params;
-                       BKE_camera_params_init(&params);
-                       BKE_camera_params_from_object(&params, scene->camera);
-                       BKE_camera_params_compute_viewplane(&params, 
viewport_size[0], viewport_size[1], 1.0f, 1.0f);
-                       stl->storage->pixsize = &params.viewdx;
+                       stl->storage->pixsize = &stl->storage->render_pixsize;
                }
 
                /* detect if painting session */
@@ -864,6 +859,29 @@ static void GPENCIL_draw_scene(void *vedata)
        }
 }
 
+/* Get pixel size for render 
+ * This function uses the same calculation used for viewport, because if use
+ * camera pixelsize, the result is not correct.
+ */
+static float get_render_pixelsize(float persmat[4][4], int winx, int winy)
+{
+       float v1[3], v2[3];
+       float len_px, len_sc;
+
+       v1[0] = persmat[0][0];
+       v1[1] = persmat[1][0];
+       v1[2] = persmat[2][0];
+
+       v2[0] = persmat[0][1];
+       v2[1] = persmat[1][1];
+       v2[2] = persmat[2][1];
+
+       len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
+       len_sc = (float)MAX2(winx, winy);
+
+       return len_px / len_sc;
+}
+
 /* init render data */
 void GPENCIL_render_init(GPENCIL_Data *ved, RenderEngine *engine, struct 
Depsgraph *depsgraph)
 {
@@ -911,6 +929,8 @@ void GPENCIL_render_init(GPENCIL_Data *ved, RenderEngine 
*engine, struct Depsgra
        DRW_viewport_matrix_override_set(stl->storage->viewmat, DRW_MAT_VIEW);
        DRW_viewport_matrix_override_set(stl->storage->viewinv, 
DRW_MAT_VIEWINV);
 
+       /* calculate pixel size for render */
+       stl->storage->render_pixsize = 
get_render_pixelsize(stl->storage->persmat, viewport_size[0], viewport_size[1]);
        /* INIT CACHE */
        GPENCIL_cache_init(vedata);
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0f7651fe6b2..70e3e3ff583 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -168,6 +168,7 @@ typedef struct GPENCIL_Storage {
        float gridsize[2];
        float gridcolor[3];
        const float *pixsize;
+       float render_pixsize;
 
        /* Render Matrices and data */
        float persmat[4][4], persinv[4][4];

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

Reply via email to