Files
test/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp

754 lines
22 KiB
C++
Raw Normal View History

/*
* ***** 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
*/
#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>
#include "../application/AppCanvas.h"
#include "../application/AppConfig.h"
#include "../application/AppView.h"
#include "../application/Controller.h"
#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;
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
using namespace Freestyle;
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"
#include "DNA_camera_types.h"
#include "DNA_freestyle_types.h"
#include "DNA_group_types.h"
#include "DNA_material_types.h"
#include "DNA_text_types.h"
#include "BKE_freestyle.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_linestyle.h"
#include "BKE_main.h"
#include "BKE_text.h"
2013-05-01 00:26:47 +00:00
#include "BKE_context.h"
#include "BLT_translation.h"
#include "BLI_blenlib.h"
#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"
#include "BLI_callbacks.h"
#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"
#include "FRS_freestyle.h"
#define DEFAULT_SPHERE_RADIUS 1.0f
#define DEFAULT_DKR_EPSILON 0.0f
struct FreestyleGlobals g_freestyle;
// Freestyle configuration
static bool freestyle_is_initialized = false;
static Config::Path *pathconfig = NULL;
static Controller *controller = NULL;
static AppView *view = NULL;
// line set buffer for copy & paste
static FreestyleLineSet lineset_buffer;
static bool lineset_copied = false;
static void load_post_callback(struct Main * /*main*/, struct ID * /*id*/, void * /*arg*/)
{
lineset_copied = false;
}
static bCallbackFuncStore load_post_callback_funcstore = {
NULL, NULL, /* next, prev */
load_post_callback, /* func */
NULL, /* arg */
0 /* alloc */
};
//=======================================================
// Initialization
//=======================================================
void FRS_initialize()
{
if (freestyle_is_initialized)
return;
pathconfig = new Config::Path;
controller = new Controller();
view = new AppView;
controller->setView(view);
controller->Clear();
g_freestyle.scene = NULL;
lineset_copied = false;
BLI_callback_add(&load_post_callback_funcstore, BLI_CB_EVT_LOAD_POST);
freestyle_is_initialized = 1;
}
void FRS_set_context(bContext *C)
{
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
}
controller->setContext(C);
}
void FRS_exit()
{
delete pathconfig;
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;
}
g_freestyle.viewport[0] = g_freestyle.viewport[1] = 0;
g_freestyle.viewport[2] = width;
g_freestyle.viewport[3] = height;
view->setWidth(width);
view->setHeight(height);
view->setBorder(xmin, ymin, xmax, ymax);
view->setThickness(thickness);
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;
}
}
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.
zero_v3(g_freestyle.viewpoint);
unit_m4(g_freestyle.mv);
copy_m4_m4(g_freestyle.proj, re->winmat);
2008-08-08 08:53:13 +00:00
#if 0
print_m4("mv", g_freestyle.mv);
print_m4("proj", g_freestyle.proj);
#endif
}
static char *escape_quotes(char *name)
{
char *s = (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
char *p = s;
while (*name) {
if (*name == '\'')
*(p++) = '\\';
*(p++) = *(name++);
}
*p = '\0';
return s;
}
static char * create_lineset_handler(char *layer_name, char *lineset_name)
{
const char *fmt = "__import__('parameter_editor').process('%s', '%s')\n";
char *s1 = escape_quotes(layer_name);
char *s2 = escape_quotes(lineset_name);
char *text = BLI_sprintfN(fmt, s1, s2);
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;
}
else {
if (target_condition > 0)
return true;
if (num_non_target_negative_conditions > 0)
return true;
if (target_condition < 0)
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)
return true;
}
else {
if (num_non_target_negative_conditions > 0)
return true;
if (num_non_target_positive_conditions > 0)
return false;
}
}
return true;
}
static void prepare(Render *re, ViewLayer *view_layer)
{
// load mesh
re->i.infostr = IFACE_("Freestyle: Mesh loading");
re->stats_draw(re->sdh, &re->i);
re->i.infostr = NULL;
if (controller->LoadMesh(re, view_layer)) // returns if scene cannot be loaded or if empty
return;
if (re->test_break(re->tbh))
return;
// add style modules
FreestyleConfig *config = &view_layer->freestyle_config;
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "\n=== Rendering options ===" << endl;
}
int layer_count = 0;
switch (config->mode) {
case FREESTYLE_CONTROL_SCRIPT_MODE:
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "Modules :" << endl;
}
for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig *)config->modules.first;
module_conf;
module_conf = module_conf->next)
{
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;
if (module_conf->script->name)
cout << " (" << module_conf->script->name << ")";
cout << endl;
}
controller->InsertStyleModule(layer_count, id_name, module_conf->script);
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
}
}
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;
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);
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "Linesets:" << endl;
}
for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first;
lineset;
lineset = lineset->next)
{
if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << " " << layer_count+1 << ": " << lineset->name << " - " <<
(lineset->linestyle ? (lineset->linestyle->id.name + 2) : "<NULL>") << endl;
}
char *buffer = create_lineset_handler(view_layer->name, lineset->name);
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) {
++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))
{
++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;
}
}
layer_count++;
}
}
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);
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;
cout << "Ridges and valleys : " <<
(controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
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;
cout << endl;
}
// set diffuse and z depth passes
RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name);
bool diffuse = false, z = false;
for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
diffuse = true;
}
if (STREQ(rpass->name, RE_PASSNAME_Z)) {
controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
z = true;
}
}
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "Passes :" << endl;
cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
cout << " Z = " << (z ? "enabled" : "disabled") << endl;
}
if (controller->hitViewMapCache())
return;
// compute view map
re->i.infostr = IFACE_("Freestyle: View map creation");
re->stats_draw(re->sdh, &re->i);
re->i.infostr = NULL;
controller->ComputeViewMap();
}
void FRS_composite_result(Render *re, ViewLayer *view_layer, Render *freestyle_render)
{
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 );
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (!rl) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "No source render layer to composite" << endl;
}
return;
}
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
src = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, freestyle_render->viewname);
if (!src) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "No source result image to composite" << endl;
}
return;
}
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "src: " << rl->rectx << " x " << rl->recty << endl;
}
#endif
rl = RE_GetRenderLayer(re->result, view_layer->name);
if (!rl) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "No destination render layer to composite to" << endl;
}
return;
}
dest = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, re->viewname);
if (!dest) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "No destination result image to composite to" << endl;
}
return;
}
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
}
#endif
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);
}
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
}
}
}
static int displayed_layer_count(ViewLayer *view_layer)
{
int count = 0;
switch (view_layer->freestyle_config.mode) {
case FREESTYLE_CONTROL_SCRIPT_MODE:
for (FreestyleModuleConfig *module = (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first;
module;
module = module->next)
{
if (module->script && module->is_displayed)
count++;
}
break;
case FREESTYLE_CONTROL_EDITOR_MODE:
for (FreestyleLineSet *lineset = (FreestyleLineSet *)view_layer->freestyle_config.linesets.first;
lineset;
lineset = lineset->next)
{
if (lineset->flags & FREESTYLE_LINESET_ENABLED)
count++;
}
break;
}
return count;
}
int FRS_is_freestyle_enabled(ViewLayer *view_layer)
{
return ((view_layer->flag & VIEW_LAYER_RENDER) &&
(view_layer->flag & VIEW_LAYER_FREESTYLE) &&
displayed_layer_count(view_layer) > 0);
}
void FRS_init_stroke_renderer(Render *re)
{
if (G.debug & G_DEBUG_FREESTYLE) {
cout << endl;
cout << "#===============================================================" << endl;
cout << "# Freestyle" << endl;
cout << "#===============================================================" << endl;
}
init_view(re);
controller->ResetRenderCount();
}
void FRS_begin_stroke_rendering(Render *re)
{
init_camera(re);
}
Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render)
{
Render *freestyle_render = NULL;
if (!render)
return controller->RenderStrokes(re, false);
RenderMonitor monitor(re);
controller->setRenderMonitor(&monitor);
controller->setViewMapCache((view_layer->freestyle_config.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false);
if (G.debug & G_DEBUG_FREESTYLE) {
cout << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| " << (re->scene->id.name + 2) << "|" << view_layer->name << endl;
cout << "----------------------------------------------------------" << endl;
}
// prepare Freestyle:
// - load mesh
// - add style modules
// - set parameters
// - compute view map
prepare(re, view_layer);
if (re->test_break(re->tbh)) {
controller->CloseFile();
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
}
else {
// render and composite Freestyle result
if (controller->_ViewMap) {
// render strokes
re->i.infostr = IFACE_("Freestyle: Stroke rendering");
re->stats_draw(re->sdh, &re->i);
re->i.infostr = NULL;
g_freestyle.scene = re->scene;
int strokeCount = controller->DrawStrokes();
if (strokeCount > 0) {
freestyle_render = controller->RenderStrokes(re, true);
}
controller->CloseFile();
g_freestyle.scene = NULL;
// composite result
if (freestyle_render) {
FRS_composite_result(re, view_layer, freestyle_render);
RE_FreeRenderResult(freestyle_render->result);
freestyle_render->result = NULL;
}
}
}
return freestyle_render;
}
void FRS_end_stroke_rendering(Render * /*re*/)
{
// 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
void FRS_free_view_map_cache(void)
{
// free cache
controller->DeleteViewMap(true);
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
printf("View map cache freed\n");
}
#endif
}
//=======================================================
// Freestyle Panel Configuration
//=======================================================
void FRS_copy_active_lineset(FreestyleConfig *config)
{
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
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;
}
}
void FRS_paste_active_lineset(FreestyleConfig *config)
{
if (!lineset_copied)
return;
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
if (lineset) {
if (lineset->linestyle)
id_us_min(&lineset->linestyle->id);
lineset->linestyle = lineset_buffer.linestyle;
if (lineset->linestyle)
id_us_plus(&lineset->linestyle->id);
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) {
id_us_min(&lineset->group->id);
lineset->group = NULL;
}
if (lineset_buffer.group) {
lineset->group = lineset_buffer.group;
id_us_plus(&lineset->group->id);
}
strcpy(lineset->name, lineset_buffer.name);
BKE_freestyle_lineset_unique_name(config, lineset);
lineset->flags |= FREESTYLE_LINESET_CURRENT;
}
}
void FRS_delete_active_lineset(FreestyleConfig *config)
{
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
if (lineset) {
BKE_freestyle_lineset_delete(config, lineset);
}
}
/**
* 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)
{
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
return (lineset != NULL) && BLI_listbase_link_move(&config->linesets, lineset, direction);
}
// Testing
Material *FRS_create_stroke_material(Main *bmain, struct FreestyleLineStyle *linestyle)
{
bNodeTree *nt = (linestyle->use_nodes) ? linestyle->nodetree : NULL;
Material *ma = BlenderStrokeRenderer::GetStrokeShader(bmain, nt, true);
ma->id.us = 0;
return ma;
}
} // extern "C"