2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2007-03-24 06:57:29 +00:00
|
|
|
* 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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2007-03-24 06:57:29 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-03-24 06:57:29 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup nodes
|
2011-02-27 20:13:22 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include <cfloat>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstring>
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2021-12-07 13:26:39 +01:00
|
|
|
#include "BLI_blenlib.h"
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "BLI_color.hh"
|
2021-12-07 13:26:39 +01:00
|
|
|
#include "BLI_math.h"
|
2020-07-16 13:41:47 +02:00
|
|
|
#include "BLI_math_base_safe.h"
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:57:07 +01:00
|
|
|
#include "BLI_math_vec_types.hh"
|
2013-01-24 21:57:13 +00:00
|
|
|
#include "BLI_rand.h"
|
|
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2017-12-07 15:36:26 +11:00
|
|
|
#include "BKE_colorband.h"
|
2007-03-24 06:57:29 +00:00
|
|
|
#include "BKE_colortools.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_material.h"
|
2011-02-07 09:33:36 +00:00
|
|
|
#include "BKE_node.h"
|
2007-03-24 06:57:29 +00:00
|
|
|
#include "BKE_texture.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
#include "DNA_color_types.h"
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_texture_types.h"
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "FN_multi_function_builder.hh"
|
2007-03-24 06:57:29 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "GPU_material.h"
|
2019-04-23 13:56:30 +02:00
|
|
|
#include "GPU_texture.h"
|
2020-08-20 23:09:37 +02:00
|
|
|
#include "GPU_uniform_buffer.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "IMB_colormanagement.h"
|
2021-12-07 13:26:39 +01:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "MEM_guardedalloc.h"
|
2021-12-07 13:26:39 +01:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "NOD_multi_function.hh"
|
|
|
|
|
#include "NOD_shader.h"
|
|
|
|
|
#include "NOD_socket_declarations.hh"
|
|
|
|
|
#include "node_util.h"
|
2021-12-07 13:26:39 +01:00
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
#include "RE_texture.h"
|
2021-12-07 13:26:39 +01:00
|
|
|
|
2021-04-12 18:43:23 +02:00
|
|
|
bool sh_node_poll_default(struct bNodeType *ntype,
|
|
|
|
|
struct bNodeTree *ntree,
|
|
|
|
|
const char **r_disabled_hint);
|
2022-01-03 19:32:33 -05:00
|
|
|
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
|
|
|
|
|
void sh_fn_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
/* ********* exec data struct, remains internal *********** */
|
|
|
|
|
|
2022-01-04 23:25:16 -05:00
|
|
|
struct XYZ_to_RGB /* Transposed #imbuf_xyz_to_rgb, passed as 3x vec3. */
|
2021-05-21 10:25:47 +05:30
|
|
|
{
|
|
|
|
|
float r[3], g[3], b[3];
|
2022-01-04 23:25:16 -05:00
|
|
|
};
|
2021-05-21 10:25:47 +05:30
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, struct bNodeStack *ns);
|
|
|
|
|
void node_data_from_gpu_stack(struct bNodeStack *ns, struct GPUNodeStack *gs);
|
2019-08-19 20:33:17 +02:00
|
|
|
void node_shader_gpu_bump_tex_coord(struct GPUMaterial *mat,
|
|
|
|
|
struct bNode *node,
|
|
|
|
|
struct GPUNodeLink **link);
|
|
|
|
|
void node_shader_gpu_default_tex_coord(struct GPUMaterial *mat,
|
|
|
|
|
struct bNode *node,
|
|
|
|
|
struct GPUNodeLink **link);
|
2011-11-08 11:38:16 +00:00
|
|
|
void node_shader_gpu_tex_mapping(struct GPUMaterial *mat,
|
|
|
|
|
struct bNode *node,
|
|
|
|
|
struct GPUNodeStack *in,
|
|
|
|
|
struct GPUNodeStack *out);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-26 15:28:05 -05:00
|
|
|
struct bNodeTreeExec *ntreeShaderBeginExecTree_internal(struct bNodeExecContext *context,
|
|
|
|
|
struct bNodeTree *ntree,
|
|
|
|
|
bNodeInstanceKey parent_key);
|
|
|
|
|
void ntreeShaderEndExecTree_internal(struct bNodeTreeExec *exec);
|
|
|
|
|
|
2019-04-02 16:37:54 +02:00
|
|
|
void ntreeExecGPUNodes(struct bNodeTreeExec *exec,
|
|
|
|
|
struct GPUMaterial *mat,
|
|
|
|
|
struct bNode *output_node);
|
2021-05-21 10:25:47 +05:30
|
|
|
void get_XYZ_to_RGB_for_gpu(XYZ_to_RGB *data);
|