4 #include <OSL/oslexec.h>
33 if (!osl_globals->use) {
39 kg->osl = osl_globals;
42 OSLThreadData *tdata =
new OSLThreadData();
44 memset((
void *)&tdata->globals, 0,
sizeof(OSL::ShaderGlobals));
45 tdata->globals.tracedata = &tdata->tracedata;
46 tdata->globals.flipHandedness =
false;
47 tdata->osl_thread_info = ss->create_thread_info();
48 tdata->context = ss->get_context(tdata->osl_thread_info);
50 tdata->oiio_thread_info = osl_globals->ts->get_perthread_info();
52 kg->osl_ss = (OSLShadingSystem *)ss;
53 kg->osl_tdata = tdata;
62 OSLThreadData *tdata = kg->osl_tdata;
63 ss->release_context(tdata->context);
65 ss->destroy_thread_info(tdata->osl_thread_info);
82 OSL::ShaderGlobals *globals = &tdata->globals;
86 globals->dPdx =
TO_VEC3(sd->dP.dx);
87 globals->dPdy =
TO_VEC3(sd->dP.dy);
89 globals->dIdx =
TO_VEC3(sd->dI.dx);
90 globals->dIdy =
TO_VEC3(sd->dI.dy);
94 globals->dudx = sd->du.dx;
95 globals->dudy = sd->du.dy;
97 globals->dvdx = sd->dv.dx;
98 globals->dvdy = sd->dv.dy;
99 globals->dPdu =
TO_VEC3(sd->dPdu);
100 globals->dPdv =
TO_VEC3(sd->dPdv);
101 globals->surfacearea = 1.0f;
102 globals->time = sd->time;
105 globals->raytype = path_flag;
109 globals->renderstate = sd;
112 globals->shader2common = sd;
113 globals->object2common = sd;
119 tdata->tracedata.init =
false;
122 sd->osl_globals = kg;
124 sd->osl_path_state =
nullptr;
129 sd->osl_shadow_path_state =
nullptr;
137 const OSL::ClosureColor *closure,
143 switch (closure->id) {
145 OSL::ClosureMul *
mul = (OSL::ClosureMul *)closure;
149 case OSL::ClosureColor::ADD: {
150 OSL::ClosureAdd *
add = (OSL::ClosureAdd *)closure;
156 OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
160 #ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
163 prim->
setup(sd, path_flag, weight);
176 OSLThreadData *tdata = kg->osl_tdata;
181 OSL::ShaderGlobals *globals = &tdata->globals;
182 OSL::ShadingContext *octx = tdata->context;
186 if (kg->osl->bump_state[shader]) {
195 bool found = kg->osl->services->get_attribute(sd,
198 TypeDesc::TypeVector,
205 memcpy(&sd->P,
data,
sizeof(
float) * 3);
206 memcpy(&dP.
dx,
data + 3,
sizeof(
float) * 3);
207 memcpy(&dP.
dy,
data + 6,
sizeof(
float) * 3);
216 sd->dP.dx *= dP_radius;
217 sd->dP.dy *= dP_radius;
220 globals->dPdx =
TO_VEC3(sd->dP.dx);
221 globals->dPdy =
TO_VEC3(sd->dP.dy);
225 ss->execute(octx, *(kg->osl->bump_state[shader]), *globals);
238 if (kg->osl->surface_state[shader]) {
239 ss->execute(octx, *(kg->osl->surface_state[shader]), *globals);
250 const OSL::ClosureColor *closure,
257 switch (closure->id) {
259 OSL::ClosureMul *
mul = (OSL::ClosureMul *)closure;
263 case OSL::ClosureColor::ADD: {
264 OSL::ClosureAdd *
add = (OSL::ClosureAdd *)closure;
271 OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
275 #ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
278 prim->
setup(sd, 0, weight);
291 OSLThreadData *tdata = kg->osl_tdata;
296 OSL::ShaderGlobals *globals = &tdata->globals;
297 OSL::ShadingContext *octx = tdata->context;
299 if (kg->osl->background_state) {
300 ss->execute(octx, *(kg->osl->background_state), *globals);
311 const OSL::ClosureColor *closure,
317 switch (closure->id) {
319 OSL::ClosureMul *
mul = (OSL::ClosureMul *)closure;
323 case OSL::ClosureColor::ADD: {
324 OSL::ClosureAdd *
add = (OSL::ClosureAdd *)closure;
330 OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
334 #ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
337 prim->
setup(sd, 0, weight);
349 OSLThreadData *tdata = kg->osl_tdata;
354 OSL::ShaderGlobals *globals = &tdata->globals;
355 OSL::ShadingContext *octx = tdata->context;
358 if (kg->osl->volume_state[shader]) {
359 ss->execute(octx, *(kg->osl->volume_state[shader]), *globals);
372 OSLThreadData *tdata = kg->osl_tdata;
378 OSL::ShaderGlobals *globals = &tdata->globals;
379 OSL::ShadingContext *octx = tdata->context;
382 if (kg->osl->displacement_state[shader]) {
383 ss->execute(octx, *(kg->osl->displacement_state[shader]), *globals);
401 ustring stdname(std::string(
"geom:") +
403 OSLGlobals::AttributeMap::const_iterator it = attr_map.find(stdname);
405 if (it != attr_map.end()) {
407 *desc = osl_attr.desc;
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Attribute
static void mul(btAlignedObjectArray< T > &items, const Q &value)
static const char * standard_name(AttributeStandard std)
virtual void setup(ShaderData *sd, uint32_t path_flag, float3 weight)=0
static ustring u_geom_undisplaced
#define CCL_NAMESPACE_END
ccl_device_forceinline float differential_make_compact(const differential3 D)
SyclQueue void void size_t num_bytes void
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, ccl_private const ShaderData *sd, uint id)
ccl_device_inline void object_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device_inline void object_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
static void shaderdata_to_shaderglobals(const KernelGlobalsCPU *kg, ShaderData *sd, const void *state, uint32_t path_flag, OSLThreadData *tdata)
static void flatten_background_closure_tree(ShaderData *sd, const OSL::ClosureColor *closure, float3 weight=make_float3(1.0f, 1.0f, 1.0f))
static void flatten_surface_closure_tree(ShaderData *sd, uint32_t path_flag, const OSL::ClosureColor *closure, float3 weight=make_float3(1.0f, 1.0f, 1.0f))
static void flatten_volume_closure_tree(ShaderData *sd, const OSL::ClosureColor *closure, float3 weight=make_float3(1.0f, 1.0f, 1.0f))
struct AttributeMap AttributeMap
bool add(void *owner, const AttributeIDRef &attribute_id, eAttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer)
static void eval_displacement(SubdivDisplacement *displacement, const int ptex_face_index, const float u, const float v, const float dPdu[3], const float dPdv[3], float r_D[3])
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)