28# include <OpenColorIO/OpenColorIO.h>
29namespace OCIO = OCIO_NAMESPACE;
32#include "scene/shader.tables"
44 static NodeEnum emission_sampling_method_enum;
51 "Emission Sampling Method",
52 emission_sampling_method_enum,
55 SOCKET_BOOLEAN(use_transparent_shadow,
"Use Transparent Shadow",
true);
56 SOCKET_BOOLEAN(use_bump_map_correction,
"Bump Map Correction",
true);
58 static NodeEnum volume_sampling_method_enum;
63 "Volume Sampling Method",
64 volume_sampling_method_enum,
67 static NodeEnum volume_interpolation_method_enum;
71 "Volume Interpolation Method",
72 volume_interpolation_method_enum,
75 SOCKET_FLOAT(volume_step_rate,
"Volume Step Rate", 1.0f);
77 static NodeEnum displacement_method_enum;
129 if (node ==
nullptr) {
132 if (node->
type == EmissionNode::get_node_type() ||
133 node->
type == BackgroundNode::get_node_type() ||
134 node->
type == PrincipledBsdfNode::get_node_type())
136 const bool is_principled = (node->
type == PrincipledBsdfNode::get_node_type());
138 ShaderInput *color_in = node->
input(is_principled ?
"Emission Color" :
"Color");
139 ShaderInput *strength_in = node->
input(is_principled ?
"Emission Strength" :
"Strength");
148 if (color_in->
link) {
155 if (strength_in->
link) {
165 if (node->
type == LightFalloffNode::get_node_type() ||
166 node->
type == IESLightNode::get_node_type())
175 if (node->
type == AddClosureNode::get_node_type()) {
180 const float3 estimate1 = (closure1_in->
link) ?
183 const float3 estimate2 = (closure2_in->
link) ?
187 return estimate1 + estimate2;
189 if (node->
type == MixClosureNode::get_node_type()) {
195 const float3 estimate1 = (closure1_in->
link) ?
198 const float3 estimate2 = (closure2_in->
link) ?
204 return estimate1 + estimate2;
208 return (1.0f - fac) * estimate1 + fac * estimate2;
266 if (
output &&
output->parent->type == EmissionNode::get_node_type()) {
288 graph_->remove_proxy_nodes();
291 graph_->compute_displacement_hash();
297 const char *old_hash = (
graph) ?
graph->displacement_hash.c_str() :
"";
298 const char *new_hash = (graph_) ? graph_->displacement_hash.c_str() :
"";
300 if (strcmp(old_hash, new_hash) != 0) {
306 graph = std::move(graph_);
315 if (!use_transparent_shadow) {
399 if (displacement_method_is_modified()) {
465 manager = make_unique<OSLShaderManager>();
470 manager = make_unique<SVMShaderManager>();
537 bool has_volumes =
false;
543 output->input(
"Surface")->link &&
output->input(
"Displacement")->link;
546 shader->
graph->finalize(
575 KernelIntegrator *kintegrator = &dscene->
data.integrator;
576 if (
bool(kintegrator->use_volumes) != has_volumes) {
578 kintegrator->use_volumes = has_volumes;
606 bool has_transparent_shadow =
false;
665 if (shader->get_use_bump_map_correction()) {
679 shader->
name.c_str(), shader->
name.length(), 0);
683 kshader->
pass_id = shader->get_pass_id();
711 KernelIntegrator *kintegrator = &dscene->
data.integrator;
713 kintegrator->transparent_shadows = has_transparent_shadow;
716 KernelFilm *kfilm = &dscene->
data.film;
748 graph->connect(bsdf->
output(
"BSDF"), graph->output()->input(
"Surface"));
751 shader->
name =
"default_surface";
764 graph->connect(principled->
output(
"Volume"), graph->output()->input(
"Volume"));
767 shader->
name =
"default_volume";
780 emission->set_color(
make_float3(0.8f, 0.8f, 0.8f));
781 emission->set_strength(0.0f);
783 graph->connect(emission->
output(
"Emission"), graph->output()->input(
"Surface"));
786 shader->
name =
"default_light";
798 shader->
name =
"default_background";
810 shader->
name =
"default_empty";
820 uint kernel_features = 0;
838 return kernel_features;
853 if (output_node->
input(
"Displacement")->
link !=
nullptr) {
870 return kernel_features;
885 string manifest =
"{";
886 unordered_set<ustring> materials;
888 if (materials.count(shader->
name)) {
891 materials.insert(shader->
name);
893 shader->
name.c_str(), shader->
name.length(), 0);
894 manifest +=
string_printf(
"\"%s\":\"%08x\",", shader->
name.c_str(), cryptomatte_id);
896 manifest[manifest.size() - 1] =
'}';
912static bool to_scene_linear_transform(OCIO::ConstConfigRcPtr &config,
913 const char *colorspace,
916 OCIO::ConstProcessorRcPtr processor;
918 processor = config->getProcessor(
"scene_linear", colorspace);
920 catch (OCIO::Exception &) {
928 const OCIO::ConstCPUProcessorRcPtr device_processor = processor->getDefaultCPUProcessor();
929 if (!device_processor) {
979 const float *table_row = table_thin_film_cmf[
i];
992 normalization = 1.0f / rgbReal;
1037 OCIO::ConstConfigRcPtr config =
nullptr;
1039 config = OCIO::GetCurrentConfig();
1041 catch (OCIO::Exception &exception) {
1042 LOG_WARNING <<
"OCIO config error: " << exception.what();
1046 if (!(config && config->hasRole(
"scene_linear"))) {
1052 if (config->hasRole(
"aces_interchange")) {
1055 if (!to_scene_linear_transform(config,
"aces_interchange", aces_to_rgb)) {
1076 else if (config->hasRole(
"XYZ")) {
1078 if (!to_scene_linear_transform(config,
"XYZ",
xyz_to_rgb)) {
unsigned long long int uint64_t
Shader * get_shader(const Scene *scene)
ClosureType get_closure_type() override
device_vector< KernelShader > shaders
device_vector< int4 > svm_nodes
bool from_auto_conversion
@ SHADER_DISPLACEMENT_MODIFIED
@ SHADER_ATTRIBUTE_MODIFIED
unique_ptr_vector< ShaderNode > nodes
string get_cryptomatte_materials(Scene *scene)
size_t thin_film_table_offset_
float3 rec709_to_scene_linear(const float3 c)
static unique_ptr< ShaderManager > create(const int shadingsystem)
void device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
SceneLinearSpace scene_linear_space
size_t ensure_bsdf_table_impl(DeviceScene *dscene, Scene *scene, const float *table, const size_t n)
void device_update_pre(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
AttributeIDMap unique_attribute_id
float linear_rgb_to_gray(const float3 c)
virtual uint64_t get_attribute_id(ustring name)
void init_xyz_transforms()
virtual void device_update_specific(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)=0
thread_spin_lock attribute_lock_
void compute_thin_film_table(const Transform &xyz_to_rgb)
int get_shader_id(Shader *shader, bool smooth=false)
unordered_map< const float *, size_t > bsdf_tables
void device_update_post(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void tag_update(Scene *scene, const uint32_t flag)
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
static thread_mutex lookup_table_mutex
uint get_kernel_features(Scene *scene)
size_t ensure_bsdf_table(DeviceScene *dscene, Scene *scene, const float(&table)[n])
static void add_default(Scene *scene)
uint get_graph_kernel_features(ShaderGraph *graph)
vector< float > thin_film_table
ShaderInput * input(const char *name)
virtual bool has_surface_transparent()
virtual bool has_surface_emission()
virtual uint get_feature()
ShaderNodeSpecialType special_type
unique_ptr_vector< ShaderInput > inputs
ShaderOutput * output(const char *name)
virtual bool has_surface_bssrdf()
virtual void attributes(Shader *shader, AttributeRequestSet *attributes)
bool has_surface_spatial_varying
bool need_update_attribute
bool has_volume_attribute_dependency
bool need_update_geometry() const
void set_graph(unique_ptr< ShaderGraph > &&graph)
bool emission_is_constant
float prev_volume_step_rate
bool need_update_displacement
EmissionSampling emission_sampling
bool shadow_transparency_needs_realloc
bool has_surface_raytrace
AttributeRequestSet attributes
bool has_surface_transparent
void tag_update(Scene *scene)
NODE_DECLARE unique_ptr< ShaderGraph > graph
bool prev_has_surface_shadow_transparency
bool has_surface_shadow_transparency() const
bool has_volume_connected
void tag_used(Scene *scene)
bool has_volume_spatial_varying
void copy_to_device_if_modified()
T * alloc(const size_t width, const size_t height=0)
reduce_max(value.rgb)") DEFINE_VALUE("REDUCE(lhs
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
ccl_device_inline float2 to_local(const T p, const T X, const T Y)
#define KERNEL_FEATURE_VOLUME
#define CLOSURE_IS_VOLUME(type)
#define KERNEL_FEATURE_NODE_BUMP_STATE
#define KERNEL_FEATURE_TRANSPARENT
#define KERNEL_FEATURE_OSL_SHADING
#define KERNEL_FEATURE_SUBSURFACE
#define KERNEL_FEATURE_NODE_BSDF
#define THIN_FILM_TABLE_SIZE
#define KERNEL_FEATURE_NODE_VOLUME
#define KERNEL_FEATURE_NODE_EMISSION
#define KERNEL_FEATURE_NODE_BUMP
#define CCL_NAMESPACE_END
#define assert(assertion)
@ SD_HAS_TRANSPARENT_SHADOW
@ SD_HAS_CONSTANT_EMISSION
@ SD_NEED_VOLUME_ATTRIBUTES
@ SD_USE_BUMP_MAP_CORRECTION
@ SD_HETEROGENEOUS_VOLUME
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_NORMAL_UNDISPLACED
@ EMISSION_SAMPLING_FRONT_BACK
@ EMISSION_SAMPLING_FRONT
ccl_device float3 rec709_to_rgb(KernelGlobals kg, const float3 rec709)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float3 one_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
uint32_t util_murmur_hash3(const void *key, const int len, const uint32_t seed)
float util_hash_to_float(const uint32_t hash)
BLI_INLINE ColorSceneLinear4f< eAlpha::Straight > to_scene_linear(const ColorTheme4f &theme4f)
color xyz_to_rgb(float x, float y, float z)
#define SOCKET_FLOAT(name, ui_name, default_value,...)
#define SOCKET_INT(name, ui_name, default_value,...)
#define NODE_DEFINE(structname)
#define SOCKET_BOOLEAN(name, ui_name, default_value,...)
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant)
@ VOLUME_INTERPOLATION_LINEAR
@ VOLUME_INTERPOLATION_CUBIC
@ VOLUME_SAMPLING_DISTANCE
@ VOLUME_SAMPLING_EQUIANGULAR
@ VOLUME_SAMPLING_MULTIPLE_IMPORTANCE
@ SHADER_SPECIAL_TYPE_LIGHT_PATH
@ SHADER_SPECIAL_TYPE_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_CLOSURE
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
float constant_emission[3]
int ggx_gen_schlick_ior_s
void insert(const char *x, const int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=nullptr)
float get_float(const SocketType &input) const
float3 get_float3(const SocketType &input) const
int reference_count() const
Node(const NodeType *type, ustring name=ustring())
unique_ptr< ObjectManager > object_manager
unique_ptr< LightManager > light_manager
Shader * default_background
T * create_node(Args &&...)=delete
void tag_has_volume_modified()
unique_ptr_vector< Shader > shaders
unique_ptr< ShaderManager > shader_manager
unique_ptr< GeometryManager > geometry_manager
unique_ptr< ProceduralManager > procedural_manager
unique_ptr< VolumeManager > volume_manager
unique_ptr< LookupTables > lookup_tables