2012-12-18 00:51:25 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
*/
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
#include <iostream>
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
#include <map>
|
|
|
|
|
#include <set>
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
#include "../application/AppCanvas.h"
|
|
|
|
|
#include "../application/AppConfig.h"
|
|
|
|
|
#include "../application/AppView.h"
|
|
|
|
|
#include "../application/Controller.h"
|
|
|
|
|
|
2014-06-28 19:18:47 +09:00
|
|
|
#include "BlenderStrokeRenderer.h"
|
|
|
|
|
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
using namespace std;
|
2013-04-09 00:46:49 +00:00
|
|
|
using namespace Freestyle;
|
2008-05-19 05:34:31 +00:00
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
extern "C" {
|
|
|
|
|
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2008-11-09 13:14:41 +00:00
|
|
|
|
2008-07-02 12:16:36 +00:00
|
|
|
#include "DNA_camera_types.h"
|
2009-08-04 00:40:36 +00:00
|
|
|
#include "DNA_freestyle_types.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "DNA_group_types.h"
|
2014-07-20 17:41:36 +09:00
|
|
|
#include "DNA_material_types.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "DNA_text_types.h"
|
2008-07-02 12:16:36 +00:00
|
|
|
|
2013-03-23 03:00:37 +00:00
|
|
|
#include "BKE_freestyle.h"
|
2010-06-25 22:45:42 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_linestyle.h"
|
2009-09-28 03:56:31 +00:00
|
|
|
#include "BKE_main.h"
|
2010-07-26 01:23:27 +00:00
|
|
|
#include "BKE_text.h"
|
2013-05-01 00:26:47 +00:00
|
|
|
#include "BKE_context.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2015-12-28 17:46:48 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2010-01-10 14:08:59 +00:00
|
|
|
#include "BLI_math.h"
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
#include "BLI_math_color_blend.h"
|
2013-03-23 21:38:35 +00:00
|
|
|
#include "BLI_callbacks.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BPY_extern.h"
|
|
|
|
|
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
#include "renderpipeline.h"
|
2008-05-19 05:34:31 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "FRS_freestyle.h"
|
2009-11-10 00:03:31 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#define DEFAULT_SPHERE_RADIUS 1.0f
|
|
|
|
|
#define DEFAULT_DKR_EPSILON 0.0f
|
2012-01-23 23:32:09 +00:00
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
struct FreestyleGlobals g_freestyle;
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Freestyle configuration
|
2014-02-05 22:36:15 +11:00
|
|
|
static bool freestyle_is_initialized = false;
|
2014-06-26 12:54:55 +09:00
|
|
|
static Config::Path *pathconfig = NULL;
|
2012-12-18 00:51:25 +00:00
|
|
|
static Controller *controller = NULL;
|
|
|
|
|
static AppView *view = NULL;
|
2008-06-08 19:35:20 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// line set buffer for copy & paste
|
|
|
|
|
static FreestyleLineSet lineset_buffer;
|
|
|
|
|
static bool lineset_copied = false;
|
2012-04-10 23:53:46 +00:00
|
|
|
|
2010-01-10 14:08:59 +00:00
|
|
|
|
2015-03-27 15:50:18 +05:00
|
|
|
static void load_post_callback(struct Main * /*main*/, struct ID * /*id*/, void * /*arg*/)
|
2013-03-23 21:38:35 +00:00
|
|
|
{
|
|
|
|
|
lineset_copied = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bCallbackFuncStore load_post_callback_funcstore = {
|
|
|
|
|
NULL, NULL, /* next, prev */
|
|
|
|
|
load_post_callback, /* func */
|
|
|
|
|
NULL, /* arg */
|
|
|
|
|
0 /* alloc */
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
//=======================================================
|
|
|
|
|
// Initialization
|
|
|
|
|
//=======================================================
|
|
|
|
|
|
|
|
|
|
void FRS_initialize()
|
|
|
|
|
{
|
|
|
|
|
if (freestyle_is_initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-26 12:54:55 +09:00
|
|
|
pathconfig = new Config::Path;
|
2012-12-18 00:51:25 +00:00
|
|
|
controller = new Controller();
|
|
|
|
|
view = new AppView;
|
|
|
|
|
controller->setView(view);
|
|
|
|
|
controller->Clear();
|
2015-11-23 15:31:11 +11:00
|
|
|
g_freestyle.scene = NULL;
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset_copied = false;
|
|
|
|
|
|
2013-03-23 21:38:35 +00:00
|
|
|
BLI_callback_add(&load_post_callback_funcstore, BLI_CB_EVT_LOAD_POST);
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
freestyle_is_initialized = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FRS_set_context(bContext *C)
|
|
|
|
|
{
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->setContext(C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FRS_exit()
|
|
|
|
|
{
|
2014-06-26 12:54:55 +09:00
|
|
|
delete pathconfig;
|
2012-12-18 00:51:25 +00:00
|
|
|
delete controller;
|
|
|
|
|
delete view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=======================================================
|
|
|
|
|
// Rendering
|
|
|
|
|
//=======================================================
|
|
|
|
|
|
|
|
|
|
static void init_view(Render *re)
|
|
|
|
|
{
|
|
|
|
|
int width = re->winx;
|
|
|
|
|
int height = re->winy;
|
|
|
|
|
int xmin = re->disprect.xmin;
|
|
|
|
|
int ymin = re->disprect.ymin;
|
|
|
|
|
int xmax = re->disprect.xmax;
|
|
|
|
|
int ymax = re->disprect.ymax;
|
|
|
|
|
|
|
|
|
|
float thickness = 1.0f;
|
|
|
|
|
switch (re->r.line_thickness_mode) {
|
|
|
|
|
case R_LINE_THICKNESS_ABSOLUTE:
|
|
|
|
|
thickness = re->r.unit_line_thickness * (re->r.size / 100.f);
|
|
|
|
|
break;
|
|
|
|
|
case R_LINE_THICKNESS_RELATIVE:
|
|
|
|
|
thickness = height / 480.f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
g_freestyle.viewport[0] = g_freestyle.viewport[1] = 0;
|
|
|
|
|
g_freestyle.viewport[2] = width;
|
|
|
|
|
g_freestyle.viewport[3] = height;
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
view->setWidth(width);
|
|
|
|
|
view->setHeight(height);
|
|
|
|
|
view->setBorder(xmin, ymin, xmax, ymax);
|
|
|
|
|
view->setThickness(thickness);
|
|
|
|
|
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "\n=== Dimensions of the 2D image coordinate system ===" << endl;
|
|
|
|
|
cout << "Width : " << width << endl;
|
|
|
|
|
cout << "Height : " << height << endl;
|
|
|
|
|
if (re->r.mode & R_BORDER)
|
|
|
|
|
cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
|
|
|
|
|
cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void init_camera(Render *re)
|
|
|
|
|
{
|
|
|
|
|
// It is assumed that imported meshes are in the camera coordinate system.
|
|
|
|
|
// Therefore, the view point (i.e., camera position) is at the origin, and
|
2014-10-29 14:11:19 +01:00
|
|
|
// the model-view matrix is simply the identity matrix.
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
zero_v3(g_freestyle.viewpoint);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
unit_m4(g_freestyle.mv);
|
2010-12-06 22:17:19 +00:00
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
copy_m4_m4(g_freestyle.proj, re->winmat);
|
2008-08-08 08:53:13 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#if 0
|
2015-11-23 15:31:11 +11:00
|
|
|
print_m4("mv", g_freestyle.mv);
|
|
|
|
|
print_m4("proj", g_freestyle.proj);
|
2012-12-18 00:51:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *escape_quotes(char *name)
|
|
|
|
|
{
|
2013-03-07 23:17:23 +00:00
|
|
|
char *s = (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
|
2012-12-18 00:51:25 +00:00
|
|
|
char *p = s;
|
|
|
|
|
while (*name) {
|
|
|
|
|
if (*name == '\'')
|
|
|
|
|
*(p++) = '\\';
|
|
|
|
|
*(p++) = *(name++);
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 23:18:32 +09:00
|
|
|
static char * create_lineset_handler(char *layer_name, char *lineset_name)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
2015-04-29 00:23:52 +05:00
|
|
|
const char *fmt = "__import__('parameter_editor').process('%s', '%s')\n";
|
2012-12-18 00:51:25 +00:00
|
|
|
char *s1 = escape_quotes(layer_name);
|
|
|
|
|
char *s2 = escape_quotes(lineset_name);
|
2015-04-28 23:18:32 +09:00
|
|
|
char *text = BLI_sprintfN(fmt, s1, s2);
|
2012-12-18 00:51:25 +00:00
|
|
|
MEM_freeN(s1);
|
|
|
|
|
MEM_freeN(s2);
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct edge_type_condition
|
|
|
|
|
{
|
|
|
|
|
int edge_type, value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// examines the conditions and returns true if the target edge type needs to be computed
|
|
|
|
|
static bool test_edge_type_conditions(struct edge_type_condition *conditions,
|
|
|
|
|
int num_edge_types, bool logical_and, int target, bool distinct)
|
|
|
|
|
{
|
|
|
|
|
int target_condition = 0;
|
|
|
|
|
int num_non_target_positive_conditions = 0;
|
|
|
|
|
int num_non_target_negative_conditions = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num_edge_types; i++) {
|
|
|
|
|
if (conditions[i].edge_type == target)
|
|
|
|
|
target_condition = conditions[i].value;
|
|
|
|
|
else if (conditions[i].value > 0)
|
|
|
|
|
++num_non_target_positive_conditions;
|
|
|
|
|
else if (conditions[i].value < 0)
|
|
|
|
|
++num_non_target_negative_conditions;
|
|
|
|
|
}
|
|
|
|
|
if (distinct) {
|
|
|
|
|
// In this case, the 'target' edge type is assumed to appear on distinct edge
|
|
|
|
|
// of its own and never together with other edge types.
|
|
|
|
|
if (logical_and) {
|
|
|
|
|
if (num_non_target_positive_conditions > 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (target_condition > 0)
|
|
|
|
|
return true;
|
|
|
|
|
if (target_condition < 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (num_non_target_negative_conditions > 0)
|
|
|
|
|
return true;
|
2011-10-27 20:57:14 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
else {
|
2011-10-27 20:57:14 +00:00
|
|
|
if (target_condition > 0)
|
|
|
|
|
return true;
|
2012-12-18 00:51:25 +00:00
|
|
|
if (num_non_target_negative_conditions > 0)
|
|
|
|
|
return true;
|
2011-10-27 20:57:14 +00:00
|
|
|
if (target_condition < 0)
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
|
|
|
|
if (num_non_target_positive_conditions > 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// In this case, the 'target' edge type may appear together with other edge types.
|
|
|
|
|
if (target_condition > 0)
|
|
|
|
|
return true;
|
|
|
|
|
if (target_condition < 0)
|
|
|
|
|
return true;
|
|
|
|
|
if (logical_and) {
|
|
|
|
|
if (num_non_target_positive_conditions > 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (num_non_target_negative_conditions > 0)
|
2011-10-27 20:57:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
else {
|
|
|
|
|
if (num_non_target_negative_conditions > 0)
|
|
|
|
|
return true;
|
|
|
|
|
if (num_non_target_positive_conditions > 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-10-27 20:57:14 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2011-10-27 20:57:14 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static void prepare(Render *re, ViewLayer *view_layer)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
|
|
|
|
// load mesh
|
2015-12-29 12:42:12 +01:00
|
|
|
re->i.infostr = IFACE_("Freestyle: Mesh loading");
|
2012-12-18 00:51:25 +00:00
|
|
|
re->stats_draw(re->sdh, &re->i);
|
|
|
|
|
re->i.infostr = NULL;
|
2017-11-22 10:52:39 -02:00
|
|
|
if (controller->LoadMesh(re, view_layer)) // returns if scene cannot be loaded or if empty
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
|
|
|
|
if (re->test_break(re->tbh))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// add style modules
|
2017-11-22 10:52:39 -02:00
|
|
|
FreestyleConfig *config = &view_layer->freestyle_config;
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "\n=== Rendering options ===" << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
int layer_count = 0;
|
|
|
|
|
|
|
|
|
|
switch (config->mode) {
|
|
|
|
|
case FREESTYLE_CONTROL_SCRIPT_MODE:
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Modules :" << endl;
|
|
|
|
|
}
|
2013-03-07 23:17:23 +00:00
|
|
|
for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig *)config->modules.first;
|
2012-12-18 00:51:25 +00:00
|
|
|
module_conf;
|
|
|
|
|
module_conf = module_conf->next)
|
|
|
|
|
{
|
2013-04-03 00:00:29 +00:00
|
|
|
if (module_conf->script && module_conf->is_displayed) {
|
|
|
|
|
const char *id_name = module_conf->script->id.name + 2;
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
2013-04-03 00:00:29 +00:00
|
|
|
cout << " " << layer_count + 1 << ": " << id_name;
|
|
|
|
|
if (module_conf->script->name)
|
|
|
|
|
cout << " (" << module_conf->script->name << ")";
|
|
|
|
|
cout << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
}
|
2014-07-19 18:52:32 +09:00
|
|
|
controller->InsertStyleModule(layer_count, id_name, module_conf->script);
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->toggleLayer(layer_count, true);
|
|
|
|
|
layer_count++;
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->setComputeRidgesAndValleysFlag((config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
|
|
|
|
|
controller->setComputeSuggestiveContoursFlag((config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
|
|
|
|
|
controller->setComputeMaterialBoundariesFlag((config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
|
|
|
|
|
break;
|
|
|
|
|
case FREESTYLE_CONTROL_EDITOR_MODE:
|
|
|
|
|
int use_ridges_and_valleys = 0;
|
|
|
|
|
int use_suggestive_contours = 0;
|
|
|
|
|
int use_material_boundaries = 0;
|
|
|
|
|
struct edge_type_condition conditions[] = {
|
|
|
|
|
{FREESTYLE_FE_SILHOUETTE, 0},
|
|
|
|
|
{FREESTYLE_FE_BORDER, 0},
|
|
|
|
|
{FREESTYLE_FE_CREASE, 0},
|
|
|
|
|
{FREESTYLE_FE_RIDGE_VALLEY, 0},
|
|
|
|
|
{FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
|
|
|
|
|
{FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
|
|
|
|
|
{FREESTYLE_FE_CONTOUR, 0},
|
|
|
|
|
{FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
|
|
|
|
|
{FREESTYLE_FE_EDGE_MARK, 0}
|
|
|
|
|
};
|
|
|
|
|
int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Linesets:" << endl;
|
|
|
|
|
}
|
2013-03-07 23:17:23 +00:00
|
|
|
for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first;
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset;
|
|
|
|
|
lineset = lineset->next)
|
|
|
|
|
{
|
|
|
|
|
if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
2013-03-07 23:17:23 +00:00
|
|
|
cout << " " << layer_count+1 << ": " << lineset->name << " - " <<
|
2013-09-30 09:28:43 +00:00
|
|
|
(lineset->linestyle ? (lineset->linestyle->id.name + 2) : "<NULL>") << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
}
|
2017-11-22 10:52:39 -02:00
|
|
|
char *buffer = create_lineset_handler(view_layer->name, lineset->name);
|
2015-04-28 23:18:32 +09:00
|
|
|
controller->InsertStyleModule(layer_count, lineset->name, buffer);
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->toggleLayer(layer_count, true);
|
2015-04-28 23:18:32 +09:00
|
|
|
MEM_freeN(buffer);
|
2012-12-18 00:51:25 +00:00
|
|
|
if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
|
|
|
|
|
++use_ridges_and_valleys;
|
|
|
|
|
++use_suggestive_contours;
|
|
|
|
|
++use_material_boundaries;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// conditions for feature edge selection by edge types
|
|
|
|
|
for (int i = 0; i < num_edge_types; i++) {
|
|
|
|
|
if (!(lineset->edge_types & conditions[i].edge_type))
|
|
|
|
|
conditions[i].value = 0; // no condition specified
|
|
|
|
|
else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
|
|
|
|
|
conditions[i].value = 1; // condition: X
|
|
|
|
|
else
|
|
|
|
|
conditions[i].value = -1; // condition: NOT X
|
|
|
|
|
}
|
|
|
|
|
// logical operator for the selection conditions
|
|
|
|
|
bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
|
|
|
|
|
// negation operator
|
|
|
|
|
if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
|
|
|
|
|
// convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
|
|
|
|
|
// NOT (X OR Y) --> (NOT X) AND (NOT Y)
|
|
|
|
|
// NOT (X AND Y) --> (NOT X) OR (NOT Y)
|
|
|
|
|
for (int i = 0; i < num_edge_types; i++)
|
|
|
|
|
conditions[i].value *= -1;
|
|
|
|
|
logical_and = !logical_and;
|
|
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
|
|
|
|
|
FREESTYLE_FE_RIDGE_VALLEY, true))
|
|
|
|
|
{
|
2010-08-07 22:48:25 +00:00
|
|
|
++use_ridges_and_valleys;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
|
|
|
|
|
FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
|
|
|
|
|
{
|
2010-08-07 22:48:25 +00:00
|
|
|
++use_suggestive_contours;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
|
|
|
|
|
FREESTYLE_FE_MATERIAL_BOUNDARY, true))
|
|
|
|
|
{
|
2010-08-07 22:48:25 +00:00
|
|
|
++use_material_boundaries;
|
|
|
|
|
}
|
2010-07-26 01:23:27 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
layer_count++;
|
2010-07-26 01:23:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0);
|
|
|
|
|
controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0);
|
|
|
|
|
controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set parameters
|
|
|
|
|
if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) {
|
|
|
|
|
controller->setSphereRadius(config->sphere_radius);
|
|
|
|
|
controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
controller->setSphereRadius(DEFAULT_SPHERE_RADIUS);
|
|
|
|
|
controller->setSuggestiveContourKrDerivativeEpsilon(DEFAULT_DKR_EPSILON);
|
|
|
|
|
}
|
|
|
|
|
controller->setFaceSmoothness((config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
|
|
|
|
|
controller->setCreaseAngle(RAD2DEGF(config->crease_angle));
|
|
|
|
|
controller->setVisibilityAlgo((config->flags & FREESTYLE_CULLING) ?
|
|
|
|
|
FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE :
|
|
|
|
|
FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE);
|
|
|
|
|
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Crease angle : " << controller->getCreaseAngle() << endl;
|
|
|
|
|
cout << "Sphere radius : " << controller->getSphereRadius() << endl;
|
|
|
|
|
cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
|
2016-12-29 10:34:59 +01:00
|
|
|
cout << "Ridges and valleys : " <<
|
|
|
|
|
(controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
|
2013-03-07 23:17:23 +00:00
|
|
|
cout << "Suggestive contours : " <<
|
|
|
|
|
(controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
|
|
|
|
|
cout << "Suggestive contour Kr derivative epsilon : " <<
|
|
|
|
|
controller->getSuggestiveContourKrDerivativeEpsilon() << endl;
|
|
|
|
|
cout << "Material boundaries : " <<
|
|
|
|
|
(controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
cout << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
// set diffuse and z depth passes
|
2017-11-22 10:52:39 -02:00
|
|
|
RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name);
|
2012-12-18 00:51:25 +00:00
|
|
|
bool diffuse = false, z = false;
|
2013-03-07 23:17:23 +00:00
|
|
|
for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
|
|
|
|
|
diffuse = true;
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
}
|
|
|
|
|
if (STREQ(rpass->name, RE_PASSNAME_Z)) {
|
2012-12-18 00:51:25 +00:00
|
|
|
controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
|
|
|
|
|
z = true;
|
2012-02-05 11:37:39 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Passes :" << endl;
|
|
|
|
|
cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
|
|
|
|
|
cout << " Z = " << (z ? "enabled" : "disabled") << endl;
|
|
|
|
|
}
|
2010-02-14 03:17:52 +00:00
|
|
|
|
2014-01-28 23:24:59 +09:00
|
|
|
if (controller->hitViewMapCache())
|
|
|
|
|
return;
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// compute view map
|
2015-12-29 12:42:12 +01:00
|
|
|
re->i.infostr = IFACE_("Freestyle: View map creation");
|
2012-12-18 00:51:25 +00:00
|
|
|
re->stats_draw(re->sdh, &re->i);
|
|
|
|
|
re->i.infostr = NULL;
|
|
|
|
|
controller->ComputeViewMap();
|
|
|
|
|
}
|
2008-11-09 13:14:41 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
void FRS_composite_result(Render *re, ViewLayer *view_layer, Render *freestyle_render)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
|
|
|
|
RenderLayer *rl;
|
|
|
|
|
float *src, *dest, *pixSrc, *pixDest;
|
|
|
|
|
int x, y, rectx, recty;
|
|
|
|
|
|
|
|
|
|
if (freestyle_render == NULL || freestyle_render->result == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rl = render_get_active_layer( freestyle_render, freestyle_render->result );
|
2015-04-06 10:40:12 -03:00
|
|
|
if (!rl) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
2015-05-09 13:04:29 +09:00
|
|
|
cout << "No source render layer to composite" << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
src = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, freestyle_render->viewname);
|
2015-05-09 13:04:29 +09:00
|
|
|
if (!src) {
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "No source result image to composite" << endl;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
#if 0
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "src: " << rl->rectx << " x " << rl->recty << endl;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
rl = RE_GetRenderLayer(re->result, view_layer->name);
|
2015-05-09 13:04:29 +09:00
|
|
|
if (!rl) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
2015-05-09 13:04:29 +09:00
|
|
|
cout << "No destination render layer to composite to" << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
dest = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, re->viewname);
|
2015-05-09 13:04:29 +09:00
|
|
|
if (!dest) {
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "No destination result image to composite to" << endl;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
#if 0
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
rectx = re->rectx;
|
|
|
|
|
recty = re->recty;
|
|
|
|
|
for (y = 0; y < recty; y++) {
|
|
|
|
|
for (x = 0; x < rectx; x++) {
|
|
|
|
|
pixSrc = src + 4 * (rectx * y + x);
|
|
|
|
|
if (pixSrc[3] > 0.0) {
|
|
|
|
|
pixDest = dest + 4 * (rectx * y + x);
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
blend_color_mix_float(pixDest, pixDest, pixSrc);
|
2010-03-29 21:58:58 +00:00
|
|
|
}
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2010-03-28 17:46:10 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static int displayed_layer_count(ViewLayer *view_layer)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
switch (view_layer->freestyle_config.mode) {
|
2012-12-18 00:51:25 +00:00
|
|
|
case FREESTYLE_CONTROL_SCRIPT_MODE:
|
2017-11-22 10:52:39 -02:00
|
|
|
for (FreestyleModuleConfig *module = (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first;
|
2012-12-18 00:51:25 +00:00
|
|
|
module;
|
|
|
|
|
module = module->next)
|
|
|
|
|
{
|
2013-04-03 00:00:29 +00:00
|
|
|
if (module->script && module->is_displayed)
|
2012-12-18 00:51:25 +00:00
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FREESTYLE_CONTROL_EDITOR_MODE:
|
2017-11-22 10:52:39 -02:00
|
|
|
for (FreestyleLineSet *lineset = (FreestyleLineSet *)view_layer->freestyle_config.linesets.first;
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset;
|
|
|
|
|
lineset = lineset->next)
|
|
|
|
|
{
|
|
|
|
|
if (lineset->flags & FREESTYLE_LINESET_ENABLED)
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-03-28 17:46:10 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
int FRS_is_freestyle_enabled(ViewLayer *view_layer)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
2017-11-22 10:52:39 -02:00
|
|
|
return ((view_layer->flag & VIEW_LAYER_RENDER) &&
|
|
|
|
|
(view_layer->flag & VIEW_LAYER_FREESTYLE) &&
|
|
|
|
|
displayed_layer_count(view_layer) > 0);
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2010-03-28 17:46:10 +00:00
|
|
|
|
2015-05-16 23:55:45 +09:00
|
|
|
void FRS_init_stroke_renderer(Render *re)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << endl;
|
|
|
|
|
cout << "#===============================================================" << endl;
|
|
|
|
|
cout << "# Freestyle" << endl;
|
|
|
|
|
cout << "#===============================================================" << endl;
|
|
|
|
|
}
|
2010-03-28 17:46:10 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
init_view(re);
|
|
|
|
|
|
|
|
|
|
controller->ResetRenderCount();
|
|
|
|
|
}
|
2010-03-28 17:46:10 +00:00
|
|
|
|
2015-05-16 23:55:45 +09:00
|
|
|
void FRS_begin_stroke_rendering(Render *re)
|
|
|
|
|
{
|
|
|
|
|
init_camera(re);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
|
|
|
|
Render *freestyle_render = NULL;
|
|
|
|
|
|
2013-06-11 02:32:01 +00:00
|
|
|
if (!render)
|
|
|
|
|
return controller->RenderStrokes(re, false);
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
RenderMonitor monitor(re);
|
|
|
|
|
controller->setRenderMonitor(&monitor);
|
2017-11-22 10:52:39 -02:00
|
|
|
controller->setViewMapCache((view_layer->freestyle_config.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << endl;
|
|
|
|
|
cout << "----------------------------------------------------------" << endl;
|
2017-11-22 10:52:39 -02:00
|
|
|
cout << "| " << (re->scene->id.name + 2) << "|" << view_layer->name << endl;
|
2013-01-03 23:27:20 +00:00
|
|
|
cout << "----------------------------------------------------------" << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
// prepare Freestyle:
|
|
|
|
|
// - load mesh
|
|
|
|
|
// - add style modules
|
|
|
|
|
// - set parameters
|
|
|
|
|
// - compute view map
|
2017-11-22 10:52:39 -02:00
|
|
|
prepare(re, view_layer);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
if (re->test_break(re->tbh)) {
|
|
|
|
|
controller->CloseFile();
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Break" << endl;
|
|
|
|
|
}
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
else {
|
|
|
|
|
// render and composite Freestyle result
|
|
|
|
|
if (controller->_ViewMap) {
|
|
|
|
|
// render strokes
|
2015-12-29 12:42:12 +01:00
|
|
|
re->i.infostr = IFACE_("Freestyle: Stroke rendering");
|
2014-06-19 16:21:17 +06:00
|
|
|
re->stats_draw(re->sdh, &re->i);
|
|
|
|
|
re->i.infostr = NULL;
|
2015-11-23 15:31:11 +11:00
|
|
|
g_freestyle.scene = re->scene;
|
2016-05-05 23:09:22 +09:00
|
|
|
int strokeCount = controller->DrawStrokes();
|
|
|
|
|
if (strokeCount > 0) {
|
|
|
|
|
freestyle_render = controller->RenderStrokes(re, true);
|
|
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
controller->CloseFile();
|
2015-11-23 15:31:11 +11:00
|
|
|
g_freestyle.scene = NULL;
|
2014-06-19 16:21:17 +06:00
|
|
|
|
|
|
|
|
// composite result
|
2016-05-05 23:09:22 +09:00
|
|
|
if (freestyle_render) {
|
2017-11-22 10:52:39 -02:00
|
|
|
FRS_composite_result(re, view_layer, freestyle_render);
|
2016-05-05 23:09:22 +09:00
|
|
|
RE_FreeRenderResult(freestyle_render->result);
|
|
|
|
|
freestyle_render->result = NULL;
|
|
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
}
|
2010-07-26 01:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
return freestyle_render;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-16 23:55:45 +09:00
|
|
|
void FRS_end_stroke_rendering(Render * /*re*/)
|
2013-03-07 23:17:23 +00:00
|
|
|
{
|
2012-12-18 00:51:25 +00:00
|
|
|
// clear canvas
|
|
|
|
|
controller->Clear();
|
|
|
|
|
}
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
|
2014-10-02 12:47:05 +02:00
|
|
|
void FRS_free_view_map_cache(void)
|
2014-01-28 23:24:59 +09:00
|
|
|
{
|
|
|
|
|
// free cache
|
|
|
|
|
controller->DeleteViewMap(true);
|
|
|
|
|
#if 0
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
printf("View map cache freed\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
//=======================================================
|
|
|
|
|
// Freestyle Panel Configuration
|
|
|
|
|
//=======================================================
|
2010-06-25 22:45:42 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void FRS_copy_active_lineset(FreestyleConfig *config)
|
|
|
|
|
{
|
2013-03-23 03:00:37 +00:00
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
if (lineset) {
|
|
|
|
|
lineset_buffer.linestyle = lineset->linestyle;
|
|
|
|
|
lineset_buffer.flags = lineset->flags;
|
|
|
|
|
lineset_buffer.selection = lineset->selection;
|
|
|
|
|
lineset_buffer.qi = lineset->qi;
|
|
|
|
|
lineset_buffer.qi_start = lineset->qi_start;
|
|
|
|
|
lineset_buffer.qi_end = lineset->qi_end;
|
|
|
|
|
lineset_buffer.edge_types = lineset->edge_types;
|
|
|
|
|
lineset_buffer.exclude_edge_types = lineset->exclude_edge_types;
|
|
|
|
|
lineset_buffer.group = lineset->group;
|
|
|
|
|
strcpy(lineset_buffer.name, lineset->name);
|
|
|
|
|
lineset_copied = true;
|
2011-11-20 23:44:50 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2011-11-20 23:44:50 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void FRS_paste_active_lineset(FreestyleConfig *config)
|
|
|
|
|
{
|
|
|
|
|
if (!lineset_copied)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-03-23 03:00:37 +00:00
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
if (lineset) {
|
2013-09-30 09:28:43 +00:00
|
|
|
if (lineset->linestyle)
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&lineset->linestyle->id);
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset->linestyle = lineset_buffer.linestyle;
|
2013-09-30 09:28:43 +00:00
|
|
|
if (lineset->linestyle)
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&lineset->linestyle->id);
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset->flags = lineset_buffer.flags;
|
|
|
|
|
lineset->selection = lineset_buffer.selection;
|
|
|
|
|
lineset->qi = lineset_buffer.qi;
|
|
|
|
|
lineset->qi_start = lineset_buffer.qi_start;
|
|
|
|
|
lineset->qi_end = lineset_buffer.qi_end;
|
|
|
|
|
lineset->edge_types = lineset_buffer.edge_types;
|
|
|
|
|
lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
|
|
|
|
|
if (lineset->group) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&lineset->group->id);
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset->group = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (lineset_buffer.group) {
|
|
|
|
|
lineset->group = lineset_buffer.group;
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&lineset->group->id);
|
2011-11-13 21:55:13 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
strcpy(lineset->name, lineset_buffer.name);
|
2013-03-23 03:00:37 +00:00
|
|
|
BKE_freestyle_lineset_unique_name(config, lineset);
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset->flags |= FREESTYLE_LINESET_CURRENT;
|
2010-06-25 22:45:42 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2010-06-25 22:45:42 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void FRS_delete_active_lineset(FreestyleConfig *config)
|
|
|
|
|
{
|
2013-03-23 03:00:37 +00:00
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2010-06-25 22:45:42 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
if (lineset) {
|
2014-05-10 23:32:22 +09:00
|
|
|
BKE_freestyle_lineset_delete(config, lineset);
|
2010-06-25 22:45:42 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2010-06-25 22:45:42 +00:00
|
|
|
|
2016-09-18 21:36:34 +02:00
|
|
|
/**
|
|
|
|
|
* Reinsert the active lineset at an offset \a direction from current position.
|
|
|
|
|
* \return if position of active lineset has changed.
|
|
|
|
|
*/
|
|
|
|
|
bool FRS_move_active_lineset(FreestyleConfig *config, int direction)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
2013-03-23 03:00:37 +00:00
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2016-09-18 21:36:34 +02:00
|
|
|
return (lineset != NULL) && BLI_listbase_link_move(&config->linesets, lineset, direction);
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2010-06-25 22:45:42 +00:00
|
|
|
|
2014-06-28 19:18:47 +09:00
|
|
|
// Testing
|
|
|
|
|
|
2014-08-01 10:18:25 +09:00
|
|
|
Material *FRS_create_stroke_material(Main *bmain, struct FreestyleLineStyle *linestyle)
|
2014-06-28 19:18:47 +09:00
|
|
|
{
|
2014-07-21 18:45:39 +09:00
|
|
|
bNodeTree *nt = (linestyle->use_nodes) ? linestyle->nodetree : NULL;
|
2014-08-01 10:18:25 +09:00
|
|
|
Material *ma = BlenderStrokeRenderer::GetStrokeShader(bmain, nt, true);
|
2014-07-20 17:41:36 +09:00
|
|
|
ma->id.us = 0;
|
|
|
|
|
return ma;
|
2014-06-28 19:18:47 +09:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
} // extern "C"
|