2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
2012-12-18 00:51:25 +00:00
|
|
|
*/
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
#include <iostream>
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
#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
|
|
|
|
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
|
|
|
|
2018-08-29 15:32:50 +02:00
|
|
|
#include "DNA_collection_types.h"
|
2009-08-04 00:40:36 +00:00
|
|
|
#include "DNA_freestyle_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
|
|
|
|
2024-02-09 19:29:34 +01:00
|
|
|
#include "BKE_callbacks.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2013-03-23 03:00:37 +00:00
|
|
|
#include "BKE_freestyle.h"
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2010-06-25 22:45:42 +00:00
|
|
|
#include "BKE_linestyle.h"
|
2024-02-10 19:16:25 +01:00
|
|
|
#include "BKE_scene.hh"
|
2010-07-26 01:23:27 +00:00
|
|
|
#include "BKE_text.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2015-12-28 17:46:48 +01:00
|
|
|
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.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"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2024-09-24 17:07:49 +02:00
|
|
|
#include "BPY_extern.hh"
|
2008-06-08 19:35:20 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2019-01-24 07:08:19 +01:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
2023-07-10 16:33:32 +02:00
|
|
|
|
2023-05-02 16:55:45 +02:00
|
|
|
#include "pipeline.hh"
|
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
|
|
|
|
2023-06-04 18:46:04 +10:00
|
|
|
FreestyleGlobals g_freestyle;
|
2015-11-23 15:31:11 +11:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Freestyle configuration
|
2014-02-05 22:36:15 +11:00
|
|
|
static bool freestyle_is_initialized = false;
|
2020-11-06 17:49:09 +01:00
|
|
|
static Config::Path *pathconfig = nullptr;
|
|
|
|
|
static Controller *controller = nullptr;
|
|
|
|
|
static AppView *view = nullptr;
|
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
|
|
|
|
2023-06-04 18:46:04 +10:00
|
|
|
static void load_post_callback(Main * /*main*/,
|
|
|
|
|
PointerRNA ** /*pointers*/,
|
2019-09-09 10:25:04 +02:00
|
|
|
const int /*num_pointers*/,
|
|
|
|
|
void * /*arg*/)
|
2013-03-23 21:38:35 +00:00
|
|
|
{
|
|
|
|
|
lineset_copied = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bCallbackFuncStore load_post_callback_funcstore = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*next*/ nullptr,
|
|
|
|
|
/*prev*/ nullptr,
|
|
|
|
|
/*func*/ load_post_callback,
|
|
|
|
|
/*arg*/ nullptr,
|
|
|
|
|
/*alloc*/ 0};
|
2013-03-23 21:38:35 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
//=======================================================
|
2018-06-17 17:05:14 +02:00
|
|
|
// Initialization
|
2012-12-18 00:51:25 +00:00
|
|
|
//=======================================================
|
|
|
|
|
|
2020-08-01 13:02:21 +10:00
|
|
|
void FRS_init()
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (freestyle_is_initialized) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
|
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();
|
2020-11-06 17:49:09 +01:00
|
|
|
g_freestyle.scene = nullptr;
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset_copied = false;
|
|
|
|
|
|
2019-09-05 15:52:38 +02:00
|
|
|
BKE_callback_add(&load_post_callback_funcstore, BKE_CB_EVT_LOAD_POST);
|
2013-03-23 21:38:35 +00:00
|
|
|
|
2020-11-06 14:25:30 +01:00
|
|
|
freestyle_is_initialized = true;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=======================================================
|
2018-06-17 17:05:14 +02:00
|
|
|
// Rendering
|
2012-12-18 00:51:25 +00:00
|
|
|
//=======================================================
|
|
|
|
|
|
|
|
|
|
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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
float thickness = 1.0f;
|
2022-11-01 21:00:56 +01:00
|
|
|
switch (re->scene->r.line_thickness_mode) {
|
2018-08-30 01:31:20 +10:00
|
|
|
case R_LINE_THICKNESS_ABSOLUTE:
|
2022-11-01 21:00:56 +01:00
|
|
|
thickness = re->scene->r.unit_line_thickness * (re->r.size / 100.0f);
|
2018-08-30 01:31:20 +10:00
|
|
|
break;
|
|
|
|
|
case R_LINE_THICKNESS_RELATIVE:
|
2020-11-06 11:25:27 +11:00
|
|
|
thickness = height / 480.0f;
|
2018-08-30 01:31:20 +10:00
|
|
|
break;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
view->setWidth(width);
|
|
|
|
|
view->setHeight(height);
|
|
|
|
|
view->setBorder(xmin, ymin, xmax, ymax);
|
|
|
|
|
view->setThickness(thickness);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (re->r.mode & R_BORDER) {
|
2013-01-03 23:27:20 +00:00
|
|
|
cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")"
|
|
|
|
|
<< endl;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*name == '\'') {
|
2012-12-18 00:51:25 +00:00
|
|
|
*(p++) = '\\';
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
*(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
|
2023-06-04 18:46:04 +10:00
|
|
|
static bool test_edge_type_conditions(edge_type_condition *conditions,
|
2012-12-18 00:51:25 +00:00
|
|
|
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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
for (int i = 0; i < num_edge_types; i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (conditions[i].edge_type == target) {
|
2012-12-18 00:51:25 +00:00
|
|
|
target_condition = conditions[i].value;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else if (conditions[i].value > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
++num_non_target_positive_conditions;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else if (conditions[i].value < 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
++num_non_target_negative_conditions;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (num_non_target_positive_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (target_condition > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (target_condition < 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (num_non_target_negative_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-10-27 20:57:14 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
else {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (target_condition > 0) {
|
2011-10-27 20:57:14 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (num_non_target_negative_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (target_condition < 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (num_non_target_positive_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// In this case, the 'target' edge type may appear together with other edge types.
|
2019-05-31 22:51:19 +10:00
|
|
|
if (target_condition > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (target_condition < 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
if (logical_and) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (num_non_target_positive_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (num_non_target_negative_conditions > 0) {
|
2011-10-27 20:57:14 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-10-27 20:57:14 +00:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
else {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (num_non_target_negative_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (num_non_target_positive_conditions > 0) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
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
|
|
|
|
2019-01-24 07:08:19 +01:00
|
|
|
static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph)
|
2012-12-18 00:51:25 +00:00
|
|
|
{
|
|
|
|
|
// load mesh
|
2024-01-11 19:49:03 +01:00
|
|
|
re->i.infostr = RPT_("Freestyle: Mesh loading");
|
2023-08-11 12:46:03 +02:00
|
|
|
re->stats_draw(&re->i);
|
2020-11-06 17:49:09 +01:00
|
|
|
re->i.infostr = nullptr;
|
2023-05-02 09:32:44 +10:00
|
|
|
if (controller->LoadMesh(re, view_layer, depsgraph)) {
|
|
|
|
|
/* Returns if scene cannot be loaded or if empty. */
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2023-08-11 12:30:57 +02:00
|
|
|
if (re->test_break()) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// add style modules
|
2017-11-22 10:52:39 -02:00
|
|
|
FreestyleConfig *config = &view_layer->freestyle_config;
|
2019-04-17 06:17:24 +02: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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
switch (config->mode) {
|
2018-08-30 01:31:20 +10:00
|
|
|
case FREESTYLE_CONTROL_SCRIPT_MODE:
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Modules :" << 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
|
|
|
}
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (FreestyleModuleConfig *, module_conf, &config->modules) {
|
2018-08-29 18:53:15 +02:00
|
|
|
if (module_conf->script && module_conf->is_displayed) {
|
|
|
|
|
const char *id_name = module_conf->script->id.name + 2;
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << " " << layer_count + 1 << ": " << id_name;
|
2020-06-23 09:54:14 +10:00
|
|
|
if (module_conf->script->filepath) {
|
|
|
|
|
cout << " (" << module_conf->script->filepath << ")";
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-08-29 18:53:15 +02:00
|
|
|
cout << endl;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
controller->InsertStyleModule(layer_count, id_name, module_conf->script);
|
|
|
|
|
controller->toggleLayer(layer_count, true);
|
|
|
|
|
layer_count++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
}
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
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;
|
2023-06-04 18:46:04 +10:00
|
|
|
edge_type_condition conditions[] = {
|
2018-08-30 01:31:20 +10:00
|
|
|
{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},
|
2019-02-03 14:01:45 +11:00
|
|
|
{FREESTYLE_FE_EDGE_MARK, 0},
|
2018-08-30 01:31:20 +10:00
|
|
|
};
|
2020-08-08 14:06:10 +10:00
|
|
|
int num_edge_types = ARRAY_SIZE(conditions);
|
2018-08-30 01:31:20 +10:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "Linesets:" << endl;
|
|
|
|
|
}
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (FreestyleLineSet *, lineset, &config->linesets) {
|
2018-08-30 01:31:20 +10:00
|
|
|
if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
|
|
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << " " << layer_count + 1 << ": " << lineset->name << " - "
|
2023-08-01 21:15:52 +10:00
|
|
|
<< (lineset->linestyle ? (lineset->linestyle->id.name + 2) : "<null>") << endl;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2018-08-29 18:53:15 +02:00
|
|
|
char *buffer = create_lineset_handler(view_layer->name, lineset->name);
|
2018-08-30 01:31:20 +10:00
|
|
|
controller->InsertStyleModule(layer_count, lineset->name, buffer);
|
|
|
|
|
controller->toggleLayer(layer_count, true);
|
|
|
|
|
MEM_freeN(buffer);
|
|
|
|
|
if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
|
2010-08-07 22:48:25 +00:00
|
|
|
++use_ridges_and_valleys;
|
|
|
|
|
++use_suggestive_contours;
|
|
|
|
|
++use_material_boundaries;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
else {
|
|
|
|
|
// conditions for feature edge selection by edge types
|
|
|
|
|
for (int i = 0; i < num_edge_types; i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!(lineset->edge_types & conditions[i].edge_type)) {
|
2018-08-30 01:31:20 +10:00
|
|
|
conditions[i].value = 0; // no condition specified
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else if (!(lineset->exclude_edge_types & conditions[i].edge_type)) {
|
2018-08-30 01:31:20 +10:00
|
|
|
conditions[i].value = 1; // condition: X
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2018-08-30 01:31:20 +10:00
|
|
|
conditions[i].value = -1; // condition: NOT X
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
}
|
|
|
|
|
// 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) {
|
2019-04-30 17:50:57 +10:00
|
|
|
// 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)
|
2019-05-31 22:51:19 +10:00
|
|
|
for (int i = 0; i < num_edge_types; i++) {
|
2018-08-30 01:31:20 +10:00
|
|
|
conditions[i].value *= -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
logical_and = !logical_and;
|
|
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(
|
|
|
|
|
conditions, num_edge_types, logical_and, FREESTYLE_FE_RIDGE_VALLEY, true))
|
|
|
|
|
{
|
|
|
|
|
++use_ridges_and_valleys;
|
|
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(conditions,
|
|
|
|
|
num_edge_types,
|
|
|
|
|
logical_and,
|
|
|
|
|
FREESTYLE_FE_SUGGESTIVE_CONTOUR,
|
|
|
|
|
true))
|
|
|
|
|
{
|
|
|
|
|
++use_suggestive_contours;
|
|
|
|
|
}
|
|
|
|
|
if (test_edge_type_conditions(
|
|
|
|
|
conditions, num_edge_types, logical_and, FREESTYLE_FE_MATERIAL_BOUNDARY, true))
|
|
|
|
|
{
|
|
|
|
|
++use_material_boundaries;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
layer_count++;
|
2010-07-26 01:23:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0);
|
|
|
|
|
controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0);
|
|
|
|
|
controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0);
|
|
|
|
|
break;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// set parameters
|
2021-09-13 10:29:24 -04:00
|
|
|
controller->setSphereRadius(config->sphere_radius);
|
|
|
|
|
controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon);
|
2012-12-18 00:51:25 +00:00
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (RenderPass *, rpass, &rl->passes) {
|
2023-07-10 16:33:32 +02:00
|
|
|
float *rpass_buffer_data = rpass->ibuf->float_buffer.data;
|
2018-12-21 23:26:04 +01:00
|
|
|
if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE_COLOR)) {
|
2023-05-23 09:19:37 +02:00
|
|
|
controller->setPassDiffuse(rpass_buffer_data, rpass->rectx, rpass->recty);
|
2012-12-18 00:51:25 +00:00
|
|
|
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)) {
|
2023-05-23 09:19:37 +02:00
|
|
|
controller->setPassZ(rpass_buffer_data, rpass->rectx, rpass->recty);
|
2012-12-18 00:51:25 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (controller->hitViewMapCache()) {
|
2014-01-28 23:24:59 +09:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// compute view map
|
2024-01-11 19:49:03 +01:00
|
|
|
re->i.infostr = RPT_("Freestyle: View map creation");
|
2023-08-11 12:46:03 +02:00
|
|
|
re->stats_draw(&re->i);
|
2020-11-06 17:49:09 +01:00
|
|
|
re->i.infostr = nullptr;
|
2012-12-18 00:51:25 +00:00
|
|
|
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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
if (freestyle_render == nullptr || freestyle_render->result == nullptr) {
|
2021-02-02 16:45:23 +01:00
|
|
|
if (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS) {
|
|
|
|
|
// Create a blank render pass output.
|
|
|
|
|
RE_create_render_pass(
|
2021-09-29 21:13:03 +02:00
|
|
|
re->result, RE_PASSNAME_FREESTYLE, 4, "RGBA", view_layer->name, re->viewname, true);
|
2021-02-02 16:45:23 +01:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-01 21:00:56 +01:00
|
|
|
rl = render_get_single_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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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;
|
|
|
|
|
}
|
2020-02-13 01:29:30 +01:00
|
|
|
|
|
|
|
|
if (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS) {
|
|
|
|
|
RE_create_render_pass(
|
2021-09-29 21:13:03 +02:00
|
|
|
re->result, RE_PASSNAME_FREESTYLE, 4, "RGBA", view_layer->name, re->viewname, true);
|
2020-02-13 01:29:30 +01:00
|
|
|
dest = RE_RenderLayerGetPass(rl, RE_PASSNAME_FREESTYLE, re->viewname);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
switch (view_layer->freestyle_config.mode) {
|
2018-08-30 01:31:20 +10:00
|
|
|
case FREESTYLE_CONTROL_SCRIPT_MODE:
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (FreestyleModuleConfig *, module, &view_layer->freestyle_config.modules) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (module->script && module->is_displayed) {
|
2018-08-30 01:31:20 +10:00
|
|
|
count++;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FREESTYLE_CONTROL_EDITOR_MODE:
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (FreestyleLineSet *, lineset, &view_layer->freestyle_config.linesets) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
|
2018-08-30 01:31:20 +10:00
|
|
|
count++;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
void FRS_begin_stroke_rendering(Render * /*re*/) {}
|
2015-05-16 23:55:45 +09:00
|
|
|
|
2020-03-26 01:14:08 +01:00
|
|
|
void FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer)
|
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);
|
2019-04-17 06:17:24 +02: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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-24 07:08:19 +01:00
|
|
|
/* Create depsgraph and evaluate scene. */
|
|
|
|
|
ViewLayer *scene_view_layer = (ViewLayer *)BLI_findstring(
|
|
|
|
|
&re->scene->view_layers, view_layer->name, offsetof(ViewLayer, name));
|
2019-09-09 14:49:05 +02:00
|
|
|
Depsgraph *depsgraph = DEG_graph_new(re->main, re->scene, scene_view_layer, DAG_EVAL_RENDER);
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-21 14:21:49 +01:00
|
|
|
/* Init camera
|
|
|
|
|
* Objects are transformed into camera coordinate system, therefore the camera position
|
|
|
|
|
* is zero and the modelview matrix is the identity matrix. */
|
|
|
|
|
Object *ob_camera_orig = RE_GetCamera(re);
|
|
|
|
|
Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, ob_camera_orig);
|
|
|
|
|
zero_v3(g_freestyle.viewpoint);
|
|
|
|
|
unit_m4(g_freestyle.mv);
|
|
|
|
|
RE_GetCameraWindow(re, ob_camera_eval, g_freestyle.proj);
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// prepare Freestyle:
|
|
|
|
|
// - load mesh
|
|
|
|
|
// - add style modules
|
|
|
|
|
// - set parameters
|
|
|
|
|
// - compute view map
|
2019-01-24 07:08:19 +01:00
|
|
|
prepare(re, view_layer, depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-11 12:30:57 +02:00
|
|
|
if (re->test_break()) {
|
2012-12-18 00:51:25 +00:00
|
|
|
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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
else {
|
|
|
|
|
// render and composite Freestyle result
|
|
|
|
|
if (controller->_ViewMap) {
|
|
|
|
|
// render strokes
|
2024-01-11 19:49:03 +01:00
|
|
|
re->i.infostr = RPT_("Freestyle: Stroke rendering");
|
2023-08-11 12:46:03 +02:00
|
|
|
re->stats_draw(&re->i);
|
2020-11-06 17:49:09 +01:00
|
|
|
re->i.infostr = nullptr;
|
2019-01-24 07:08:19 +01:00
|
|
|
g_freestyle.scene = DEG_get_evaluated_scene(depsgraph);
|
2016-05-05 23:09:22 +09:00
|
|
|
int strokeCount = controller->DrawStrokes();
|
2020-11-06 17:49:09 +01:00
|
|
|
Render *freestyle_render = nullptr;
|
2016-05-05 23:09:22 +09:00
|
|
|
if (strokeCount > 0) {
|
|
|
|
|
freestyle_render = controller->RenderStrokes(re, true);
|
|
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
controller->CloseFile();
|
2020-11-06 17:49:09 +01:00
|
|
|
g_freestyle.scene = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-19 16:21:17 +06:00
|
|
|
// composite result
|
2021-02-02 16:45:23 +01:00
|
|
|
FRS_composite_result(re, view_layer, freestyle_render);
|
2016-05-05 23:09:22 +09:00
|
|
|
if (freestyle_render) {
|
2020-03-26 01:14:08 +01:00
|
|
|
RE_FreeRender(freestyle_render);
|
2016-05-05 23:09:22 +09:00
|
|
|
}
|
2014-06-19 16:21:17 +06:00
|
|
|
}
|
2010-07-26 01:23:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-24 07:08:19 +01:00
|
|
|
DEG_graph_free(depsgraph);
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void FRS_free_view_map_cache()
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
2023-06-19 20:06:55 +10:00
|
|
|
STRNCPY(lineset_buffer.name, lineset->name);
|
2012-12-18 00:51:25 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!lineset_copied) {
|
2012-12-18 00:51:25 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-23 03:00:37 +00:00
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
if (lineset) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (lineset->linestyle) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&lineset->linestyle->id);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
lineset->linestyle = lineset_buffer.linestyle;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (lineset->linestyle) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&lineset->linestyle->id);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
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);
|
2020-11-06 17:49:09 +01:00
|
|
|
lineset->group = nullptr;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-06-19 20:06:55 +10:00
|
|
|
STRNCPY(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
|
|
|
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);
|
2020-11-06 17:49:09 +01:00
|
|
|
return (lineset != nullptr) && 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
|
|
|
|
|
|
2023-06-04 18:46:04 +10:00
|
|
|
Material *FRS_create_stroke_material(Main *bmain, FreestyleLineStyle *linestyle)
|
2014-06-28 19:18:47 +09:00
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
bNodeTree *nt = (linestyle->use_nodes) ? linestyle->nodetree : nullptr;
|
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
|
|
|
}
|