41 # include <OpenColorIO/OpenColorIO.h>
42 namespace OCIO = OCIO_NAMESPACE;
56 return expf(-(slope_x * slope_x + slope_y * slope_y));
68 #if defined(_MSC_VER) && (_MSC_VER == 1900)
69 # define MSVC_VOLATILE volatile
71 # define MSVC_VOLATILE
82 const int DATA_TMP_SIZE = 512;
87 for (
int index_theta = row_from; index_theta < row_to; index_theta++) {
90 const float sin_theta =
safe_sqrtf(1.0f - cos_theta * cos_theta);
95 CDF_P22_omega_i[0] = 0;
97 for (
MSVC_VOLATILE int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x) {
101 (DATA_TMP_SIZE - 1.0f));
104 float dot_product =
fmaxf(0.0f, -(
float)slope_x[index_slope_x] * sin_theta + cos_theta);
106 float P22_omega_i = 0.0f;
108 for (
int j = 0; j < 100; ++j) {
111 P22_omega_i += dot_product *
beckmann_table_P22((
float)slope_x[index_slope_x], slope_y);
115 CDF_P22_omega_i[index_slope_x] = CDF_P22_omega_i[index_slope_x - 1] + (
double)P22_omega_i;
119 for (
int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x)
120 CDF_P22_omega_i[index_slope_x] /= CDF_P22_omega_i[DATA_TMP_SIZE - 1];
123 int index_slope_x = 0;
129 while (CDF_P22_omega_i[index_slope_x] <=
U)
132 const double interp = (CDF_P22_omega_i[index_slope_x] -
U) /
133 (CDF_P22_omega_i[index_slope_x] - CDF_P22_omega_i[index_slope_x - 1]);
137 (
float)(
interp * slope_x[index_slope_x - 1] + (1.0 -
interp) * slope_x[index_slope_x]);
164 SOCKET_BOOLEAN(use_transparent_shadow,
"Use Transparent Shadow",
true);
165 SOCKET_BOOLEAN(heterogeneous_volume,
"Heterogeneous Volume",
true);
167 static NodeEnum volume_sampling_method_enum;
172 "Volume Sampling Method",
173 volume_sampling_method_enum,
176 static NodeEnum volume_interpolation_method_enum;
180 "Volume Interpolation Method",
181 volume_interpolation_method_enum,
184 SOCKET_FLOAT(volume_step_rate,
"Volume Step Rate", 1.0f);
186 static NodeEnum displacement_method_enum;
251 assert(
node->input(
"Color"));
252 assert(
node->input(
"Strength"));
254 if (
node->input(
"Color")->link ||
node->input(
"Strength")->link) {
258 *emission =
node->get_color() *
node->get_strength();
260 else if (surf->
link->
parent->
type == BackgroundNode::get_node_type()) {
263 assert(
node->input(
"Color"));
264 assert(
node->input(
"Strength"));
266 if (
node->input(
"Color")->link ||
node->input(
"Strength")->link) {
270 *emission =
node->get_color() *
node->get_strength();
297 if (strcmp(old_hash, new_hash) != 0) {
359 if (displacement_method_is_modified()) {
418 manager =
new OSLShaderManager();
488 AlembicProcedural *abc_proc =
static_cast<AlembicProcedural *
>(procedural);
490 foreach (
Node *abc_node, abc_proc->get_objects()) {
491 AlembicObject *abc_object =
static_cast<AlembicObject *
>(abc_node);
493 foreach (
Node *
node, abc_object->get_used_shaders()) {
502 foreach (
Node *
node, geom->get_used_shaders()) {
508 if (light->get_shader())
509 const_cast<Shader *
>(light->get_shader())->used =
true;
523 bool has_volumes =
false;
524 bool has_transparent_shadow =
false;
529 if (
shader->get_use_mis())
531 if (
shader->has_surface_transparent &&
shader->get_use_transparent_shadow())
543 if (
shader->has_volume_connected && !
shader->has_surface)
546 if (
shader->get_heterogeneous_volume() &&
shader->has_volume_spatial_varying)
549 if (
shader->has_volume_attribute_dependency)
551 if (
shader->has_bssrdf_bump)
568 if (
shader->is_constant_emission(&constant_emission))
574 kshader->
flags = flag;
638 shader->name =
"default_surface";
649 graph->add(principled);
651 graph->connect(principled->
output(
"Volume"),
graph->output()->input(
"Volume"));
654 shader->name =
"default_volume";
665 emission->set_color(
make_float3(0.8f, 0.8f, 0.8f));
666 emission->set_strength(0.0f);
667 graph->add(emission);
669 graph->connect(emission->
output(
"Emission"),
graph->output()->input(
"Surface"));
672 shader->name =
"default_light";
683 shader->name =
"default_background";
694 shader->name =
"default_empty";
717 if (
node->has_surface_bssrdf()) {
720 if (
node->has_surface_transparent()) {
723 if (
node->has_raytrace()) {
763 OSLShaderManager::free_memory();
776 string manifest =
"{";
777 unordered_set<ustring, ustringHash> materials;
779 if (materials.count(
shader->name)) {
782 materials.insert(
shader->name);
786 manifest[manifest.size() - 1] =
'}';
802 static bool to_scene_linear_transform(OCIO::ConstConfigRcPtr &config,
803 const char *colorspace,
806 OCIO::ConstProcessorRcPtr processor;
808 processor = config->getProcessor(OCIO::ROLE_SCENE_LINEAR, colorspace);
810 catch (OCIO::Exception &) {
818 OCIO::ConstCPUProcessorRcPtr device_processor = processor->getDefaultCPUProcessor();
819 if (!device_processor) {
824 device_processor->applyRGB(&to_scene_linear.
x.x);
825 device_processor->applyRGB(&to_scene_linear.
y.x);
826 device_processor->applyRGB(&to_scene_linear.
z.x);
843 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
844 if (!(config && config->hasRole(OCIO::ROLE_SCENE_LINEAR))) {
850 if (config->hasRole(
"aces_interchange")) {
865 1.0521111f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.9184170f, 0.0f);
868 if (!to_scene_linear_transform(config,
"aces_interchange", aces_to_rgb)) {
872 xyz_to_rgb = aces_to_rgb * xyz_E_to_aces * xyz_D65_to_E;
874 else if (config->hasRole(
"XYZ")) {
876 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()
bool has_volume_decoupled
device_vector< KernelShader > shaders
@ SHADER_DISPLACEMENT_MODIFIED
@ SHADER_ATTRIBUTE_MODIFIED
void tag_update(Scene *scene, uint32_t flag)
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_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()
size_t beckmann_table_offset
thread_spin_lock attribute_lock_
void get_requested_features(Scene *scene, DeviceRequestedFeatures *requested_features)
int get_shader_id(Shader *shader, bool smooth=false)
void get_requested_graph_features(ShaderGraph *graph, DeviceRequestedFeatures *requested_features)
static ShaderManager * create(int shadingsystem)
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
static vector< float > beckmann_table
void update_shaders_used(Scene *scene)
static thread_mutex lookup_table_mutex
void tag_update(Scene *scene, uint32_t flag)
static void add_default(Scene *scene)
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
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)
@ SHADER_SPECIAL_TYPE_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_CLOSURE
CCL_NAMESPACE_BEGIN ccl_device float3 xyz_to_rgb(KernelGlobals *kg, float3 xyz)
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
@ SD_HAS_TRANSPARENT_SHADOW
@ SD_HAS_CONSTANT_EMISSION
@ SD_NEED_VOLUME_ATTRIBUTES
@ SD_HETEROGENEOUS_VOLUME
@ ATTR_STD_POSITION_UNDISPLACED
#define BECKMANN_TABLE_SIZE
#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,...)
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
KernelIntegrator integrator
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)
T * create_node(Args &&... args)
vector< Geometry * > geometry
vector< Shader * > shaders
vector< Procedural * > procedurals
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)
#define CLOSURE_IS_VOLUME(type)
#define NODE_FEATURE_BUMP
#define NODE_GROUP_LEVEL_0
#define NODE_FEATURE_BUMP_STATE
#define CLOSURE_IS_PRINCIPLED(type)
#define NODE_FEATURE_VOLUME
#define NODE_GROUP_LEVEL_1
ccl_device_inline float4 float3_to_float4(const float3 a)
ccl_device_inline float3 float4_to_float3(const float4 a)
ccl_device_inline float dot(const float2 &a, const float2 &b)
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)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
std::unique_lock< std::mutex > thread_scoped_lock
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex