2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-02-02 22:15:33 +05:00
|
|
|
/* TODO(sergey): There is a bit of headers dependency hell going on
|
|
|
|
* here, so for now we just put here. In the future it might be better
|
|
|
|
* to have dedicated file for such tweaks.
|
|
|
|
*/
|
2015-10-25 20:48:28 +01:00
|
|
|
#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
|
2015-02-02 22:15:33 +05:00
|
|
|
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
2015-06-13 16:17:55 +02:00
|
|
|
# pragma GCC diagnostic ignored "-Wuninitialized"
|
2015-02-02 22:15:33 +05:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/colorspace.h"
|
|
|
|
#include "scene/mesh.h"
|
|
|
|
#include "scene/object.h"
|
2021-12-01 17:30:46 +01:00
|
|
|
#include "scene/pointcloud.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/scene.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/osl/closures.h"
|
|
|
|
#include "kernel/osl/globals.h"
|
|
|
|
#include "kernel/osl/services.h"
|
|
|
|
#include "kernel/osl/shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/foreach.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/string.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format off
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
#include "kernel/device/cpu/compat.h"
|
|
|
|
#include "kernel/device/cpu/globals.h"
|
|
|
|
#include "kernel/device/cpu/image.h"
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/util/differential.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/integrator/state.h"
|
|
|
|
#include "kernel/integrator/state_flow.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "kernel/geom/geom.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "kernel/bvh/bvh.h"
|
2014-03-29 13:03:48 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/camera/camera.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/camera/projection.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/integrator/path_state.h"
|
|
|
|
#include "kernel/integrator/shader_eval.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/util/color.h"
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format on
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* RenderServices implementation */
|
|
|
|
|
2018-03-08 05:33:55 +01:00
|
|
|
static void copy_matrix(OSL::Matrix44 &m, const Transform &tfm)
|
|
|
|
{
|
2018-03-08 06:48:14 +01:00
|
|
|
ProjectionTransform t = projection_transpose(ProjectionTransform(tfm));
|
2018-06-11 12:54:17 +02:00
|
|
|
memcpy((void *)&m, &t, sizeof(m));
|
2018-03-08 05:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void copy_matrix(OSL::Matrix44 &m, const ProjectionTransform &tfm)
|
|
|
|
{
|
|
|
|
ProjectionTransform t = projection_transpose(tfm);
|
2018-06-11 12:54:17 +02:00
|
|
|
memcpy((void *)&m, &t, sizeof(m));
|
2018-03-08 05:33:55 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* static ustrings */
|
|
|
|
ustring OSLRenderServices::u_distance("distance");
|
|
|
|
ustring OSLRenderServices::u_index("index");
|
2014-05-06 16:39:28 +02:00
|
|
|
ustring OSLRenderServices::u_world("world");
|
2011-04-27 11:58:34 +00:00
|
|
|
ustring OSLRenderServices::u_camera("camera");
|
|
|
|
ustring OSLRenderServices::u_screen("screen");
|
|
|
|
ustring OSLRenderServices::u_raster("raster");
|
|
|
|
ustring OSLRenderServices::u_ndc("NDC");
|
2012-12-01 19:15:05 +00:00
|
|
|
ustring OSLRenderServices::u_object_location("object:location");
|
2019-08-22 14:26:09 +02:00
|
|
|
ustring OSLRenderServices::u_object_color("object:color");
|
2022-03-07 17:34:52 +01:00
|
|
|
ustring OSLRenderServices::u_object_alpha("object:alpha");
|
2012-12-01 19:15:05 +00:00
|
|
|
ustring OSLRenderServices::u_object_index("object:index");
|
|
|
|
ustring OSLRenderServices::u_geom_dupli_generated("geom:dupli_generated");
|
|
|
|
ustring OSLRenderServices::u_geom_dupli_uv("geom:dupli_uv");
|
|
|
|
ustring OSLRenderServices::u_material_index("material:index");
|
|
|
|
ustring OSLRenderServices::u_object_random("object:random");
|
2018-02-14 17:02:28 +01:00
|
|
|
ustring OSLRenderServices::u_particle_index("particle:index");
|
2018-02-14 14:32:38 +01:00
|
|
|
ustring OSLRenderServices::u_particle_random("particle:random");
|
2012-12-01 19:15:05 +00:00
|
|
|
ustring OSLRenderServices::u_particle_age("particle:age");
|
|
|
|
ustring OSLRenderServices::u_particle_lifetime("particle:lifetime");
|
|
|
|
ustring OSLRenderServices::u_particle_location("particle:location");
|
|
|
|
ustring OSLRenderServices::u_particle_rotation("particle:rotation");
|
|
|
|
ustring OSLRenderServices::u_particle_size("particle:size");
|
|
|
|
ustring OSLRenderServices::u_particle_velocity("particle:velocity");
|
|
|
|
ustring OSLRenderServices::u_particle_angular_velocity("particle:angular_velocity");
|
|
|
|
ustring OSLRenderServices::u_geom_numpolyvertices("geom:numpolyvertices");
|
|
|
|
ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices");
|
|
|
|
ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices");
|
|
|
|
ustring OSLRenderServices::u_geom_name("geom:name");
|
2016-08-14 11:44:25 -04:00
|
|
|
ustring OSLRenderServices::u_geom_undisplaced("geom:undisplaced");
|
2013-05-11 09:31:58 +00:00
|
|
|
ustring OSLRenderServices::u_is_smooth("geom:is_smooth");
|
2013-01-03 12:08:54 +00:00
|
|
|
ustring OSLRenderServices::u_is_curve("geom:is_curve");
|
|
|
|
ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness");
|
2021-09-24 07:42:36 +02:00
|
|
|
ustring OSLRenderServices::u_curve_length("geom:curve_length");
|
2013-01-03 12:08:54 +00:00
|
|
|
ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal");
|
2018-02-14 14:32:38 +01:00
|
|
|
ustring OSLRenderServices::u_curve_random("geom:curve_random");
|
2021-12-01 17:30:46 +01:00
|
|
|
ustring OSLRenderServices::u_is_point("geom:is_point");
|
|
|
|
ustring OSLRenderServices::u_point_radius("geom:point_radius");
|
2022-01-25 13:25:33 +01:00
|
|
|
ustring OSLRenderServices::u_point_position("geom:point_position");
|
|
|
|
ustring OSLRenderServices::u_point_random("geom:point_random");
|
2021-10-04 12:19:18 +02:00
|
|
|
ustring OSLRenderServices::u_normal_map_normal("geom:normal_map_normal");
|
2012-12-01 19:15:05 +00:00
|
|
|
ustring OSLRenderServices::u_path_ray_length("path:ray_length");
|
2013-07-31 20:30:37 +00:00
|
|
|
ustring OSLRenderServices::u_path_ray_depth("path:ray_depth");
|
2016-12-06 16:15:36 +01:00
|
|
|
ustring OSLRenderServices::u_path_diffuse_depth("path:diffuse_depth");
|
|
|
|
ustring OSLRenderServices::u_path_glossy_depth("path:glossy_depth");
|
2014-04-21 14:20:29 +02:00
|
|
|
ustring OSLRenderServices::u_path_transparent_depth("path:transparent_depth");
|
2016-01-06 23:38:13 +01:00
|
|
|
ustring OSLRenderServices::u_path_transmission_depth("path:transmission_depth");
|
2012-12-01 19:15:05 +00:00
|
|
|
ustring OSLRenderServices::u_trace("trace");
|
|
|
|
ustring OSLRenderServices::u_hit("hit");
|
|
|
|
ustring OSLRenderServices::u_hitdist("hitdist");
|
|
|
|
ustring OSLRenderServices::u_N("N");
|
|
|
|
ustring OSLRenderServices::u_Ng("Ng");
|
|
|
|
ustring OSLRenderServices::u_P("P");
|
|
|
|
ustring OSLRenderServices::u_I("I");
|
|
|
|
ustring OSLRenderServices::u_u("u");
|
|
|
|
ustring OSLRenderServices::u_v("v");
|
2011-04-27 11:58:34 +00:00
|
|
|
ustring OSLRenderServices::u_empty;
|
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
OSLRenderServices::OSLRenderServices(OSL::TextureSystem *texture_system)
|
|
|
|
: texture_system(texture_system)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OSLRenderServices::~OSLRenderServices()
|
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
if (texture_system) {
|
2022-06-16 19:39:13 +02:00
|
|
|
VLOG_INFO << "OSL texture system stats:\n" << texture_system->getstats();
|
2016-08-17 08:42:10 -04:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
OSL::TransformationPtr xform,
|
|
|
|
float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* this is only used for shader and object space, we don't really have
|
2012-06-09 17:22:52 +00:00
|
|
|
* a concept of shader space, so we just use object space for both. */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (xform) {
|
2012-06-04 22:44:58 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2011-04-27 11:58:34 +00:00
|
|
|
int object = sd->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object != OBJECT_NONE) {
|
2012-10-16 10:59:35 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-11-29 16:11:37 +00:00
|
|
|
Transform tfm;
|
|
|
|
|
|
|
|
if (time == sd->time)
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
tfm = object_get_transform(kg, sd);
|
2012-11-29 16:11:37 +00:00
|
|
|
else
|
2019-05-14 12:13:43 +02:00
|
|
|
tfm = object_fetch_transform_motion_test(kg, object, time, NULL);
|
2012-10-16 10:59:35 +00:00
|
|
|
#else
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform tfm = object_get_transform(kg, sd);
|
2012-10-16 10:59:35 +00:00
|
|
|
#endif
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-10-29 18:54:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (sd->type == PRIMITIVE_LAMP) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false);
|
|
|
|
copy_matrix(result, tfm);
|
2016-10-29 18:54:42 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
OSL::TransformationPtr xform,
|
|
|
|
float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* this is only used for shader and object space, we don't really have
|
2012-06-09 17:22:52 +00:00
|
|
|
* a concept of shader space, so we just use object space for both. */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (xform) {
|
2012-06-04 22:44:58 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2011-04-27 11:58:34 +00:00
|
|
|
int object = sd->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object != OBJECT_NONE) {
|
2012-10-16 10:59:35 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
|
|
|
Transform itfm;
|
2012-11-29 16:11:37 +00:00
|
|
|
|
|
|
|
if (time == sd->time)
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
itfm = object_get_inverse_transform(kg, sd);
|
2012-11-29 16:11:37 +00:00
|
|
|
else
|
2019-05-14 12:13:43 +02:00
|
|
|
object_fetch_transform_motion_test(kg, object, time, &itfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
#else
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform itfm = object_get_inverse_transform(kg, sd);
|
2012-10-16 10:59:35 +00:00
|
|
|
#endif
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, itfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-10-29 18:54:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (sd->type == PRIMITIVE_LAMP) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true);
|
|
|
|
copy_matrix(result, itfm);
|
2016-10-29 18:54:42 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
ustring from,
|
|
|
|
float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (from == u_ndc) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.ndctoworld);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_raster) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.rastertoworld);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_screen) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.screentoworld);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_camera) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.cameratoworld);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_world) {
|
2014-05-06 16:39:28 +02:00
|
|
|
result.makeIdentity();
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
ustring to,
|
|
|
|
float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (to == u_ndc) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtondc);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_raster) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtoraster);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_screen) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtoscreen);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_camera) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtocamera);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_world) {
|
2014-05-06 16:39:28 +02:00
|
|
|
result.makeIdentity();
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
OSL::TransformationPtr xform)
|
2012-09-02 01:10:31 +00:00
|
|
|
{
|
2012-10-16 10:59:35 +00:00
|
|
|
/* this is only used for shader and object space, we don't really have
|
|
|
|
* a concept of shader space, so we just use object space for both. */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (xform) {
|
2012-10-16 10:59:35 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2012-10-16 10:59:35 +00:00
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object != OBJECT_NONE) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform tfm = object_get_transform(kg, sd);
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
|
2016-10-29 18:54:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (sd->type == PRIMITIVE_LAMP) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false);
|
|
|
|
copy_matrix(result, tfm);
|
2016-10-29 18:54:42 +02:00
|
|
|
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
OSL::TransformationPtr xform)
|
2012-10-16 10:59:35 +00:00
|
|
|
{
|
|
|
|
/* this is only used for shader and object space, we don't really have
|
|
|
|
* a concept of shader space, so we just use object space for both. */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (xform) {
|
2012-10-16 10:59:35 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2012-10-16 10:59:35 +00:00
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object != OBJECT_NONE) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform tfm = object_get_inverse_transform(kg, sd);
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
|
2016-10-29 18:54:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (sd->type == PRIMITIVE_LAMP) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true);
|
|
|
|
copy_matrix(result, itfm);
|
2016-10-29 18:54:42 +02:00
|
|
|
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-09-02 01:10:31 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from)
|
2012-09-02 01:10:31 +00:00
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (from == u_ndc) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.ndctoworld);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_raster) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.rastertoworld);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_screen) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.screentoworld);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (from == u_camera) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.cameratoworld);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-16 10:59:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
|
|
|
|
OSL::Matrix44 &result,
|
|
|
|
ustring to)
|
2012-10-16 10:59:35 +00:00
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (to == u_ndc) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtondc);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_raster) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtoraster);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_screen) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtoscreen);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (to == u_camera) {
|
2018-03-08 05:33:55 +01:00
|
|
|
copy_matrix(result, kernel_data.cam.worldtocamera);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-16 10:59:35 +00:00
|
|
|
return false;
|
2012-09-02 01:10:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 10:17:58 +02:00
|
|
|
bool OSLRenderServices::get_array_attribute(OSL::ShaderGlobals *sg,
|
|
|
|
bool derivatives,
|
2012-06-04 22:44:58 +00:00
|
|
|
ustring object,
|
|
|
|
TypeDesc type,
|
|
|
|
ustring name,
|
|
|
|
int index,
|
|
|
|
void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
2020-10-26 18:23:40 +01:00
|
|
|
if (type == TypeFloatArray4) {
|
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = 0.0f;
|
|
|
|
fval[3] = 1.0f;
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[4] = f[1].x;
|
|
|
|
fval[5] = f[1].y;
|
|
|
|
fval[6] = 0.0f;
|
|
|
|
fval[7] = 0.0f;
|
|
|
|
|
|
|
|
fval[8] = f[2].x;
|
|
|
|
fval[9] = f[2].y;
|
|
|
|
fval[10] = 0.0f;
|
|
|
|
fval[11] = 0.0f;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
|
2019-03-05 14:54:54 +01:00
|
|
|
float *fval = (float *)val;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
if (derivatives) {
|
|
|
|
fval[3] = f[1].x;
|
|
|
|
fval[4] = f[1].y;
|
|
|
|
fval[5] = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
fval[6] = f[2].x;
|
|
|
|
fval[7] = f[2].y;
|
|
|
|
fval[8] = 0.0f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypeFloat) {
|
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = average(f[0]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
if (derivatives) {
|
|
|
|
fval[1] = average(f[1]);
|
|
|
|
fval[2] = average(f[2]);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:23:40 +01:00
|
|
|
static bool set_attribute_float2(float2 f, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
float2 fv[3];
|
|
|
|
|
|
|
|
fv[0] = f;
|
|
|
|
fv[1] = make_float2(0.0f, 0.0f);
|
|
|
|
fv[2] = make_float2(0.0f, 0.0f);
|
|
|
|
|
|
|
|
return set_attribute_float2(fv, type, derivatives, val);
|
|
|
|
}
|
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:23:40 +01:00
|
|
|
if (type == TypeFloatArray4) {
|
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = f[0].z;
|
|
|
|
fval[3] = 1.0f;
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[4] = f[1].x;
|
|
|
|
fval[5] = f[1].y;
|
|
|
|
fval[6] = f[1].z;
|
|
|
|
fval[7] = 0.0f;
|
|
|
|
|
|
|
|
fval[8] = f[2].x;
|
|
|
|
fval[9] = f[2].y;
|
|
|
|
fval[10] = f[2].z;
|
|
|
|
fval[11] = 0.0f;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
|
2012-10-20 15:09:36 +00:00
|
|
|
float *fval = (float *)val;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = f[0].z;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[3] = f[1].x;
|
|
|
|
fval[4] = f[1].y;
|
|
|
|
fval[5] = f[1].z;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[6] = f[2].x;
|
|
|
|
fval[7] = f[2].y;
|
|
|
|
fval[8] = f[2].z;
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
else if (type == TypeDesc::TypeFloat) {
|
2012-09-14 18:10:54 +00:00
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = average(f[0]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
2012-09-14 18:10:54 +00:00
|
|
|
fval[1] = average(f[1]);
|
|
|
|
fval[2] = average(f[2]);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool set_attribute_float3(float3 f, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
float3 fv[3];
|
|
|
|
|
|
|
|
fv[0] = f;
|
|
|
|
fv[1] = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
fv[2] = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
return set_attribute_float3(fv, type, derivatives, val);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 13:18:52 +10:00
|
|
|
/* Attributes with the TypeRGBA type descriptor should be retrieved and stored
|
2019-09-12 17:42:13 +02:00
|
|
|
* in a float array of size 4 (e.g. node_vertex_color.osl), this array have
|
|
|
|
* a type descriptor TypeFloatArray4. If the storage is not a TypeFloatArray4,
|
|
|
|
* we either store the first three components in a vector, store the average of
|
2019-09-19 13:18:52 +10:00
|
|
|
* the components in a float, or fail the retrieval and do nothing. We allow
|
2019-09-12 17:42:13 +02:00
|
|
|
* this for the correct operation of the Attribute node.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
float *fval = (float *)val;
|
|
|
|
if (type == TypeFloatArray4) {
|
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = f[0].z;
|
|
|
|
fval[3] = f[0].w;
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[4] = f[1].x;
|
|
|
|
fval[5] = f[1].y;
|
|
|
|
fval[6] = f[1].z;
|
|
|
|
fval[7] = f[1].w;
|
|
|
|
|
|
|
|
fval[8] = f[2].x;
|
|
|
|
fval[9] = f[2].y;
|
|
|
|
fval[10] = f[2].z;
|
|
|
|
fval[11] = f[2].w;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
|
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = f[0].z;
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[3] = f[1].x;
|
|
|
|
fval[4] = f[1].y;
|
|
|
|
fval[5] = f[1].z;
|
|
|
|
|
|
|
|
fval[6] = f[2].x;
|
|
|
|
fval[7] = f[2].y;
|
|
|
|
fval[8] = f[2].z;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypeFloat) {
|
|
|
|
fval[0] = average(float4_to_float3(f[0]));
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[1] = average(float4_to_float3(f[1]));
|
|
|
|
fval[2] = average(float4_to_float3(f[2]));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:23:40 +01:00
|
|
|
static bool set_attribute_float4(float4 f, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
float4 fv[3];
|
|
|
|
|
|
|
|
fv[0] = f;
|
2022-03-23 15:53:10 +01:00
|
|
|
fv[1] = zero_float4();
|
|
|
|
fv[2] = zero_float4();
|
2020-10-26 18:23:40 +01:00
|
|
|
|
|
|
|
return set_attribute_float4(fv, type, derivatives, val);
|
|
|
|
}
|
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:23:40 +01:00
|
|
|
if (type == TypeFloatArray4) {
|
2012-10-20 15:09:36 +00:00
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = f[0];
|
2020-10-26 18:23:40 +01:00
|
|
|
fval[1] = f[0];
|
|
|
|
fval[2] = f[0];
|
|
|
|
fval[3] = 1.0f;
|
|
|
|
|
|
|
|
if (derivatives) {
|
|
|
|
fval[4] = f[1];
|
|
|
|
fval[5] = f[1];
|
|
|
|
fval[6] = f[1];
|
|
|
|
fval[7] = 0.0f;
|
|
|
|
|
|
|
|
fval[8] = f[2];
|
|
|
|
fval[9] = f[2];
|
|
|
|
fval[10] = f[2];
|
|
|
|
fval[11] = 0.0f;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
|
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = f[0];
|
|
|
|
fval[1] = f[0];
|
|
|
|
fval[2] = f[0];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[3] = f[1];
|
|
|
|
fval[4] = f[1];
|
|
|
|
fval[5] = f[1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[6] = f[2];
|
|
|
|
fval[7] = f[2];
|
|
|
|
fval[8] = f[2];
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
else if (type == TypeDesc::TypeFloat) {
|
2012-06-04 22:44:58 +00:00
|
|
|
float *fval = (float *)val;
|
2012-09-14 18:10:54 +00:00
|
|
|
fval[0] = f[0];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
2012-09-14 18:10:54 +00:00
|
|
|
fval[1] = f[1];
|
|
|
|
fval[2] = f[2];
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return true;
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool set_attribute_float(float f, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
float fv[3];
|
|
|
|
|
|
|
|
fv[0] = f;
|
|
|
|
fv[1] = 0.0f;
|
|
|
|
fv[2] = 0.0f;
|
|
|
|
|
|
|
|
return set_attribute_float(fv, type, derivatives, val);
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-03 14:32:13 +00:00
|
|
|
static bool set_attribute_int(int i, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
|
|
|
|
int *ival = (int *)val;
|
|
|
|
ival[0] = i;
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
2012-11-03 14:32:13 +00:00
|
|
|
ival[1] = 0;
|
|
|
|
ival[2] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
static bool set_attribute_string(ustring str, TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
2014-08-05 17:53:00 +06:00
|
|
|
if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
|
|
|
|
type.arraylen == 0) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
ustring *sval = (ustring *)val;
|
|
|
|
sval[0] = str;
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
sval[1] = OSLRenderServices::u_empty;
|
|
|
|
sval[2] = OSLRenderServices::u_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-03 14:32:13 +00:00
|
|
|
static bool set_attribute_float3_3(float3 P[3], TypeDesc type, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
|
|
|
|
float *fval = (float *)val;
|
|
|
|
|
|
|
|
fval[0] = P[0].x;
|
|
|
|
fval[1] = P[0].y;
|
|
|
|
fval[2] = P[0].z;
|
|
|
|
|
|
|
|
fval[3] = P[1].x;
|
|
|
|
fval[4] = P[1].y;
|
|
|
|
fval[5] = P[1].z;
|
|
|
|
|
|
|
|
fval[6] = P[2].x;
|
|
|
|
fval[7] = P[2].y;
|
|
|
|
fval[8] = P[2].z;
|
|
|
|
|
|
|
|
if (type.arraylen > 3)
|
|
|
|
memset(fval + 3 * 3, 0, sizeof(float) * 3 * (type.arraylen - 3));
|
2015-03-28 00:15:15 +05:00
|
|
|
if (derivatives)
|
2012-11-03 14:32:13 +00:00
|
|
|
memset(fval + type.arraylen * 3, 0, sizeof(float) * 2 * 3 * type.arraylen);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-31 17:33:55 +01:00
|
|
|
static bool set_attribute_matrix(const Transform &tfm, TypeDesc type, void *val)
|
|
|
|
{
|
|
|
|
if (type == TypeDesc::TypeMatrix) {
|
2018-03-08 06:48:14 +01:00
|
|
|
copy_matrix(*(OSL::Matrix44 *)val, tfm);
|
2013-12-31 17:33:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
static bool get_primitive_attribute(const KernelGlobalsCPU *kg,
|
2019-02-19 15:41:22 +01:00
|
|
|
const ShaderData *sd,
|
|
|
|
const OSLGlobals::Attribute &attr,
|
2012-09-14 18:10:54 +00:00
|
|
|
const TypeDesc &type,
|
|
|
|
bool derivatives,
|
|
|
|
void *val)
|
|
|
|
{
|
2015-03-28 00:15:15 +05:00
|
|
|
if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
|
|
|
|
attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
|
2012-09-14 18:10:54 +00:00
|
|
|
float3 fval[3];
|
2020-10-26 18:13:53 +01:00
|
|
|
if (primitive_is_volume_attribute(sd, attr.desc)) {
|
|
|
|
fval[0] = primitive_volume_attribute_float3(kg, sd, attr.desc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memset(fval, 0, sizeof(fval));
|
|
|
|
fval[0] = primitive_surface_attribute_float3(
|
|
|
|
kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
|
|
|
}
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float3(fval, type, derivatives, val);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
else if (attr.type == TypeFloat2) {
|
2020-10-26 18:13:53 +01:00
|
|
|
if (primitive_is_volume_attribute(sd, attr.desc)) {
|
|
|
|
assert(!"Float2 attribute not support for volumes");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float2 fval[3];
|
|
|
|
fval[0] = primitive_surface_attribute_float2(
|
|
|
|
kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
|
|
|
return set_attribute_float2(fval, type, derivatives, val);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (attr.type == TypeDesc::TypeFloat) {
|
2012-11-04 22:31:32 +00:00
|
|
|
float fval[3];
|
2020-10-26 18:13:53 +01:00
|
|
|
if (primitive_is_volume_attribute(sd, attr.desc)) {
|
|
|
|
memset(fval, 0, sizeof(fval));
|
|
|
|
fval[0] = primitive_volume_attribute_float(kg, sd, attr.desc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fval[0] = primitive_surface_attribute_float(
|
|
|
|
kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
|
|
|
}
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float(fval, type, derivatives, val);
|
2012-11-04 22:31:32 +00:00
|
|
|
}
|
2020-10-26 18:23:40 +01:00
|
|
|
else if (attr.type == TypeDesc::TypeFloat4 || attr.type == TypeRGBA) {
|
2019-09-12 17:42:13 +02:00
|
|
|
float4 fval[3];
|
2020-10-26 18:13:53 +01:00
|
|
|
if (primitive_is_volume_attribute(sd, attr.desc)) {
|
|
|
|
memset(fval, 0, sizeof(fval));
|
|
|
|
fval[0] = primitive_volume_attribute_float4(kg, sd, attr.desc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fval[0] = primitive_surface_attribute_float4(
|
|
|
|
kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
return set_attribute_float4(fval, type, derivatives, val);
|
|
|
|
}
|
2012-11-04 22:31:32 +00:00
|
|
|
else {
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
2012-11-04 22:31:32 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
static bool get_mesh_attribute(const KernelGlobalsCPU *kg,
|
2013-12-31 17:33:55 +01:00
|
|
|
const ShaderData *sd,
|
|
|
|
const OSLGlobals::Attribute &attr,
|
|
|
|
const TypeDesc &type,
|
|
|
|
bool derivatives,
|
|
|
|
void *val)
|
|
|
|
{
|
2015-03-28 00:15:15 +05:00
|
|
|
if (attr.type == TypeDesc::TypeMatrix) {
|
2016-07-01 17:36:27 -04:00
|
|
|
Transform tfm = primitive_attribute_matrix(kg, sd, attr.desc);
|
2013-12-31 17:33:55 +01:00
|
|
|
return set_attribute_matrix(tfm, type, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:23:40 +01:00
|
|
|
static bool get_object_attribute(const OSLGlobals::Attribute &attr,
|
|
|
|
TypeDesc type,
|
|
|
|
bool derivatives,
|
|
|
|
void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:23:40 +01:00
|
|
|
if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
|
|
|
|
attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
|
2021-11-05 20:05:08 +01:00
|
|
|
const float *data = (const float *)attr.value.data();
|
|
|
|
return set_attribute_float3(make_float3(data[0], data[1], data[2]), type, derivatives, val);
|
2020-10-26 18:23:40 +01:00
|
|
|
}
|
|
|
|
else if (attr.type == TypeFloat2) {
|
2021-11-05 20:05:08 +01:00
|
|
|
const float *data = (const float *)attr.value.data();
|
|
|
|
return set_attribute_float2(make_float2(data[0], data[1]), type, derivatives, val);
|
2020-10-26 18:23:40 +01:00
|
|
|
}
|
|
|
|
else if (attr.type == TypeDesc::TypeFloat) {
|
2021-11-05 20:05:08 +01:00
|
|
|
const float *data = (const float *)attr.value.data();
|
|
|
|
return set_attribute_float(data[0], type, derivatives, val);
|
2020-10-26 18:23:40 +01:00
|
|
|
}
|
|
|
|
else if (attr.type == TypeRGBA || attr.type == TypeDesc::TypeFloat4) {
|
2021-11-05 20:05:08 +01:00
|
|
|
const float *data = (const float *)attr.value.data();
|
|
|
|
return set_attribute_float4(
|
|
|
|
make_float4(data[0], data[1], data[2], data[3]), type, derivatives, val);
|
2020-10-26 18:23:40 +01:00
|
|
|
}
|
|
|
|
else if (attr.type == type) {
|
|
|
|
size_t datasize = attr.value.datasize();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-10-26 18:23:40 +01:00
|
|
|
memcpy(val, attr.value.data(), datasize);
|
|
|
|
if (derivatives) {
|
|
|
|
memset((char *)val + datasize, 0, datasize * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
|
|
|
ustring name,
|
|
|
|
TypeDesc type,
|
|
|
|
bool derivatives,
|
|
|
|
void *val)
|
2012-09-14 18:10:54 +00:00
|
|
|
{
|
2012-12-01 19:15:05 +00:00
|
|
|
/* todo: turn this into hash table? */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-14 19:09:25 +00:00
|
|
|
/* Object Attributes */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (name == u_object_location) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = object_location(kg, sd);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2019-08-22 14:26:09 +02:00
|
|
|
else if (name == u_object_color) {
|
|
|
|
float3 f = object_color(kg, sd->object);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
2022-03-07 17:34:52 +01:00
|
|
|
else if (name == u_object_alpha) {
|
|
|
|
float f = object_alpha(kg, sd->object);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_object_index) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = object_pass_id(kg, sd->object);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_geom_dupli_generated) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = object_dupli_generated(kg, sd->object);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-10-20 15:09:36 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_geom_dupli_uv) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = object_dupli_uv(kg, sd->object);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-10-20 15:09:36 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_material_index) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = shader_pass_id(kg, sd);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_object_random) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = object_random_number(kg, sd->object);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-14 19:09:25 +00:00
|
|
|
/* Particle Attributes */
|
2018-02-14 17:02:28 +01:00
|
|
|
else if (name == u_particle_index) {
|
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
|
|
|
float f = particle_index(kg, particle_id);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2018-02-14 14:32:38 +01:00
|
|
|
else if (name == u_particle_random) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
2019-08-21 20:04:09 +02:00
|
|
|
float f = hash_uint2_to_float(particle_index(kg, particle_id), 0);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_age) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = particle_age(kg, particle_id);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_lifetime) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
2014-05-05 02:19:08 +10:00
|
|
|
float f = particle_lifetime(kg, particle_id);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_location) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = particle_location(kg, particle_id);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
|
|
|
#if 0 /* unsupported */
|
2019-04-17 08:16:53 +02:00
|
|
|
else if (name == u_particle_rotation) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float4 f = particle_rotation(kg, particle_id);
|
|
|
|
return set_attribute_float4(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_size) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = particle_size(kg, particle_id);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_velocity) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = particle_velocity(kg, particle_id);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_particle_angular_velocity) {
|
2014-05-05 01:30:02 +10:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f = particle_angular_velocity(kg, particle_id);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
2012-09-14 18:10:54 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-29 01:57:32 +00:00
|
|
|
/* Geometry Attributes */
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_geom_numpolyvertices) {
|
2012-11-03 14:32:13 +00:00
|
|
|
return set_attribute_int(3, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if ((name == u_geom_trianglevertices || name == u_geom_polyvertices) &&
|
2021-12-20 02:52:56 +01:00
|
|
|
sd->type & PRIMITIVE_TRIANGLE) {
|
2012-11-03 14:32:13 +00:00
|
|
|
float3 P[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type & PRIMITIVE_MOTION) {
|
2014-03-29 13:03:47 +01:00
|
|
|
motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P);
|
2021-12-20 02:52:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
triangle_vertices(kg, sd->prim, P);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-23 11:31:19 +01:00
|
|
|
if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
2012-12-01 19:15:05 +00:00
|
|
|
object_position_transform(kg, sd, &P[0]);
|
|
|
|
object_position_transform(kg, sd, &P[1]);
|
|
|
|
object_position_transform(kg, sd, &P[2]);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:13 +00:00
|
|
|
return set_attribute_float3_3(P, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_geom_name) {
|
|
|
|
ustring object_name = kg->osl->object_names[sd->object];
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_string(object_name, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_is_smooth) {
|
2013-05-11 09:31:58 +00:00
|
|
|
float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2012-12-29 01:57:32 +00:00
|
|
|
/* Hair Attributes */
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_is_curve) {
|
2021-12-20 02:52:56 +01:00
|
|
|
float f = (sd->type & PRIMITIVE_CURVE) != 0;
|
2012-12-29 01:57:32 +00:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_curve_thickness) {
|
2013-01-03 12:08:54 +00:00
|
|
|
float f = curve_thickness(kg, sd);
|
2012-12-29 01:57:32 +00:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_curve_tangent_normal) {
|
2013-01-03 12:08:54 +00:00
|
|
|
float3 f = curve_tangent_normal(kg, sd);
|
2012-12-29 01:57:32 +00:00
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
2022-01-25 13:25:33 +01:00
|
|
|
else if (name == u_curve_random) {
|
|
|
|
float f = curve_random(kg, sd);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2021-12-01 17:30:46 +01:00
|
|
|
/* point attributes */
|
|
|
|
else if (name == u_is_point) {
|
2021-12-20 02:52:56 +01:00
|
|
|
float f = (sd->type & PRIMITIVE_POINT) != 0;
|
2021-12-01 17:30:46 +01:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else if (name == u_point_radius) {
|
|
|
|
float f = point_radius(kg, sd);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2022-01-25 13:25:33 +01:00
|
|
|
else if (name == u_point_position) {
|
|
|
|
float3 f = point_position(kg, sd);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else if (name == u_point_random) {
|
|
|
|
float f = point_random(kg, sd);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2021-10-04 12:19:18 +02:00
|
|
|
else if (name == u_normal_map_normal) {
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type & PRIMITIVE_TRIANGLE) {
|
2021-10-04 12:19:18 +02:00
|
|
|
float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v);
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-10-17 12:12:26 +00:00
|
|
|
return false;
|
2021-10-04 12:19:18 +02:00
|
|
|
}
|
2012-10-17 12:12:26 +00:00
|
|
|
}
|
2012-10-16 22:42:05 +00:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
|
|
|
ustring name,
|
|
|
|
TypeDesc type,
|
|
|
|
bool derivatives,
|
|
|
|
void *val)
|
2012-10-17 12:12:26 +00:00
|
|
|
{
|
2015-03-28 00:15:15 +05:00
|
|
|
if (name == u_path_ray_length) {
|
2013-06-08 10:51:33 +00:00
|
|
|
/* Ray Length */
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f = sd->ray_length;
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-10-16 22:42:05 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_path_ray_depth) {
|
2013-07-31 20:30:37 +00:00
|
|
|
/* Ray Depth */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
|
|
|
|
int f = (state) ? state->path.bounce : (shadow_state) ? shadow_state->shadow_path.bounce : 0;
|
2013-07-31 20:30:37 +00:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
2016-12-06 16:15:36 +01:00
|
|
|
}
|
|
|
|
else if (name == u_path_diffuse_depth) {
|
|
|
|
/* Diffuse Ray Depth */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
|
|
|
|
int f = (state) ? state->path.diffuse_bounce :
|
|
|
|
(shadow_state) ? shadow_state->shadow_path.diffuse_bounce :
|
|
|
|
0;
|
2016-12-06 16:15:36 +01:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else if (name == u_path_glossy_depth) {
|
|
|
|
/* Glossy Ray Depth */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
|
|
|
|
int f = (state) ? state->path.glossy_bounce :
|
|
|
|
(shadow_state) ? shadow_state->shadow_path.glossy_bounce :
|
|
|
|
0;
|
2016-12-06 16:15:36 +01:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else if (name == u_path_transmission_depth) {
|
|
|
|
/* Transmission Ray Depth */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
|
|
|
|
int f = (state) ? state->path.transmission_bounce :
|
|
|
|
(shadow_state) ? shadow_state->shadow_path.transmission_bounce :
|
|
|
|
0;
|
2016-12-06 16:15:36 +01:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
2013-07-31 20:30:37 +00:00
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_path_transparent_depth) {
|
2014-05-24 07:28:01 +02:00
|
|
|
/* Transparent Ray Depth */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
|
|
|
|
int f = (state) ? state->path.transparent_bounce :
|
|
|
|
(shadow_state) ? shadow_state->shadow_path.transparent_bounce :
|
|
|
|
0;
|
2014-04-21 14:20:29 +02:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-28 00:15:15 +05:00
|
|
|
else if (name == u_ndc) {
|
2021-02-05 16:23:34 +11:00
|
|
|
/* NDC coordinates with special exception for orthographic projection. */
|
2013-06-08 10:51:33 +00:00
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
|
|
|
float3 ndc[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:47 +01:00
|
|
|
if ((globals->raytype & PATH_RAY_CAMERA) && sd->object == OBJECT_NONE &&
|
|
|
|
kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
|
2013-06-08 10:51:33 +00:00
|
|
|
ndc[0] = camera_world_to_ndc(kg, sd, sd->ray_P);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-08 10:51:33 +00:00
|
|
|
if (derivatives) {
|
2022-07-13 16:54:53 +02:00
|
|
|
ndc[1] = zero_float3();
|
|
|
|
ndc[2] = zero_float3();
|
2013-06-08 10:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ndc[0] = camera_world_to_ndc(kg, sd, sd->P);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-08 10:51:33 +00:00
|
|
|
if (derivatives) {
|
|
|
|
ndc[1] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dx) - ndc[0];
|
|
|
|
ndc[2] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dy) - ndc[0];
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-08 10:51:33 +00:00
|
|
|
return set_attribute_float3(ndc, type, derivatives, val);
|
|
|
|
}
|
2012-09-14 18:10:54 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
bool OSLRenderServices::get_attribute(OSL::ShaderGlobals *sg,
|
|
|
|
bool derivatives,
|
|
|
|
ustring object_name,
|
2012-06-04 22:44:58 +00:00
|
|
|
TypeDesc type,
|
|
|
|
ustring name,
|
|
|
|
void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-07-11 22:39:51 +02:00
|
|
|
if (sg == NULL || sg->renderstate == NULL)
|
2014-06-05 02:29:48 +06:00
|
|
|
return false;
|
|
|
|
|
2014-07-24 23:07:49 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2014-08-05 17:53:00 +06:00
|
|
|
return get_attribute(sd, derivatives, object_name, type, name, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSLRenderServices::get_attribute(
|
|
|
|
ShaderData *sd, bool derivatives, ustring object_name, TypeDesc type, ustring name, void *val)
|
|
|
|
{
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2016-07-16 19:42:28 -04:00
|
|
|
int prim_type = 0;
|
2014-05-05 01:30:02 +10:00
|
|
|
int object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* lookup of attribute on another object */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object_name != u_empty) {
|
2019-05-14 12:13:43 +02:00
|
|
|
OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
if (it == kg->osl->object_name_map.end())
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
object = it->second;
|
|
|
|
}
|
2012-12-22 15:15:11 +00:00
|
|
|
else {
|
|
|
|
object = sd->object;
|
2016-07-16 19:42:28 -04:00
|
|
|
prim_type = attribute_primitive_type(kg, sd);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (object == OBJECT_NONE)
|
2012-12-22 15:15:11 +00:00
|
|
|
return get_background_attribute(kg, sd, name, type, derivatives, val);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* find attribute on object */
|
2016-07-16 19:42:28 -04:00
|
|
|
object = object * ATTR_PRIM_TYPES + prim_type;
|
2019-05-14 12:13:43 +02:00
|
|
|
OSLGlobals::AttributeMap &attribute_map = kg->osl->attribute_map[object];
|
2011-04-27 11:58:34 +00:00
|
|
|
OSLGlobals::AttributeMap::iterator it = attribute_map.find(name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (it != attribute_map.end()) {
|
2012-09-14 18:10:54 +00:00
|
|
|
const OSLGlobals::Attribute &attr = it->second;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
if (attr.desc.element != ATTR_ELEMENT_OBJECT) {
|
2012-09-14 18:10:54 +00:00
|
|
|
/* triangle and vertex attributes */
|
2019-02-19 15:41:22 +01:00
|
|
|
if (get_primitive_attribute(kg, sd, attr, type, derivatives, val))
|
2014-05-06 16:39:28 +02:00
|
|
|
return true;
|
|
|
|
else
|
2012-09-14 18:10:54 +00:00
|
|
|
return get_mesh_attribute(kg, sd, attr, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* object attribute */
|
2020-10-26 18:23:40 +01:00
|
|
|
return get_object_attribute(attr, type, derivatives, val);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-09-14 18:10:54 +00:00
|
|
|
/* not found in attribute, check standard object info */
|
2012-10-17 12:12:26 +00:00
|
|
|
bool is_std_object_attribute = get_object_standard_attribute(
|
|
|
|
kg, sd, name, type, derivatives, val);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (is_std_object_attribute)
|
2012-10-17 12:12:26 +00:00
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-04 22:31:32 +00:00
|
|
|
return get_background_attribute(kg, sd, name, type, derivatives, val);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 10:17:58 +02:00
|
|
|
bool OSLRenderServices::get_userdata(
|
|
|
|
bool derivatives, ustring name, TypeDesc type, OSL::ShaderGlobals *sg, void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
return false; /* disabled by lockgeom */
|
|
|
|
}
|
|
|
|
|
2020-04-28 13:46:36 +02:00
|
|
|
#if OSL_LIBRARY_VERSION_CODE >= 11100
|
|
|
|
TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename,
|
|
|
|
OSL::ShadingContext *)
|
|
|
|
#else
|
|
|
|
|
2018-10-26 19:26:06 +02:00
|
|
|
TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename)
|
2020-04-28 13:46:36 +02:00
|
|
|
#endif
|
2018-10-26 19:26:06 +02:00
|
|
|
{
|
2019-05-14 12:13:43 +02:00
|
|
|
OSLTextureHandleMap::iterator it = textures.find(filename);
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
/* For non-OIIO textures, just return a pointer to our own OSLTextureHandle. */
|
2019-05-14 12:13:43 +02:00
|
|
|
if (it != textures.end()) {
|
2019-05-02 12:40:24 +02:00
|
|
|
if (it->second->type != OSLTextureHandle::OIIO) {
|
|
|
|
return (TextureSystem::TextureHandle *)it->second.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get handle from OpenImageIO. */
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
TextureSystem::TextureHandle *handle = ts->get_texture_handle(filename);
|
|
|
|
if (handle == NULL) {
|
2018-10-26 19:26:06 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
/* Insert new OSLTextureHandle if needed. */
|
2019-05-14 12:13:43 +02:00
|
|
|
if (it == textures.end()) {
|
|
|
|
textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO));
|
|
|
|
it = textures.find(filename);
|
2018-10-26 19:26:06 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
/* Assign OIIO texture handle and return. */
|
|
|
|
it->second->oiio_handle = handle;
|
|
|
|
return (TextureSystem::TextureHandle *)it->second.get();
|
2018-10-26 19:26:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle)
|
|
|
|
{
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
|
|
|
|
|
|
|
|
if (handle->oiio_handle) {
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
return ts->good(handle->oiio_handle);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-26 19:26:06 +02:00
|
|
|
}
|
|
|
|
|
2015-12-18 21:42:04 +05:00
|
|
|
bool OSLRenderServices::texture(ustring filename,
|
|
|
|
TextureHandle *texture_handle,
|
|
|
|
TexturePerthread *texture_thread_info,
|
|
|
|
TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg,
|
|
|
|
float s,
|
|
|
|
float t,
|
|
|
|
float dsdx,
|
|
|
|
float dtdx,
|
|
|
|
float dsdy,
|
|
|
|
float dtdy,
|
|
|
|
int nchannels,
|
|
|
|
float *result,
|
|
|
|
float *dresultds,
|
2018-10-26 19:26:06 +02:00
|
|
|
float *dresultdt,
|
|
|
|
ustring *errormessage)
|
2015-12-18 21:42:04 +05:00
|
|
|
{
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
|
|
|
|
OSLTextureHandle::Type texture_type = (handle) ? handle->type : OSLTextureHandle::OIIO;
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
KernelGlobals kernel_globals = sd->osl_globals;
|
2017-08-18 18:37:05 +02:00
|
|
|
bool status = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
switch (texture_type) {
|
|
|
|
case OSLTextureHandle::BEVEL: {
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Bevel shader hack. */
|
|
|
|
if (nchannels >= 3) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
if (state) {
|
|
|
|
int num_samples = (int)s;
|
|
|
|
float radius = t;
|
|
|
|
float3 N = svm_bevel(kernel_globals, state, sd, radius, num_samples);
|
|
|
|
result[0] = N.x;
|
|
|
|
result[1] = N.y;
|
|
|
|
result[2] = N.z;
|
|
|
|
status = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
break;
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
case OSLTextureHandle::AO: {
|
2018-06-15 11:03:29 +02:00
|
|
|
/* AO shader hack. */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
const IntegratorStateCPU *state = sd->osl_path_state;
|
2021-10-17 16:22:20 +02:00
|
|
|
if (state) {
|
|
|
|
int num_samples = (int)s;
|
|
|
|
float radius = t;
|
|
|
|
float3 N = make_float3(dsdx, dtdx, dsdy);
|
|
|
|
int flags = 0;
|
|
|
|
if ((int)dtdy) {
|
|
|
|
flags |= NODE_AO_INSIDE;
|
|
|
|
}
|
|
|
|
if ((int)options.sblur) {
|
|
|
|
flags |= NODE_AO_ONLY_LOCAL;
|
|
|
|
}
|
|
|
|
if ((int)options.tblur) {
|
|
|
|
flags |= NODE_AO_GLOBAL_RADIUS;
|
|
|
|
}
|
|
|
|
result[0] = svm_ao(kernel_globals, state, sd, N, radius, num_samples, flags);
|
|
|
|
status = true;
|
2018-06-15 11:03:29 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
break;
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-27 00:46:37 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
case OSLTextureHandle::SVM: {
|
2022-05-11 20:11:44 -07:00
|
|
|
int id = -1;
|
|
|
|
if (handle->svm_slots[0].w == -1) {
|
|
|
|
/* Packed single texture. */
|
|
|
|
id = handle->svm_slots[0].y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Packed tiled texture. */
|
|
|
|
int tx = (int)s;
|
|
|
|
int ty = (int)t;
|
|
|
|
int tile = 1001 + 10 * ty + tx;
|
|
|
|
for (int4 tile_node : handle->svm_slots) {
|
|
|
|
if (tile_node.x == tile) {
|
|
|
|
id = tile_node.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tile_node.z == tile) {
|
|
|
|
id = tile_node.w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s -= tx;
|
|
|
|
t -= ty;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 rgba;
|
|
|
|
if (id == -1) {
|
|
|
|
rgba = make_float4(
|
|
|
|
TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B, TEX_IMAGE_MISSING_A);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rgba = kernel_tex_image_interp(kernel_globals, id, s, 1.0f - t);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
result[0] = rgba[0];
|
|
|
|
if (nchannels > 1)
|
|
|
|
result[1] = rgba[1];
|
|
|
|
if (nchannels > 2)
|
|
|
|
result[2] = rgba[2];
|
|
|
|
if (nchannels > 3)
|
|
|
|
result[3] = rgba[3];
|
|
|
|
status = true;
|
2019-05-02 12:40:24 +02:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
case OSLTextureHandle::IES: {
|
|
|
|
/* IES light. */
|
2022-05-11 20:11:44 -07:00
|
|
|
result[0] = kernel_ies_interp(kernel_globals, handle->svm_slots[0].y, s, t);
|
2019-05-02 12:40:24 +02:00
|
|
|
status = true;
|
|
|
|
break;
|
2015-12-18 21:42:04 +05:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
case OSLTextureHandle::OIIO: {
|
|
|
|
/* OpenImageIO texture cache. */
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
if (handle && handle->oiio_handle) {
|
|
|
|
if (texture_thread_info == NULL) {
|
|
|
|
OSLThreadData *tdata = kernel_globals->osl_tdata;
|
|
|
|
texture_thread_info = tdata->oiio_thread_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = ts->texture(handle->oiio_handle,
|
|
|
|
texture_thread_info,
|
|
|
|
options,
|
|
|
|
s,
|
|
|
|
t,
|
|
|
|
dsdx,
|
|
|
|
dtdx,
|
|
|
|
dsdy,
|
|
|
|
dtdy,
|
|
|
|
nchannels,
|
|
|
|
result,
|
|
|
|
dresultds,
|
|
|
|
dresultdt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = ts->texture(filename,
|
|
|
|
options,
|
|
|
|
s,
|
|
|
|
t,
|
|
|
|
dsdx,
|
|
|
|
dtdx,
|
|
|
|
dsdy,
|
|
|
|
dtdy,
|
|
|
|
nchannels,
|
|
|
|
result,
|
|
|
|
dresultds,
|
|
|
|
dresultdt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
/* This might be slow, but prevents error messages leak and
|
|
|
|
* other nasty stuff happening. */
|
|
|
|
ts->geterror();
|
|
|
|
}
|
2019-05-02 15:45:31 +02:00
|
|
|
else if (handle && handle->processor) {
|
|
|
|
ColorSpaceManager::to_scene_linear(handle->processor, result, nchannels);
|
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
break;
|
2014-06-12 13:26:48 +06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
if (!status) {
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 3 || nchannels == 4) {
|
2012-11-20 17:40:21 +00:00
|
|
|
result[0] = 1.0f;
|
|
|
|
result[1] = 0.0f;
|
|
|
|
result[2] = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-12-18 21:42:04 +05:00
|
|
|
bool OSLRenderServices::texture3d(ustring filename,
|
|
|
|
TextureHandle *texture_handle,
|
|
|
|
TexturePerthread *texture_thread_info,
|
|
|
|
TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg,
|
|
|
|
const OSL::Vec3 &P,
|
|
|
|
const OSL::Vec3 &dPdx,
|
|
|
|
const OSL::Vec3 &dPdy,
|
|
|
|
const OSL::Vec3 &dPdz,
|
|
|
|
int nchannels,
|
|
|
|
float *result,
|
|
|
|
float *dresultds,
|
|
|
|
float *dresultdt,
|
2019-01-02 19:55:26 +01:00
|
|
|
float *dresultdr,
|
|
|
|
ustring *errormessage)
|
2012-11-20 17:40:21 +00:00
|
|
|
{
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
|
|
|
|
OSLTextureHandle::Type texture_type = (handle) ? handle->type : OSLTextureHandle::OIIO;
|
|
|
|
bool status = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
switch (texture_type) {
|
|
|
|
case OSLTextureHandle::SVM: {
|
|
|
|
/* Packed texture. */
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
KernelGlobals kernel_globals = sd->osl_globals;
|
2022-05-11 20:11:44 -07:00
|
|
|
int slot = handle->svm_slots[0].y;
|
2020-03-17 16:48:00 +01:00
|
|
|
float3 P_float3 = make_float3(P.x, P.y, P.z);
|
|
|
|
float4 rgba = kernel_tex_image_interp_3d(kernel_globals, slot, P_float3, INTERPOLATION_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
result[0] = rgba[0];
|
|
|
|
if (nchannels > 1)
|
|
|
|
result[1] = rgba[1];
|
|
|
|
if (nchannels > 2)
|
|
|
|
result[2] = rgba[2];
|
|
|
|
if (nchannels > 3)
|
|
|
|
result[3] = rgba[3];
|
|
|
|
status = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OSLTextureHandle::OIIO: {
|
|
|
|
/* OpenImageIO texture cache. */
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
if (handle && handle->oiio_handle) {
|
|
|
|
if (texture_thread_info == NULL) {
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
KernelGlobals kernel_globals = sd->osl_globals;
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLThreadData *tdata = kernel_globals->osl_tdata;
|
|
|
|
texture_thread_info = tdata->oiio_thread_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = ts->texture3d(handle->oiio_handle,
|
|
|
|
texture_thread_info,
|
|
|
|
options,
|
|
|
|
P,
|
|
|
|
dPdx,
|
|
|
|
dPdy,
|
|
|
|
dPdz,
|
|
|
|
nchannels,
|
|
|
|
result,
|
|
|
|
dresultds,
|
|
|
|
dresultdt,
|
|
|
|
dresultdr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = ts->texture3d(filename,
|
|
|
|
options,
|
|
|
|
P,
|
|
|
|
dPdx,
|
|
|
|
dPdy,
|
|
|
|
dPdz,
|
|
|
|
nchannels,
|
|
|
|
result,
|
|
|
|
dresultds,
|
|
|
|
dresultdt,
|
|
|
|
dresultdr);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
if (!status) {
|
|
|
|
/* This might be slow, but prevents error messages leak and
|
|
|
|
* other nasty stuff happening. */
|
|
|
|
ts->geterror();
|
|
|
|
}
|
2019-05-02 15:45:31 +02:00
|
|
|
else if (handle && handle->processor) {
|
|
|
|
ColorSpaceManager::to_scene_linear(handle->processor, result, nchannels);
|
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
break;
|
2015-12-18 21:42:04 +05:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
case OSLTextureHandle::IES:
|
|
|
|
case OSLTextureHandle::AO:
|
|
|
|
case OSLTextureHandle::BEVEL: {
|
|
|
|
status = false;
|
|
|
|
break;
|
2015-04-06 23:29:29 +05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
if (!status) {
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 3 || nchannels == 4) {
|
2012-11-20 17:40:21 +00:00
|
|
|
result[0] = 1.0f;
|
|
|
|
result[1] = 0.0f;
|
|
|
|
result[2] = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-01-02 19:55:26 +01:00
|
|
|
bool OSLRenderServices::environment(ustring filename,
|
2019-05-02 12:40:24 +02:00
|
|
|
TextureHandle *texture_handle,
|
2019-01-02 19:55:26 +01:00
|
|
|
TexturePerthread *thread_info,
|
|
|
|
TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg,
|
|
|
|
const OSL::Vec3 &R,
|
|
|
|
const OSL::Vec3 &dRdx,
|
|
|
|
const OSL::Vec3 &dRdy,
|
|
|
|
int nchannels,
|
|
|
|
float *result,
|
|
|
|
float *dresultds,
|
|
|
|
float *dresultdt,
|
|
|
|
ustring *errormessage)
|
2012-11-20 17:40:21 +00:00
|
|
|
{
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
bool status = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
if (handle && handle->oiio_handle) {
|
|
|
|
if (thread_info == NULL) {
|
2019-05-14 12:13:43 +02:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2021-10-17 16:10:10 +02:00
|
|
|
KernelGlobals kernel_globals = sd->osl_globals;
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLThreadData *tdata = kernel_globals->osl_tdata;
|
|
|
|
thread_info = tdata->oiio_thread_info;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
status = ts->environment(handle->oiio_handle,
|
|
|
|
thread_info,
|
|
|
|
options,
|
|
|
|
R,
|
|
|
|
dRdx,
|
|
|
|
dRdy,
|
|
|
|
nchannels,
|
|
|
|
result,
|
|
|
|
dresultds,
|
|
|
|
dresultdt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = ts->environment(
|
|
|
|
filename, options, R, dRdx, dRdy, nchannels, result, dresultds, dresultdt);
|
2019-01-02 19:55:26 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
if (!status) {
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 3 || nchannels == 4) {
|
2012-11-20 17:40:21 +00:00
|
|
|
result[0] = 1.0f;
|
|
|
|
result[1] = 0.0f;
|
|
|
|
result[2] = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-04 15:49:28 +05:00
|
|
|
if (nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 15:45:31 +02:00
|
|
|
else if (handle && handle->processor) {
|
|
|
|
ColorSpaceManager::to_scene_linear(handle->processor, result, nchannels);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-04-28 13:46:36 +02:00
|
|
|
#if OSL_LIBRARY_VERSION_CODE >= 11100
|
|
|
|
bool OSLRenderServices::get_texture_info(ustring filename,
|
|
|
|
TextureHandle *texture_handle,
|
|
|
|
TexturePerthread *,
|
|
|
|
OSL::ShadingContext *,
|
|
|
|
int subimage,
|
|
|
|
ustring dataname,
|
|
|
|
TypeDesc datatype,
|
|
|
|
void *data,
|
|
|
|
ustring *)
|
|
|
|
#else
|
2019-01-02 19:55:26 +01:00
|
|
|
bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *sg,
|
|
|
|
ustring filename,
|
2019-05-02 12:40:24 +02:00
|
|
|
TextureHandle *texture_handle,
|
2019-01-02 19:55:26 +01:00
|
|
|
int subimage,
|
2012-11-20 17:40:21 +00:00
|
|
|
ustring dataname,
|
2019-01-02 19:55:26 +01:00
|
|
|
TypeDesc datatype,
|
|
|
|
void *data)
|
2020-04-28 13:46:36 +02:00
|
|
|
#endif
|
2012-11-20 17:40:21 +00:00
|
|
|
{
|
2019-05-02 12:40:24 +02:00
|
|
|
OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
|
|
|
|
|
|
|
|
/* No texture info for other texture types. */
|
|
|
|
if (handle && handle->type != OSLTextureHandle::OIIO) {
|
2019-05-04 18:49:37 +02:00
|
|
|
return false;
|
2018-10-26 19:26:06 +02:00
|
|
|
}
|
2019-05-02 12:40:24 +02:00
|
|
|
|
|
|
|
/* Get texture info from OpenImageIO. */
|
2019-05-14 12:13:43 +02:00
|
|
|
OSL::TextureSystem *ts = texture_system;
|
2019-05-02 12:40:24 +02:00
|
|
|
return ts->get_texture_info(filename, subimage, dataname, datatype, data);
|
2012-11-20 17:40:21 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 01:10:31 +00:00
|
|
|
int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg,
|
|
|
|
ustring filename,
|
|
|
|
const OSL::Vec3 ¢er,
|
2012-09-14 23:11:47 +00:00
|
|
|
float radius,
|
|
|
|
int max_points,
|
|
|
|
bool sort,
|
|
|
|
size_t *out_indices,
|
|
|
|
float *out_distances,
|
|
|
|
int derivs_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
return 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 22:48:32 +01:00
|
|
|
int OSLRenderServices::pointcloud_get(OSL::ShaderGlobals *sg,
|
|
|
|
ustring filename,
|
|
|
|
size_t *indices,
|
|
|
|
int count,
|
2012-09-14 23:11:47 +00:00
|
|
|
ustring attr_name,
|
|
|
|
TypeDesc attr_type,
|
|
|
|
void *out_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
return 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 22:48:32 +01:00
|
|
|
bool OSLRenderServices::pointcloud_write(OSL::ShaderGlobals *sg,
|
|
|
|
ustring filename,
|
|
|
|
const OSL::Vec3 &pos,
|
|
|
|
int nattribs,
|
|
|
|
const ustring *names,
|
|
|
|
const TypeDesc *types,
|
|
|
|
const void **data)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
bool OSLRenderServices::trace(TraceOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg,
|
|
|
|
const OSL::Vec3 &P,
|
|
|
|
const OSL::Vec3 &dPdx,
|
|
|
|
const OSL::Vec3 &dPdy,
|
|
|
|
const OSL::Vec3 &R,
|
|
|
|
const OSL::Vec3 &dRdx,
|
|
|
|
const OSL::Vec3 &dRdy)
|
|
|
|
{
|
|
|
|
/* todo: options.shader support, maybe options.traceset */
|
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
/* setup ray */
|
|
|
|
Ray ray;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
ray.P = TO_FLOAT3(P);
|
|
|
|
ray.D = TO_FLOAT3(R);
|
2022-07-13 16:54:53 +02:00
|
|
|
ray.tmin = 0.0f;
|
|
|
|
ray.tmax = (options.maxdist == 1.0e30f) ? FLT_MAX : options.maxdist - options.mindist;
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
ray.time = sd->time;
|
2022-02-23 18:38:51 +01:00
|
|
|
ray.self.object = OBJECT_NONE;
|
|
|
|
ray.self.prim = PRIM_NONE;
|
|
|
|
ray.self.light_object = OBJECT_NONE;
|
|
|
|
ray.self.light_prim = PRIM_NONE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
if (options.mindist == 0.0f) {
|
|
|
|
/* avoid self-intersections */
|
|
|
|
if (ray.P == sd->P) {
|
2022-02-23 18:38:51 +01:00
|
|
|
ray.self.object = sd->object;
|
|
|
|
ray.self.prim = sd->prim;
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* offset for minimum distance */
|
|
|
|
ray.P += options.mindist * ray.D;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
/* ray differentials */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
differential3 dP;
|
|
|
|
dP.dx = TO_FLOAT3(dPdx);
|
|
|
|
dP.dy = TO_FLOAT3(dPdy);
|
|
|
|
ray.dP = differential_make_compact(dP);
|
|
|
|
differential3 dD;
|
|
|
|
dD.dx = TO_FLOAT3(dRdx);
|
|
|
|
dD.dy = TO_FLOAT3(dRdy);
|
|
|
|
ray.dD = differential_make_compact(dD);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
/* allocate trace data */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
tracedata->ray = ray;
|
|
|
|
tracedata->setup = false;
|
2012-12-15 10:18:42 +00:00
|
|
|
tracedata->init = true;
|
2020-08-24 14:30:54 +02:00
|
|
|
tracedata->hit = false;
|
2019-05-14 12:13:43 +02:00
|
|
|
tracedata->sd.osl_globals = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-06-27 12:39:10 +02:00
|
|
|
|
2022-06-30 12:14:22 +10:00
|
|
|
/* Can't ray-trace from shaders like displacement, before BVH exists. */
|
2019-06-27 12:39:10 +02:00
|
|
|
if (kernel_data.bvh.bvh_layout == BVH_LAYOUT_NONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-30 12:14:22 +10:00
|
|
|
/* Ray-trace, leaving out shadow opaque to avoid early exit. */
|
2017-08-24 03:33:33 +02:00
|
|
|
uint visibility = PATH_RAY_ALL_VISIBILITY - PATH_RAY_SHADOW_OPAQUE;
|
2020-08-24 14:30:54 +02:00
|
|
|
tracedata->hit = scene_intersect(kg, &ray, visibility, &tracedata->isect);
|
|
|
|
return tracedata->hit;
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg,
|
|
|
|
ustring source,
|
|
|
|
ustring name,
|
|
|
|
TypeDesc type,
|
|
|
|
void *val,
|
|
|
|
bool derivatives)
|
|
|
|
{
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-15 10:18:42 +00:00
|
|
|
if (source == u_trace && tracedata->init) {
|
2012-12-01 19:15:05 +00:00
|
|
|
if (name == u_hit) {
|
2020-08-24 14:30:54 +02:00
|
|
|
return set_attribute_int(tracedata->hit, type, derivatives, val);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
}
|
2020-08-24 14:30:54 +02:00
|
|
|
else if (tracedata->hit) {
|
2012-12-01 19:15:05 +00:00
|
|
|
if (name == u_hitdist) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f[3] = {tracedata->isect.t, 0.0f, 0.0f};
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ShaderData *sd = &tracedata->sd;
|
2021-10-17 16:10:10 +02:00
|
|
|
const KernelGlobalsCPU *kg = sd->osl_globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
if (!tracedata->setup) {
|
|
|
|
/* lazy shader data setup */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
shader_setup_from_ray(kg, sd, &tracedata->ray, &tracedata->isect);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
tracedata->setup = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
if (name == u_N) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float3(sd->N, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_Ng) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return set_attribute_float3(sd->Ng, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_P) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f[3] = {sd->P, sd->dP.dx, sd->dP.dy};
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_I) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float3 f[3] = {sd->I, sd->dI.dx, sd->dI.dy};
|
|
|
|
return set_attribute_float3(f, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_u) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f[3] = {sd->u, sd->du.dx, sd->du.dy};
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
else if (name == u_v) {
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
float f[3] = {sd->v, sd->dv.dx, sd->dv.dy};
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-05 17:53:00 +06:00
|
|
|
return get_attribute(sd, derivatives, u_empty, type, name, val);
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|