28 # include <OpenColorIO/OpenColorIO.h>
29 namespace OCIO = OCIO_NAMESPACE;
43 return expf(-(slope_x * slope_x + slope_y * slope_y));
55 #if defined(_MSC_VER) && (_MSC_VER == 1900)
56 # define MSVC_VOLATILE volatile
58 # define MSVC_VOLATILE
69 const int DATA_TMP_SIZE = 512;
74 for (
int index_theta = row_from; index_theta < row_to; index_theta++) {
77 const float sin_theta =
safe_sqrtf(1.0f - cos_theta * cos_theta);
82 CDF_P22_omega_i[0] = 0;
84 for (
MSVC_VOLATILE int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x) {
88 (DATA_TMP_SIZE - 1.0f));
91 float dot_product =
fmaxf(0.0f, -(
float)slope_x[index_slope_x] * sin_theta + cos_theta);
93 float P22_omega_i = 0.0f;
95 for (
int j = 0; j < 100; ++j) {
98 P22_omega_i += dot_product *
beckmann_table_P22((
float)slope_x[index_slope_x], slope_y);
102 CDF_P22_omega_i[index_slope_x] = CDF_P22_omega_i[index_slope_x - 1] + (
double)P22_omega_i;
106 for (
int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x)
107 CDF_P22_omega_i[index_slope_x] /= CDF_P22_omega_i[DATA_TMP_SIZE - 1];
110 int index_slope_x = 0;
116 while (CDF_P22_omega_i[index_slope_x] <=
U)
119 const double interp = (CDF_P22_omega_i[index_slope_x] -
U) /
120 (CDF_P22_omega_i[index_slope_x] - CDF_P22_omega_i[index_slope_x - 1]);
124 (
float)(
interp * slope_x[index_slope_x - 1] + (1.0 -
interp) * slope_x[index_slope_x]);
151 SOCKET_BOOLEAN(use_transparent_shadow,
"Use Transparent Shadow",
true);
152 SOCKET_BOOLEAN(heterogeneous_volume,
"Heterogeneous Volume",
true);
154 static NodeEnum volume_sampling_method_enum;
159 "Volume Sampling Method",
160 volume_sampling_method_enum,
163 static NodeEnum volume_interpolation_method_enum;
167 "Volume Interpolation Method",
168 volume_interpolation_method_enum,
171 SOCKET_FLOAT(volume_step_rate,
"Volume Step Rate", 1.0f);
173 static NodeEnum displacement_method_enum;
238 assert(
node->input(
"Color"));
239 assert(
node->input(
"Strength"));
241 if (
node->input(
"Color")->link ||
node->input(
"Strength")->link) {
245 *emission =
node->get_color() *
node->get_strength();
247 else if (surf->
link->
parent->
type == BackgroundNode::get_node_type()) {
250 assert(
node->input(
"Color"));
251 assert(
node->input(
"Strength"));
253 if (
node->input(
"Color")->link ||
node->input(
"Strength")->link) {
257 *emission =
node->get_color() *
node->get_strength();
284 if (strcmp(old_hash, new_hash) != 0) {
346 if (displacement_method_is_modified()) {
406 manager =
new OSLShaderManager();
487 bool has_volumes =
false;
488 bool has_transparent_shadow =
false;
493 if (shader->get_use_mis())
540 kshader->
flags = flag;
541 kshader->
pass_id = shader->get_pass_id();
570 KernelIntegrator *kintegrator = &dscene->
data.integrator;
571 kintegrator->use_volumes = has_volumes;
573 kintegrator->transparent_shadows = has_transparent_shadow;
576 KernelFilm *kfilm = &dscene->
data.film;
608 shader->
name =
"default_surface";
620 graph->add(principled);
622 graph->connect(principled->
output(
"Volume"),
graph->output()->input(
"Volume"));
625 shader->
name =
"default_volume";
638 emission->set_color(
make_float3(0.8f, 0.8f, 0.8f));
639 emission->set_strength(0.0f);
640 graph->add(emission);
642 graph->connect(emission->
output(
"Emission"),
graph->output()->input(
"Surface"));
645 shader->
name =
"default_light";
657 shader->
name =
"default_background";
669 shader->
name =
"default_empty";
679 uint kernel_features = 0;
682 kernel_features |=
node->get_feature();
692 if (
node->has_surface_bssrdf()) {
695 if (
node->has_surface_transparent()) {
700 return kernel_features;
728 return kernel_features;
736 OSLShaderManager::free_memory();
754 string manifest =
"{";
755 unordered_set<ustring, ustringHash>
materials;
762 manifest +=
string_printf(
"\"%s\":\"%08x\",", shader->
name.c_str(), cryptomatte_id);
764 manifest[manifest.size() - 1] =
'}';
780 static bool to_scene_linear_transform(OCIO::ConstConfigRcPtr &config,
781 const char *colorspace,
784 OCIO::ConstProcessorRcPtr processor;
786 processor = config->getProcessor(OCIO::ROLE_SCENE_LINEAR, colorspace);
788 catch (OCIO::Exception &) {
796 OCIO::ConstCPUProcessorRcPtr device_processor = processor->getDefaultCPUProcessor();
797 if (!device_processor) {
802 device_processor->applyRGB(&to_scene_linear.
x.x);
803 device_processor->applyRGB(&to_scene_linear.
y.x);
804 device_processor->applyRGB(&to_scene_linear.
z.x);
839 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
840 if (!(config && config->hasRole(OCIO::ROLE_SCENE_LINEAR))) {
846 if (config->hasRole(
"aces_interchange")) {
849 if (!to_scene_linear_transform(config,
"aces_interchange", aces_to_rgb)) {
870 else if (config->hasRole(
"XYZ")) {
872 if (!to_scene_linear_transform(config,
"XYZ",
xyz_to_rgb)) {
typedef float(TangentPoint)[2]
MINLINE float safe_sqrtf(float a)
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
bool modified(const AttributeRequestSet &other)
Shader * get_shader(const Scene *scene)
virtual ClosureType get_closure_type()
static void free_memory()
device_vector< KernelShader > shaders
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
void compute_displacement_hash()
void remove_proxy_nodes()
string get_cryptomatte_materials(Scene *scene)
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
static bool beckmann_table_ready
static void free_memory()
uint get_attribute_id(ustring name)
AttributeIDMap unique_attribute_id
float linear_rgb_to_gray(float3 c)
void init_xyz_transforms()
virtual void device_update_specific(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)=0
size_t beckmann_table_offset
thread_spin_lock attribute_lock_
int get_shader_id(Shader *shader, bool smooth=false)
static ShaderManager * create(int shadingsystem)
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
static vector< float > beckmann_table
static thread_mutex lookup_table_mutex
void tag_update(Scene *scene, uint32_t flag)
uint get_kernel_features(Scene *scene)
float3 rec709_to_scene_linear(float3 c)
static void add_default(Scene *scene)
uint get_graph_kernel_features(ShaderGraph *graph)
ShaderInput * input(const char *name)
ShaderOutput * output(const char *name)
bool has_surface_spatial_varying
bool need_update_attribute
bool has_volume_attribute_dependency
void set_graph(ShaderGraph *graph)
bool need_update_geometry() const
NODE_DECLARE ShaderGraph * graph
float prev_volume_step_rate
bool has_integrator_dependency
bool need_update_displacement
bool has_surface_emission
bool has_surface_raytrace
AttributeRequestSet attributes
bool has_surface_transparent
void tag_update(Scene *scene)
bool is_constant_emission(float3 *emission)
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)
#define CCL_NAMESPACE_END
SyclQueue void void size_t num_bytes void
smooth(Type::VEC4, "color_mul") .smooth(Type gpFillTexture gpSceneDepthTexture materials[GPENCIL_MATERIAL_BUFFER_LEN]
ccl_global KernelShaderEvalInput ccl_global float * output
#define CLOSURE_IS_VOLUME(type)
#define CLOSURE_IS_PRINCIPLED(type)
@ SD_HAS_TRANSPARENT_SHADOW
@ SD_HAS_CONSTANT_EMISSION
@ SD_NEED_VOLUME_ATTRIBUTES
@ SD_HETEROGENEOUS_VOLUME
@ ATTR_STD_POSITION_UNDISPLACED
@ KERNEL_FEATURE_NODE_VOLUME
@ KERNEL_FEATURE_NODE_EMISSION
@ KERNEL_FEATURE_NODE_BSDF
@ KERNEL_FEATURE_NODE_BUMP
@ KERNEL_FEATURE_SUBSURFACE
@ KERNEL_FEATURE_PRINCIPLED
@ KERNEL_FEATURE_TRANSPARENT
@ KERNEL_FEATURE_NODE_BUMP_STATE
#define BECKMANN_TABLE_SIZE
ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
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)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
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 SOCKET_BOOLEAN(name, ui_name, default_value,...)
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
smooth(Type::FLOAT, "mask_weight")
static void beckmann_table_rows(float *table, int row_from, int row_to)
static void beckmann_table_build(vector< float > &table)
static float beckmann_table_P22(const float slope_x, const float slope_y)
static float beckmann_table_slope_max()
@ 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
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
float constant_emission[3]
void insert(const char *x, int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=NULL)
int reference_count() const
T * create_node(Args &&...args)
vector< Shader * > shaders
LookupTables * lookup_tables
Shader * default_background
ObjectManager * object_manager
ProceduralManager * procedural_manager
ShaderManager * shader_manager
LightManager * light_manager
GeometryManager * geometry_manager
void push(TaskRunFunction &&task)
void wait_work(Summary *stats=NULL)
std::unique_lock< std::mutex > thread_scoped_lock
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)