2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OSL_H__
|
|
|
|
#define __OSL_H__
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/array.h"
|
|
|
|
#include "util/set.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "util/thread.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "scene/shader.h"
|
|
|
|
#include "scene/shader_graph.h"
|
|
|
|
#include "scene/shader_nodes.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
2018-08-29 11:54:26 +00:00
|
|
|
# include <OSL/llvm_util.h>
|
2012-11-03 14:32:35 +00:00
|
|
|
# include <OSL/oslcomp.h>
|
2011-04-27 11:58:34 +00:00
|
|
|
# include <OSL/oslexec.h>
|
2012-11-03 14:32:35 +00:00
|
|
|
# include <OSL/oslquery.h>
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
class DeviceScene;
|
|
|
|
class ImageManager;
|
|
|
|
class OSLRenderServices;
|
2013-02-11 22:41:11 +00:00
|
|
|
struct OSLGlobals;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Scene;
|
|
|
|
class ShaderGraph;
|
|
|
|
class ShaderNode;
|
2012-09-15 16:31:07 +00:00
|
|
|
class ShaderInput;
|
2011-04-27 11:58:34 +00:00
|
|
|
class ShaderOutput;
|
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
|
2012-12-12 06:51:06 +00:00
|
|
|
/* OSL Shader Info
|
|
|
|
* to auto detect closures in the shader for MIS and transparent shadows */
|
|
|
|
|
|
|
|
struct OSLShaderInfo {
|
|
|
|
OSLShaderInfo()
|
2013-04-01 20:26:52 +00:00
|
|
|
: has_surface_emission(false), has_surface_transparent(false), has_surface_bssrdf(false)
|
2012-12-12 06:51:06 +00:00
|
|
|
{
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-05-29 13:10:34 +00:00
|
|
|
OSL::OSLQuery query;
|
2012-12-12 06:51:06 +00:00
|
|
|
bool has_surface_emission;
|
|
|
|
bool has_surface_transparent;
|
2013-04-01 20:26:52 +00:00
|
|
|
bool has_surface_bssrdf;
|
2012-12-12 06:51:06 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Shader Manage */
|
|
|
|
|
|
|
|
class OSLShaderManager : public ShaderManager {
|
|
|
|
public:
|
|
|
|
OSLShaderManager();
|
|
|
|
~OSLShaderManager();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-03-13 17:26:11 +00:00
|
|
|
static void free_memory();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2021-05-12 04:57:37 +00:00
|
|
|
void reset(Scene *scene) override;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2021-05-12 04:57:37 +00:00
|
|
|
bool use_osl() override
|
2012-12-04 07:48:09 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2021-05-02 00:34:56 +00:00
|
|
|
void device_update_specific(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress) override;
|
2021-05-12 04:57:37 +00:00
|
|
|
void device_free(Device *device, DeviceScene *dscene, Scene *scene) override;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* osl compile and query */
|
|
|
|
static bool osl_compile(const string &inputfile, const string &outputfile);
|
|
|
|
static bool osl_query(OSL::OSLQuery &query, const string &filepath);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* shader file loading, all functions return pointer to hash string if found */
|
|
|
|
const char *shader_test_loaded(const string &hash);
|
|
|
|
const char *shader_load_bytecode(const string &hash, const string &bytecode);
|
|
|
|
const char *shader_load_filepath(string filepath);
|
2012-12-12 06:51:06 +00:00
|
|
|
OSLShaderInfo *shader_loaded_info(const string &hash);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-05-29 13:10:34 +00:00
|
|
|
/* create OSL node using OSLQuery */
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 21:20:51 +00:00
|
|
|
static OSLNode *osl_node(ShaderGraph *graph,
|
|
|
|
ShaderManager *manager,
|
2020-03-11 15:51:42 +00:00
|
|
|
const std::string &filepath,
|
|
|
|
const std::string &bytecode_hash = "",
|
|
|
|
const std::string &bytecode = "");
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
protected:
|
|
|
|
void texture_system_init();
|
2013-04-22 14:27:12 +00:00
|
|
|
void texture_system_free();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
void shading_system_init();
|
2013-04-22 14:27:12 +00:00
|
|
|
void shading_system_free();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
OSL::ShadingSystem *ss;
|
|
|
|
OSL::TextureSystem *ts;
|
|
|
|
OSLRenderServices *services;
|
|
|
|
OSL::ErrorHandler errhandler;
|
2012-12-12 06:51:06 +00:00
|
|
|
map<string, OSLShaderInfo> loaded_shaders;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-04-04 23:48:07 +00:00
|
|
|
static OSL::TextureSystem *ts_shared;
|
|
|
|
static thread_mutex ts_shared_mutex;
|
|
|
|
static int ts_shared_users;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-04-22 14:27:12 +00:00
|
|
|
static OSL::ShadingSystem *ss_shared;
|
|
|
|
static OSLRenderServices *services_shared;
|
|
|
|
static thread_mutex ss_shared_mutex;
|
|
|
|
static thread_mutex ss_mutex;
|
|
|
|
static int ss_shared_users;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Graph Compiler */
|
|
|
|
|
|
|
|
class OSLCompiler {
|
|
|
|
public:
|
2019-05-14 10:13:43 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
OSLCompiler(OSLShaderManager *manager,
|
|
|
|
OSLRenderServices *services,
|
|
|
|
OSL::ShadingSystem *shadingsys,
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 15:06:08 +00:00
|
|
|
Scene *scene);
|
2019-05-14 10:13:43 +00:00
|
|
|
#endif
|
2021-10-21 12:52:34 +00:00
|
|
|
void compile(OSLGlobals *og, Shader *shader);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
void add(ShaderNode *node, const char *name, bool isfilepath = false);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-05-07 17:48:28 +00:00
|
|
|
void parameter(ShaderNode *node, const char *name);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void parameter(const char *name, float f);
|
|
|
|
void parameter_color(const char *name, float3 f);
|
|
|
|
void parameter_vector(const char *name, float3 f);
|
|
|
|
void parameter_normal(const char *name, float3 f);
|
|
|
|
void parameter_point(const char *name, float3 f);
|
|
|
|
void parameter(const char *name, int f);
|
|
|
|
void parameter(const char *name, const char *s);
|
|
|
|
void parameter(const char *name, ustring str);
|
|
|
|
void parameter(const char *name, const Transform &tfm);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-09-15 15:41:37 +00:00
|
|
|
void parameter_array(const char *name, const float f[], int arraylen);
|
2016-05-07 23:54:35 +00:00
|
|
|
void parameter_color_array(const char *name, const array<float3> &f);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-02-18 02:20:39 +00:00
|
|
|
void parameter_attribute(const char *name, ustring s);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-05-02 13:45:31 +00:00
|
|
|
void parameter_texture(const char *name, ustring filename, ustring colorspace);
|
|
|
|
void parameter_texture(const char *name, int svm_slot);
|
2019-05-02 10:40:24 +00:00
|
|
|
void parameter_texture_ies(const char *name, int svm_slot);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
ShaderType output_type()
|
|
|
|
{
|
|
|
|
return current_type;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool background;
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 15:06:08 +00:00
|
|
|
Scene *scene;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
private:
|
2013-12-09 04:28:01 +00:00
|
|
|
#ifdef WITH_OSL
|
2011-04-27 11:58:34 +00:00
|
|
|
string id(ShaderNode *node);
|
2016-01-07 08:15:30 +00:00
|
|
|
OSL::ShaderGroupRef compile_type(Shader *shader, ShaderGraph *graph, ShaderType type);
|
2011-04-27 11:58:34 +00:00
|
|
|
bool node_skip_input(ShaderNode *node, ShaderInput *input);
|
2012-09-15 16:31:07 +00:00
|
|
|
string compatible_name(ShaderNode *node, ShaderInput *input);
|
|
|
|
string compatible_name(ShaderNode *node, ShaderOutput *output);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-11-25 08:07:29 +00:00
|
|
|
void find_dependencies(ShaderNodeSet &dependencies, ShaderInput *input);
|
|
|
|
void generate_nodes(const ShaderNodeSet &nodes);
|
2019-05-14 10:13:43 +00:00
|
|
|
|
|
|
|
OSLShaderManager *manager;
|
|
|
|
OSLRenderServices *services;
|
|
|
|
OSL::ShadingSystem *ss;
|
2013-12-09 04:28:01 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
ShaderType current_type;
|
|
|
|
Shader *current_shader;
|
2019-05-14 10:13:43 +00:00
|
|
|
|
|
|
|
static int texture_shared_unique_id;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
2021-06-24 05:56:58 +00:00
|
|
|
#endif /* __OSL_H__ */
|