29# include <OpenColorIO/OpenColorIO.h>
30namespace OCIO = OCIO_NAMESPACE;
33#include "scene/shader.tables"
45 static NodeEnum emission_sampling_method_enum;
52 "Emission Sampling Method",
53 emission_sampling_method_enum,
56 SOCKET_BOOLEAN(use_transparent_shadow,
"Use Transparent Shadow",
true);
57 SOCKET_BOOLEAN(use_bump_map_correction,
"Bump Map Correction",
true);
58 SOCKET_BOOLEAN(heterogeneous_volume,
"Heterogeneous Volume",
true);
60 static NodeEnum volume_sampling_method_enum;
65 "Volume Sampling Method",
66 volume_sampling_method_enum,
69 static NodeEnum volume_interpolation_method_enum;
73 "Volume Interpolation Method",
74 volume_interpolation_method_enum,
77 SOCKET_FLOAT(volume_step_rate,
"Volume Step Rate", 1.0f);
79 static NodeEnum displacement_method_enum;
133 if (node ==
nullptr) {
136 else if (node->
type == EmissionNode::get_node_type() ||
137 node->
type == BackgroundNode::get_node_type() ||
138 node->
type == PrincipledBsdfNode::get_node_type())
140 const bool is_principled = (node->
type == PrincipledBsdfNode::get_node_type());
142 ShaderInput *color_in = node->
input(is_principled ?
"Emission Color" :
"Color");
143 ShaderInput *strength_in = node->
input(is_principled ?
"Emission Strength" :
"Strength");
152 if (color_in->
link) {
159 if (strength_in->
link) {
170 if (node->
type == EmissionNode::get_node_type()) {
179 else if (node->
type == LightFalloffNode::get_node_type() ||
180 node->
type == IESLightNode::get_node_type())
189 else if (node->
type == AddClosureNode::get_node_type()) {
194 const float3 estimate1 = (closure1_in->
link) ?
197 const float3 estimate2 = (closure2_in->
link) ?
201 return estimate1 + estimate2;
203 else if (node->
type == MixClosureNode::get_node_type()) {
209 const float3 estimate1 = (closure1_in->
link) ?
212 const float3 estimate2 = (closure2_in->
link) ?
218 return estimate1 + estimate2;
222 return (1.0f - fac) * estimate1 + fac * estimate2;
301 const char *old_hash = (
graph) ?
graph->displacement_hash.c_str() :
"";
304 if (strcmp(old_hash, new_hash) != 0) {
360 graph->add(transparent);
389 if (displacement_method_is_modified()) {
447 manager =
new OSLShaderManager(device);
526 if (scene->
shaders.size() == 0) {
531 bool has_volumes =
false;
532 bool has_transparent_shadow =
false;
595 if (shader->get_use_bump_map_correction()) {
608 kshader->
pass_id = shader->get_pass_id();
633 KernelIntegrator *kintegrator = &dscene->
data.integrator;
634 kintegrator->use_volumes = has_volumes;
636 kintegrator->transparent_shadows = has_transparent_shadow;
639 KernelFilm *kfilm = &dscene->
data.film;
675 shader->
name =
"default_surface";
687 graph->
add(principled);
692 shader->
name =
"default_volume";
705 emission->set_color(
make_float3(0.8f, 0.8f, 0.8f));
706 emission->set_strength(0.0f);
707 graph->
add(emission);
712 shader->
name =
"default_light";
724 shader->
name =
"default_background";
736 shader->
name =
"default_empty";
746 uint kernel_features = 0;
764 return kernel_features;
770 for (
int i = 0; i < scene->
shaders.size(); i++) {
796 return kernel_features;
803 OSLShaderManager::free_memory();
821 string manifest =
"{";
822 unordered_set<ustring> materials;
824 if (materials.count(shader->
name)) {
827 materials.insert(shader->
name);
829 manifest +=
string_printf(
"\"%s\":\"%08x\",", shader->
name.c_str(), cryptomatte_id);
831 manifest[manifest.size() - 1] =
'}';
847static bool to_scene_linear_transform(OCIO::ConstConfigRcPtr &config,
848 const char *colorspace,
851 OCIO::ConstProcessorRcPtr processor;
853 processor = config->getProcessor(
"scene_linear", colorspace);
855 catch (OCIO::Exception &) {
863 OCIO::ConstCPUProcessorRcPtr device_processor = processor->getDefaultCPUProcessor();
864 if (!device_processor) {
869 device_processor->applyRGB(&to_scene_linear.
x.x);
870 device_processor->applyRGB(&to_scene_linear.
y.x);
871 device_processor->applyRGB(&to_scene_linear.
z.x);
907 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
908 if (!(config && config->hasRole(
"scene_linear"))) {
914 if (config->hasRole(
"aces_interchange")) {
917 if (!to_scene_linear_transform(config,
"aces_interchange", aces_to_rgb)) {
938 else if (config->hasRole(
"XYZ")) {
940 if (!to_scene_linear_transform(config,
"XYZ",
xyz_to_rgb)) {
Shader * get_shader(const Scene *scene)
virtual ClosureType get_closure_type()
static void free_memory()
device_vector< KernelShader > shaders
bool from_auto_conversion
void tag_update(Scene *scene, uint32_t flag)
@ SHADER_DISPLACEMENT_MODIFIED
@ SHADER_ATTRIBUTE_MODIFIED
bool need_update_background
bool has_background_light(Scene *scene)
void tag_update(Scene *scene, uint32_t flag)
size_t add_table(DeviceScene *dscene, vector< float > &data)
void remove_table(size_t *offset)
list< ShaderNode * > nodes
T * create_node(Args &&...args)
void compute_displacement_hash()
void connect(ShaderOutput *from, ShaderInput *to)
void remove_proxy_nodes()
ShaderNode * add(ShaderNode *node)
string get_cryptomatte_materials(Scene *scene)
static ShaderManager * create(int shadingsystem, Device *device)
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
static void free_memory()
AttributeIDMap unique_attribute_id
float linear_rgb_to_gray(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_
int get_shader_id(Shader *shader, bool smooth=false)
unordered_map< const float *, size_t > bsdf_tables
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
static thread_mutex lookup_table_mutex
void tag_update(Scene *scene, uint32_t flag)
uint get_kernel_features(Scene *scene)
size_t ensure_bsdf_table_impl(DeviceScene *dscene, Scene *scene, const float *table, size_t n)
float3 rec709_to_scene_linear(float3 c)
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)
ShaderInput * input(const char *name)
virtual bool has_surface_transparent()
virtual bool has_surface_emission()
ShaderNodeSpecialType special_type
vector< ShaderInput * > inputs
virtual int get_feature()
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
void set_graph(ShaderGraph *graph)
bool need_update_geometry() const
bool emission_is_constant
NODE_DECLARE ShaderGraph * graph
float prev_volume_step_rate
bool need_update_displacement
EmissionSampling emission_sampling
bool has_surface_raytrace
AttributeRequestSet attributes
bool has_surface_transparent
void tag_update(Scene *scene)
bool has_volume_connected
void tag_used(Scene *scene)
bool has_volume_spatial_varying
T * alloc(size_t width, size_t height=0, size_t depth=0)
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define CCL_NAMESPACE_END
smooth(Type::VEC3, "P") .flat(Type out_color storage_buf(0, Qualifier::READ, "Surfel", "surfels_buf[]") .push_constant(Type smooth(Type::VEC4, "interp_color")
#define CLOSURE_IS_VOLUME(type)
#define KERNEL_FEATURE_VOLUME
@ SD_HAS_TRANSPARENT_SHADOW
@ SD_HAS_CONSTANT_EMISSION
@ SD_NEED_VOLUME_ATTRIBUTES
@ SD_USE_BUMP_MAP_CORRECTION
@ SD_HETEROGENEOUS_VOLUME
#define KERNEL_FEATURE_NODE_BUMP_STATE
@ ATTR_STD_POSITION_UNDISPLACED
#define KERNEL_FEATURE_OSL
#define KERNEL_FEATURE_TRANSPARENT
@ EMISSION_SAMPLING_FRONT_BACK
@ EMISSION_SAMPLING_FRONT
#define KERNEL_FEATURE_SUBSURFACE
#define KERNEL_FEATURE_NODE_BSDF
#define KERNEL_FEATURE_NODE_VOLUME
#define KERNEL_FEATURE_NODE_EMISSION
#define KERNEL_FEATURE_NODE_BUMP
ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline float reduce_max(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()
float util_hash_to_float(uint32_t hash)
uint32_t util_murmur_hash3(const void *key, int len, uint32_t seed)
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_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_CLOSURE
unsigned __int64 uint64_t
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
float constant_emission[3]
int ggx_gen_schlick_ior_s
void insert(const char *x, int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=NULL)
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())
vector< Shader * > shaders
LookupTables * lookup_tables
Shader * default_background
ObjectManager * object_manager
ProceduralManager * procedural_manager
ShaderManager * shader_manager
LightManager * light_manager
T * create_node(Args &&...args)
GeometryManager * geometry_manager
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
ccl_device_inline float4 float3_to_float4(const float3 a)
ccl_device_inline float3 float4_to_float3(const float4 a)