23#include "util/colorspace.h"
28#include "scene/shader.tables"
40 static NodeEnum emission_sampling_method_enum;
47 "Emission Sampling Method",
48 emission_sampling_method_enum,
51 SOCKET_BOOLEAN(use_transparent_shadow,
"Use Transparent Shadow",
true);
52 SOCKET_BOOLEAN(use_bump_map_correction,
"Bump Map Correction",
true);
54 static NodeEnum volume_sampling_method_enum;
59 "Volume Sampling Method",
60 volume_sampling_method_enum,
63 static NodeEnum volume_interpolation_method_enum;
67 "Volume Interpolation Method",
68 volume_interpolation_method_enum,
71 SOCKET_FLOAT(volume_step_rate,
"Volume Step Rate", 1.0f);
73 static NodeEnum displacement_method_enum;
130 if (
node ==
nullptr) {
133 if (
node->type == EmissionNode::get_node_type() ||
134 node->type == BackgroundNode::get_node_type() ||
135 node->type == PrincipledBsdfNode::get_node_type())
137 const bool is_principled = (
node->type == PrincipledBsdfNode::get_node_type());
139 ShaderInput *color_in =
node->input(is_principled ?
"Emission Color" :
"Color");
140 ShaderInput *strength_in =
node->input(is_principled ?
"Emission Strength" :
"Strength");
149 if (color_in->
link) {
156 if (strength_in->
link) {
166 if (
node->type == LightFalloffNode::get_node_type() ||
167 node->type == IESLightNode::get_node_type())
176 if (
node->type == AddClosureNode::get_node_type()) {
181 const float3 estimate1 = (closure1_in->
link) ?
184 const float3 estimate2 = (closure2_in->
link) ?
188 return estimate1 + estimate2;
190 if (
node->type == MixClosureNode::get_node_type()) {
196 const float3 estimate1 = (closure1_in->
link) ?
199 const float3 estimate2 = (closure2_in->
link) ?
205 return estimate1 + estimate2;
209 return (1.0f - fac) * estimate1 + fac * estimate2;
214 const bool has_emission =
node->has_surface_emission();
268 if (
output &&
output->parent->type == EmissionNode::get_node_type()) {
290 graph_->remove_proxy_nodes();
293 graph_->compute_displacement_hash();
299 const char *old_hash = (
graph) ?
graph->displacement_hash.c_str() :
"";
300 const char *new_hash = (graph_) ? graph_->displacement_hash.c_str() :
"";
302 if (strcmp(old_hash, new_hash) != 0) {
308 graph = std::move(graph_);
317 if (!use_transparent_shadow) {
322 if (
node->has_surface_transparent()) {
404 if (displacement_method_is_modified()) {
473 manager = make_unique<OSLShaderManager>();
478 manager = make_unique<SVMShaderManager>();
546 bool has_volumes =
false;
552 output->input(
"Surface")->link &&
553 output->input(
"Displacement")->link;
556 shader->
graph->finalize(scene,
596 KernelIntegrator *kintegrator = &dscene->
data.integrator;
597 if (
bool(kintegrator->use_volumes) != has_volumes) {
599 kintegrator->use_volumes = has_volumes;
627 bool has_transparent_shadow =
false;
689 if (shader->get_use_bump_map_correction()) {
706 shader->
name.c_str(), shader->
name.length(), 0);
709 kshader->
flags = flag;
710 kshader->
pass_id = shader->get_pass_id();
738 KernelIntegrator *kintegrator = &dscene->
data.integrator;
740 kintegrator->transparent_shadows = has_transparent_shadow;
743 KernelFilm *kfilm = &dscene->
data.film;
775 graph->connect(bsdf->
output(
"BSDF"), graph->output()->input(
"Surface"));
778 shader->
name =
"default_surface";
791 graph->connect(principled->
output(
"Volume"), graph->output()->input(
"Volume"));
794 shader->
name =
"default_volume";
807 emission->set_color(
make_float3(0.8f, 0.8f, 0.8f));
808 emission->set_strength(0.0f);
810 graph->connect(emission->
output(
"Emission"), graph->output()->input(
"Surface"));
813 shader->
name =
"default_light";
825 shader->
name =
"default_background";
837 shader->
name =
"default_empty";
849 attribute->set_attribute(ustring(
"radiance"));
851 emission->set_strength(1.0f);
852 graph->connect(
attribute->output(
"Color"), emission->
input(
"Color"));
853 graph->connect(emission->
output(
"Emission"), graph->output()->input(
"Surface"));
856 shader->
name =
"default_gsplat";
869 kernel_features |=
node->get_feature();
876 if (
node->has_surface_bssrdf()) {
879 if (
node->has_surface_transparent()) {
884 return kernel_features;
899 if (output_node->
input(
"Displacement")->
link !=
nullptr) {
916 return kernel_features;
931 string manifest =
"{";
932 unordered_set<ustring> materials;
934 if (materials.contains(shader->
name)) {
937 materials.insert(shader->
name);
939 shader->
name.c_str(), shader->
name.length(), 0);
940 manifest +=
string_printf(
"\"%s\":\"%08x\",", shader->
name.c_str(), cryptomatte_id);
942 manifest[manifest.size() - 1] =
'}';
994 const float *table_row = table_thin_film_cmf[i];
1007 normalization = 1.0f / rgbReal;
unsigned long long int uint64_t
bool modified(const AttributeRequestSet &other) const
Shader * get_shader(const Scene *scene)
ClosureType get_closure_type() override
static Transform get_xyz_to_scene_linear_rgb()
static Transform get_xyz_to_rec709()
static const char * get_scene_linear_interop_id(const bool srgb_encoded=false)
device_vector< KernelShader > shaders
device_vector< int > svm_nodes
bool from_auto_conversion
@ SHADER_DISPLACEMENT_MODIFIED
@ SHADER_ATTRIBUTE_MODIFIED
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
unique_ptr_vector< ShaderNode > nodes
const SocketType & socket_type
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)
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)
unordered_map< const float *, size_t > bsdf_tables
void device_update_post(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
int get_shader_id(const Shader *shader, bool smooth=false)
void tag_update(Scene *scene, const uint32_t flag)
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
string scene_linear_interop_id
static thread_mutex lookup_table_mutex
uint64_t get_kernel_features(Scene *scene)
uint64_t get_graph_kernel_features(ShaderGraph *graph)
size_t ensure_bsdf_table(DeviceScene *dscene, Scene *scene, const float(&table)[n])
static void add_default(Scene *scene)
vector< float > thin_film_table
ShaderInput * input(const char *name)
ShaderOutput * output(const char *name)
AttributeRequestSet global_attributes
bool has_surface_spatial_varying
bool has_bump_from_surface
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 has_bump_from_displacement
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 need_update_shadow_transparency
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)
#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)
float dot(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
float reduce_max(float2 a)
@ SD_HAS_TRANSPARENT_SHADOW
@ SD_HAS_CONSTANT_EMISSION
@ SD_NEED_VOLUME_ATTRIBUTES
@ SD_USE_BUMP_MAP_CORRECTION
@ SD_HAS_BUMP_FROM_DISPLACEMENT
@ SD_HETEROGENEOUS_VOLUME
@ SD_HAS_BUMP_FROM_SURFACE
@ EMISSION_SAMPLING_FRONT_BACK
@ EMISSION_SAMPLING_FRONT
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_NORMAL_UNDISPLACED
ccl_device float3 rec709_to_rgb(KernelGlobals kg, const float3 rec709)
ccl_device_inline dual3 fabs(const ccl_private dual3 &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)
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_SCENE_TIME
@ 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)
int reference_count() const
Node(const NodeType *type, ustring name=ustring())