2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2015-02-02 17:15:33 +00: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 19:48:28 +00:00
|
|
|
#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
|
2015-02-02 17:15:33 +00:00
|
|
|
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
2015-06-13 14:17:55 +00:00
|
|
|
# pragma GCC diagnostic ignored "-Wuninitialized"
|
2015-02-02 17:15:33 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
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
|
|
|
#include "osl_closures.h"
|
2012-12-01 19:15:05 +00:00
|
|
|
#include "osl_globals.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "osl_services.h"
|
|
|
|
#include "osl_shader.h"
|
|
|
|
|
|
|
|
#include "util_foreach.h"
|
2015-12-18 16:50:10 +00:00
|
|
|
#include "util_logging.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_string.h"
|
|
|
|
|
|
|
|
#include "kernel_compat_cpu.h"
|
|
|
|
#include "kernel_globals.h"
|
2014-03-29 12:03:45 +00:00
|
|
|
#include "kernel_random.h"
|
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
|
|
|
#include "kernel_projection.h"
|
|
|
|
#include "kernel_differential.h"
|
2014-03-29 12:03:48 +00:00
|
|
|
#include "kernel_montecarlo.h"
|
|
|
|
#include "kernel_camera.h"
|
2016-05-20 14:46:49 +00:00
|
|
|
#include "kernels/cpu/kernel_cpu_image.h"
|
2014-03-29 12:03:48 +00:00
|
|
|
#include "geom/geom.h"
|
2016-07-11 10:28:45 +00:00
|
|
|
#include "bvh/bvh.h"
|
2014-03-29 12:03:48 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
#include "kernel_projection.h"
|
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
|
|
|
#include "kernel_accumulate.h"
|
|
|
|
#include "kernel_shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-11-28 00:38:23 +00:00
|
|
|
#ifdef WITH_PTEX
|
2016-02-12 17:33:43 +00:00
|
|
|
# include <Ptexture.h>
|
2013-11-28 00:38:23 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* RenderServices implementation */
|
|
|
|
|
2014-05-04 17:49:22 +00:00
|
|
|
#define COPY_MATRIX44(m1, m2) { \
|
|
|
|
CHECK_TYPE(m1, OSL::Matrix44*); \
|
|
|
|
CHECK_TYPE(m2, Transform*); \
|
|
|
|
memcpy(m1, m2, sizeof(*m2)); \
|
|
|
|
} (void)0
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* static ustrings */
|
|
|
|
ustring OSLRenderServices::u_distance("distance");
|
|
|
|
ustring OSLRenderServices::u_index("index");
|
2014-05-06 14:39:28 +00: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");
|
|
|
|
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");
|
|
|
|
ustring OSLRenderServices::u_particle_index("particle:index");
|
|
|
|
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 15:44:25 +00:00
|
|
|
ustring OSLRenderServices::u_geom_undisplaced("geom:undisplaced");
|
2013-05-11 09:31:58 +00:00
|
|
|
ustring OSLRenderServices::u_is_smooth("geom:is_smooth");
|
2012-12-29 01:57:32 +00:00
|
|
|
#ifdef __HAIR__
|
2013-01-03 12:08:54 +00:00
|
|
|
ustring OSLRenderServices::u_is_curve("geom:is_curve");
|
|
|
|
ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness");
|
|
|
|
ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal");
|
2012-12-29 01:57:32 +00:00
|
|
|
#endif
|
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");
|
2014-04-21 12:20:29 +00:00
|
|
|
ustring OSLRenderServices::u_path_transparent_depth("path:transparent_depth");
|
2016-01-06 22:38:13 +00: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;
|
|
|
|
|
|
|
|
OSLRenderServices::OSLRenderServices()
|
|
|
|
{
|
|
|
|
kernel_globals = NULL;
|
2013-09-03 22:39:21 +00:00
|
|
|
osl_ts = NULL;
|
2013-11-28 00:38:23 +00:00
|
|
|
|
|
|
|
#ifdef WITH_PTEX
|
|
|
|
size_t maxmem = 16384 * 1024;
|
|
|
|
ptex_cache = PtexCache::create(0, maxmem);
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSLRenderServices::~OSLRenderServices()
|
|
|
|
{
|
2016-08-17 12:42:10 +00:00
|
|
|
if(osl_ts) {
|
|
|
|
VLOG(2) << "OSL texture system stats:\n"
|
|
|
|
<< osl_ts->getstats();
|
|
|
|
}
|
2013-11-28 00:38:23 +00:00
|
|
|
#ifdef WITH_PTEX
|
|
|
|
ptex_cache->release();
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 13:05:21 +00:00
|
|
|
void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_, OSL::TextureSystem *osl_ts_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
kernel_globals = kernel_globals_;
|
2013-06-28 13:05:21 +00:00
|
|
|
osl_ts = osl_ts_;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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-27 19:15:15 +00:00
|
|
|
if(xform) {
|
2012-06-04 22:44:58 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2011-04-27 11:58:34 +00:00
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-27 19:15:15 +00: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)
|
|
|
|
tfm = sd->ob_tfm;
|
|
|
|
else
|
|
|
|
tfm = object_fetch_transform_motion_test(kg, object, time, NULL);
|
2012-10-16 10:59:35 +00:00
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
tfm = transform_transpose(tfm);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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-27 19:15:15 +00:00
|
|
|
if(xform) {
|
2012-06-04 22:44:58 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2011-04-27 11:58:34 +00:00
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-27 19:15:15 +00: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)
|
|
|
|
itfm = sd->ob_itfm;
|
|
|
|
else
|
|
|
|
object_fetch_transform_motion_test(kg, object, time, &itfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
#else
|
|
|
|
Transform itfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
|
|
|
|
#endif
|
|
|
|
itfm = transform_transpose(itfm);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &itfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from, float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
KernelGlobals *kg = kernel_globals;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(from == u_ndc) {
|
2012-10-18 13:16:57 +00:00
|
|
|
Transform tfm = transform_transpose(transform_quick_inverse(kernel_data.cam.worldtondc));
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_raster) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.rastertoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_screen) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.screentoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_camera) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.cameratoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_world) {
|
2014-05-06 14:39:28 +00:00
|
|
|
result.makeIdentity();
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring to, float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
KernelGlobals *kg = kernel_globals;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(to == u_ndc) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtondc);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_raster) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtoraster);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_screen) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtoscreen);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_camera) {
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtocamera);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_world) {
|
2014-05-06 14:39:28 +00:00
|
|
|
result.makeIdentity();
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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-27 19:15:15 +00:00
|
|
|
if(xform) {
|
2012-10-16 10:59:35 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(object != OBJECT_NONE) {
|
2012-10-16 10:59:35 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
|
|
|
Transform tfm = sd->ob_tfm;
|
|
|
|
#else
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
|
|
|
|
#endif
|
|
|
|
tfm = transform_transpose(tfm);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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-27 19:15:15 +00:00
|
|
|
if(xform) {
|
2012-10-16 10:59:35 +00:00
|
|
|
const ShaderData *sd = (const ShaderData *)xform;
|
|
|
|
int object = sd->object;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(object != OBJECT_NONE) {
|
2012-10-16 10:59:35 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
|
|
|
Transform tfm = sd->ob_itfm;
|
|
|
|
#else
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
|
|
|
|
#endif
|
|
|
|
tfm = transform_transpose(tfm);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-09-02 01:10:31 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from)
|
2012-09-02 01:10:31 +00:00
|
|
|
{
|
2012-10-16 10:59:35 +00:00
|
|
|
KernelGlobals *kg = kernel_globals;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(from == u_ndc) {
|
2012-10-18 12:45:27 +00:00
|
|
|
Transform tfm = transform_transpose(transform_quick_inverse(kernel_data.cam.worldtondc));
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_raster) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.rastertoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_screen) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.screentoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(from == u_camera) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.cameratoworld);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring to)
|
2012-10-16 10:59:35 +00:00
|
|
|
{
|
|
|
|
KernelGlobals *kg = kernel_globals;
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(to == u_ndc) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtondc);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_raster) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtoraster);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_screen) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtoscreen);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(to == u_camera) {
|
2012-10-16 10:59:35 +00:00
|
|
|
Transform tfm = transform_transpose(kernel_data.cam.worldtocamera);
|
2012-12-15 10:18:42 +00:00
|
|
|
COPY_MATRIX44(&result, &tfm);
|
2012-10-16 10:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-09-02 01:10:31 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor)
|
2012-09-14 23:11:47 +00:00
|
|
|
{
|
2012-10-20 15:09:36 +00:00
|
|
|
float *fval = (float *)val;
|
|
|
|
|
|
|
|
fval[0] = f[0].x;
|
|
|
|
fval[1] = f[0].y;
|
|
|
|
fval[2] = f[0].z;
|
|
|
|
|
2015-03-27 19:15:15 +00: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;
|
|
|
|
|
|
|
|
fval[6] = f[2].x;
|
|
|
|
fval[7] = f[2].y;
|
|
|
|
fval[8] = f[2].z;
|
2012-09-14 18:10:54 +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
|
|
|
|
|
|
|
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]);
|
2012-10-20 15:09:36 +00:00
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(derivatives) {
|
2012-09-14 18:10:54 +00:00
|
|
|
fval[1] = average(f[1]);
|
|
|
|
fval[2] = average(f[2]);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor)
|
2012-09-14 23:11:47 +00:00
|
|
|
{
|
2012-10-20 15:09:36 +00:00
|
|
|
float *fval = (float *)val;
|
|
|
|
fval[0] = f[0];
|
|
|
|
fval[1] = f[1];
|
|
|
|
fval[2] = f[2];
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(derivatives) {
|
2012-10-20 15:09:36 +00:00
|
|
|
fval[3] = f[1];
|
|
|
|
fval[4] = f[1];
|
|
|
|
fval[5] = f[1];
|
|
|
|
|
|
|
|
fval[6] = f[2];
|
|
|
|
fval[7] = f[2];
|
|
|
|
fval[8] = f[2];
|
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
|
|
|
|
|
|
|
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];
|
2012-10-20 15:09:36 +00:00
|
|
|
|
2015-03-27 19:15:15 +00: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
|
|
|
}
|
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
|
|
|
}
|
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-27 19:15:15 +00: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 11:53:00 +00: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-27 19:15:15 +00: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-27 19:15:15 +00: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 16:33:55 +00:00
|
|
|
static bool set_attribute_matrix(const Transform& tfm, TypeDesc type, void *val)
|
|
|
|
{
|
|
|
|
if(type == TypeDesc::TypeMatrix) {
|
|
|
|
Transform transpose = transform_transpose(tfm);
|
|
|
|
memcpy(val, &transpose, sizeof(Transform));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get_mesh_element_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr,
|
2012-09-14 18:10:54 +00:00
|
|
|
const TypeDesc& type, bool derivatives, void *val)
|
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
|
|
|
|
attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor)
|
2014-05-04 16:19:08 +00:00
|
|
|
{
|
2012-09-14 18:10:54 +00:00
|
|
|
float3 fval[3];
|
2016-07-01 21:36:27 +00:00
|
|
|
fval[0] = primitive_attribute_float3(kg, sd, attr.desc,
|
2013-01-03 12:08:54 +00:00
|
|
|
(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
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(attr.type == TypeDesc::TypeFloat) {
|
2012-11-04 22:31:32 +00:00
|
|
|
float fval[3];
|
2016-07-01 21:36:27 +00:00
|
|
|
fval[0] = primitive_attribute_float(kg, sd, attr.desc,
|
2013-01-03 12:08:54 +00:00
|
|
|
(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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-31 16:33:55 +00:00
|
|
|
static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr,
|
|
|
|
const TypeDesc& type, bool derivatives, void *val)
|
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(attr.type == TypeDesc::TypeMatrix) {
|
2016-07-01 21:36:27 +00:00
|
|
|
Transform tfm = primitive_attribute_matrix(kg, sd, attr.desc);
|
2013-12-31 16:33:55 +00:00
|
|
|
return set_attribute_matrix(tfm, type, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivatives, void *val)
|
|
|
|
{
|
|
|
|
size_t datasize = attr.value.datasize();
|
|
|
|
|
|
|
|
memcpy(val, attr.value.data(), datasize);
|
2015-03-27 19:15:15 +00:00
|
|
|
if(derivatives)
|
2012-06-04 22:44:58 +00:00
|
|
|
memset((char *)val + datasize, 0, datasize * 2);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, 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? */
|
2012-11-03 14:32:13 +00:00
|
|
|
|
2012-09-14 19:09:25 +00:00
|
|
|
/* Object Attributes */
|
2015-03-27 19:15:15 +00: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
|
|
|
}
|
2015-03-27 19:15:15 +00: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-27 19:15:15 +00: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-27 19:15:15 +00: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-27 19:15:15 +00: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-27 19:15:15 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
/* Particle Attributes */
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_index) {
|
2014-05-04 15:30:02 +00: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_index(kg, particle_id);
|
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
2012-09-14 19:09:25 +00:00
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_age) {
|
2014-05-04 15:30:02 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_lifetime) {
|
2014-05-04 15:30:02 +00:00
|
|
|
int particle_id = object_particle_id(kg, sd->object);
|
2014-05-04 16:19:08 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_location) {
|
2014-05-04 15:30:02 +00: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 */
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_rotation) {
|
2014-05-04 15:30:02 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_size) {
|
2014-05-04 15:30:02 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_velocity) {
|
2014-05-04 15:30:02 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_particle_angular_velocity) {
|
2014-05-04 15:30:02 +00: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
|
|
|
}
|
2012-12-29 01:57:32 +00:00
|
|
|
|
|
|
|
/* Geometry Attributes */
|
2015-03-27 19:15:15 +00: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-27 19:15:15 +00:00
|
|
|
else if((name == u_geom_trianglevertices || name == u_geom_polyvertices)
|
2013-01-09 21:09:20 +00:00
|
|
|
#ifdef __HAIR__
|
2014-05-04 16:19:08 +00:00
|
|
|
&& sd->type & PRIMITIVE_ALL_TRIANGLE)
|
2013-01-09 21:09:20 +00:00
|
|
|
#else
|
2014-05-04 16:19:08 +00:00
|
|
|
)
|
2013-01-09 21:09:20 +00:00
|
|
|
#endif
|
2014-05-04 16:19:08 +00:00
|
|
|
{
|
2012-11-03 14:32:13 +00:00
|
|
|
float3 P[3];
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
if(sd->type & PRIMITIVE_TRIANGLE)
|
|
|
|
triangle_vertices(kg, sd->prim, P);
|
|
|
|
else
|
|
|
|
motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P);
|
2012-12-01 19:15:05 +00:00
|
|
|
|
|
|
|
if(!(sd->flag & SD_TRANSFORM_APPLIED)) {
|
|
|
|
object_position_transform(kg, sd, &P[0]);
|
|
|
|
object_position_transform(kg, sd, &P[1]);
|
|
|
|
object_position_transform(kg, sd, &P[2]);
|
|
|
|
}
|
|
|
|
|
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-27 19:15:15 +00: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
|
|
|
#ifdef __HAIR__
|
|
|
|
/* Hair Attributes */
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_is_curve) {
|
2014-03-29 12:03:46 +00:00
|
|
|
float f = (sd->type & PRIMITIVE_ALL_CURVE) != 0;
|
2012-12-29 01:57:32 +00:00
|
|
|
return set_attribute_float(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-27 19:15:15 +00: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-27 19:15:15 +00: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);
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-17 12:12:26 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-16 22:42:05 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
bool OSLRenderServices::get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
|
|
|
|
TypeDesc type, bool derivatives, void *val)
|
2012-10-17 12:12:26 +00:00
|
|
|
{
|
2015-03-27 19:15:15 +00: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-27 19:15:15 +00:00
|
|
|
else if(name == u_path_ray_depth) {
|
2013-07-31 20:30:37 +00:00
|
|
|
/* Ray Depth */
|
2016-01-06 22:38:13 +00:00
|
|
|
PathState *state = sd->osl_path_state;
|
|
|
|
int f = state->bounce;
|
2013-07-31 20:30:37 +00:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_path_transparent_depth) {
|
2014-05-24 05:28:01 +00:00
|
|
|
/* Transparent Ray Depth */
|
2016-01-06 22:38:13 +00:00
|
|
|
PathState *state = sd->osl_path_state;
|
|
|
|
int f = state->transparent_bounce;
|
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else if(name == u_path_transmission_depth) {
|
|
|
|
/* Transmission Ray Depth */
|
|
|
|
PathState *state = sd->osl_path_state;
|
|
|
|
int f = state->transmission_bounce;
|
2014-04-21 12:20:29 +00:00
|
|
|
return set_attribute_int(f, type, derivatives, val);
|
|
|
|
}
|
2015-03-27 19:15:15 +00:00
|
|
|
else if(name == u_ndc) {
|
2013-06-08 10:51:33 +00:00
|
|
|
/* NDC coordinates with special exception for otho */
|
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
|
|
|
float3 ndc[3];
|
|
|
|
|
2014-03-29 12:03:47 +00: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);
|
|
|
|
|
|
|
|
if(derivatives) {
|
|
|
|
ndc[1] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dx) - ndc[0];
|
|
|
|
ndc[2] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dy) - ndc[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ndc[0] = camera_world_to_ndc(kg, sd, sd->P);
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_attribute_float3(ndc, type, derivatives, val);
|
|
|
|
}
|
2012-09-14 18:10:54 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00: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
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(sg->renderstate == NULL)
|
2014-06-04 20:29:48 +00:00
|
|
|
return false;
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
2014-08-05 11:53:00 +00: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)
|
|
|
|
{
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2016-07-16 23:42:28 +00:00
|
|
|
int prim_type = 0;
|
2014-05-04 15:30:02 +00:00
|
|
|
int object;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* lookup of attribute on another object */
|
2015-03-27 19:15:15 +00:00
|
|
|
if(object_name != u_empty) {
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(it == kg->osl->object_name_map.end())
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
object = it->second;
|
|
|
|
}
|
2012-12-22 15:15:11 +00:00
|
|
|
else {
|
|
|
|
object = sd->object;
|
2016-07-16 23:42:28 +00:00
|
|
|
prim_type = attribute_primitive_type(kg, sd);
|
2012-12-22 15:15:11 +00:00
|
|
|
|
2015-03-27 19:15:15 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
/* find attribute on object */
|
2016-07-16 23:42:28 +00:00
|
|
|
object = object*ATTR_PRIM_TYPES + prim_type;
|
2012-12-01 19:15:05 +00: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);
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(it != attribute_map.end()) {
|
2012-09-14 18:10:54 +00:00
|
|
|
const OSLGlobals::Attribute& attr = it->second;
|
2012-11-04 22:31:32 +00:00
|
|
|
|
2016-07-01 21:36:27 +00:00
|
|
|
if(attr.desc.element != ATTR_ELEMENT_OBJECT) {
|
2012-09-14 18:10:54 +00:00
|
|
|
/* triangle and vertex attributes */
|
2014-05-06 14:39:28 +00:00
|
|
|
if(get_mesh_element_attribute(kg, sd, attr, type, derivatives, val))
|
|
|
|
return true;
|
|
|
|
else
|
2012-09-14 18:10:54 +00:00
|
|
|
return get_mesh_attribute(kg, sd, attr, type, derivatives, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* object attribute */
|
|
|
|
get_object_attribute(attr, derivatives, val);
|
|
|
|
return true;
|
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);
|
2012-11-04 22:31:32 +00:00
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(is_std_object_attribute)
|
2012-10-17 12:12:26 +00:00
|
|
|
return true;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSLRenderServices::get_userdata(bool derivatives, ustring name, TypeDesc type,
|
2014-07-24 21:07:49 +00:00
|
|
|
OSL::ShaderGlobals *sg, void *val)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
return false; /* disabled by lockgeom */
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:07:49 +00:00
|
|
|
bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, OSL::ShaderGlobals *sg)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
return false; /* never called by OSL */
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:42:04 +00: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,
|
|
|
|
float *dresultdt)
|
|
|
|
{
|
|
|
|
OSL::TextureSystem *ts = osl_ts;
|
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
|
|
|
|
|
|
|
if(texture_thread_info == NULL) {
|
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
|
|
|
texture_thread_info = tdata->oiio_thread_info;
|
|
|
|
}
|
2013-11-28 00:38:23 +00:00
|
|
|
|
|
|
|
#ifdef WITH_PTEX
|
|
|
|
/* todo: this is just a quick hack, only works with particular files and options */
|
|
|
|
if(string_endswith(filename.string(), ".ptx")) {
|
|
|
|
float2 uv;
|
|
|
|
int faceid;
|
|
|
|
|
|
|
|
if(!primitive_ptex(kg, sd, &uv, &faceid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
float u = uv.x;
|
|
|
|
float v = uv.y;
|
|
|
|
float dudx = 0.0f;
|
|
|
|
float dvdx = 0.0f;
|
|
|
|
float dudy = 0.0f;
|
|
|
|
float dvdy = 0.0f;
|
|
|
|
|
|
|
|
Ptex::String error;
|
|
|
|
PtexPtr<PtexTexture> r(ptex_cache->get(filename.c_str(), error));
|
|
|
|
|
|
|
|
if(!r) {
|
|
|
|
//std::cerr << error.c_str() << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mipmaplerp = false;
|
|
|
|
float sharpness = 1.0f;
|
|
|
|
PtexFilter::Options opts(PtexFilter::f_bicubic, mipmaplerp, sharpness);
|
|
|
|
PtexPtr<PtexFilter> f(PtexFilter::getFilter(r, opts));
|
|
|
|
|
2014-11-04 10:49:28 +00:00
|
|
|
f->eval(result, options.firstchannel, nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy);
|
2013-11-28 00:38:23 +00:00
|
|
|
|
2014-11-04 10:49:28 +00:00
|
|
|
for(int c = r->numChannels(); c < nchannels; c++)
|
2013-11-28 00:38:23 +00:00
|
|
|
result[c] = result[0];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2014-06-12 07:26:48 +00:00
|
|
|
bool status;
|
2013-11-28 00:38:23 +00:00
|
|
|
|
2016-07-03 11:08:21 +00:00
|
|
|
if(filename.length() && filename[0] == '@') {
|
2014-11-08 12:28:40 +00:00
|
|
|
int slot = atoi(filename.c_str() + 1);
|
2014-06-12 07:26:48 +00:00
|
|
|
float4 rgba = kernel_tex_image_interp(slot, s, 1.0f - t);
|
2013-08-05 12:49:15 +00:00
|
|
|
|
2014-06-12 07:26:48 +00:00
|
|
|
result[0] = rgba[0];
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels > 1)
|
2014-06-12 07:26:48 +00:00
|
|
|
result[1] = rgba[1];
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels > 2)
|
2014-06-12 07:26:48 +00:00
|
|
|
result[2] = rgba[2];
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels > 3)
|
2014-06-12 07:26:48 +00:00
|
|
|
result[3] = rgba[3];
|
|
|
|
status = true;
|
|
|
|
}
|
|
|
|
else {
|
2015-12-18 16:42:04 +00:00
|
|
|
if(texture_handle != NULL) {
|
|
|
|
status = ts->texture(texture_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);
|
|
|
|
}
|
2014-06-12 07:26:48 +00:00
|
|
|
}
|
2012-11-20 17:40:21 +00:00
|
|
|
|
|
|
|
if(!status) {
|
2014-11-04 10:49:28 +00: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;
|
|
|
|
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
2016-01-06 18:09:48 +00:00
|
|
|
/* This might be slow, but prevents error messages leak and
|
|
|
|
* other nasty stuff happening.
|
|
|
|
*/
|
|
|
|
string err = ts->geterror();
|
|
|
|
(void)err;
|
2012-11-20 17:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:42:04 +00: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,
|
|
|
|
float *dresultdr)
|
2012-11-20 17:40:21 +00:00
|
|
|
{
|
2013-06-28 13:05:21 +00:00
|
|
|
OSL::TextureSystem *ts = osl_ts;
|
2013-08-05 12:49:15 +00:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
2015-12-18 16:42:04 +00:00
|
|
|
|
|
|
|
if(texture_thread_info == NULL) {
|
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
|
|
|
texture_thread_info = tdata->oiio_thread_info;
|
|
|
|
}
|
|
|
|
|
2015-04-06 18:29:29 +00:00
|
|
|
bool status;
|
2016-07-03 11:08:21 +00:00
|
|
|
if(filename.length() && filename[0] == '@') {
|
2015-04-06 18:29:29 +00:00
|
|
|
int slot = atoi(filename.c_str() + 1);
|
|
|
|
float4 rgba = kernel_tex_image_interp_3d(slot, P.x, P.y, P.z);
|
2013-08-05 12:49:15 +00:00
|
|
|
|
2015-04-06 18:29:29 +00: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;
|
|
|
|
}
|
|
|
|
else {
|
2015-12-18 16:42:04 +00:00
|
|
|
if(texture_handle != NULL) {
|
|
|
|
status = ts->texture3d(texture_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);
|
|
|
|
}
|
2015-04-06 18:29:29 +00:00
|
|
|
}
|
2012-11-20 17:40:21 +00:00
|
|
|
|
|
|
|
if(!status) {
|
2014-11-04 10:49:28 +00: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;
|
|
|
|
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
2016-01-06 18:09:48 +00:00
|
|
|
/* This might be slow, but prevents error messages leak and
|
|
|
|
* other nasty stuff happening.
|
|
|
|
*/
|
|
|
|
string err = ts->geterror();
|
|
|
|
(void)err;
|
2012-11-20 17:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
2014-11-04 10:49:28 +00:00
|
|
|
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy,
|
|
|
|
int nchannels, float *result)
|
2012-11-20 17:40:21 +00:00
|
|
|
{
|
2013-06-28 13:05:21 +00:00
|
|
|
OSL::TextureSystem *ts = osl_ts;
|
2013-08-05 12:49:15 +00:00
|
|
|
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
|
|
|
OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
|
|
|
|
|
2015-04-06 19:25:54 +00:00
|
|
|
OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
|
2014-11-04 10:49:28 +00:00
|
|
|
|
|
|
|
bool status = ts->environment(th, thread_info,
|
|
|
|
options, R, dRdx, dRdy,
|
|
|
|
nchannels, result);
|
2012-11-20 17:40:21 +00:00
|
|
|
|
|
|
|
if(!status) {
|
2014-11-04 10:49:28 +00: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;
|
|
|
|
|
2014-11-04 10:49:28 +00:00
|
|
|
if(nchannels == 4)
|
2012-11-20 17:40:21 +00:00
|
|
|
result[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-07-25 09:23:15 +00:00
|
|
|
bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *sg, ustring filename, int subimage,
|
2012-11-20 17:40:21 +00:00
|
|
|
ustring dataname,
|
|
|
|
TypeDesc datatype, void *data)
|
|
|
|
{
|
2013-06-28 13:05:21 +00:00
|
|
|
OSL::TextureSystem *ts = osl_ts;
|
2012-11-20 17:40:21 +00:00
|
|
|
return ts->get_texture_info(filename, subimage, dataname, datatype, data);
|
|
|
|
}
|
|
|
|
|
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 21:48:32 +00: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 21:48:32 +00: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);
|
|
|
|
|
|
|
|
/* setup ray */
|
|
|
|
Ray ray;
|
|
|
|
|
|
|
|
ray.P = TO_FLOAT3(P);
|
|
|
|
ray.D = TO_FLOAT3(R);
|
2014-10-08 08:58:40 +00:00
|
|
|
ray.t = (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;
|
|
|
|
|
|
|
|
if(options.mindist == 0.0f) {
|
|
|
|
/* avoid self-intersections */
|
|
|
|
if(ray.P == sd->P) {
|
|
|
|
bool transmit = (dot(sd->Ng, ray.D) < 0.0f);
|
|
|
|
ray.P = ray_offset(sd->P, (transmit)? -sd->Ng: sd->Ng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* offset for minimum distance */
|
|
|
|
ray.P += options.mindist*ray.D;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ray differentials */
|
|
|
|
ray.dP.dx = TO_FLOAT3(dPdx);
|
|
|
|
ray.dP.dy = TO_FLOAT3(dPdy);
|
|
|
|
ray.dD.dx = TO_FLOAT3(dRdx);
|
|
|
|
ray.dD.dy = TO_FLOAT3(dRdy);
|
|
|
|
|
|
|
|
/* 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;
|
2014-03-01 13:57:25 +00:00
|
|
|
tracedata->sd.osl_globals = sd->osl_globals;
|
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
|
|
|
|
|
|
|
/* raytrace */
|
2014-03-29 12:03:47 +00:00
|
|
|
return scene_intersect(sd->osl_globals, &ray, PATH_RAY_ALL_VISIBILITY, &tracedata->isect, NULL, 0.0f, 0.0f);
|
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;
|
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
|
|
|
|
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) {
|
2014-03-29 12:03:47 +00:00
|
|
|
return set_attribute_int((tracedata->isect.prim != PRIM_NONE), 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
|
|
|
}
|
2014-03-29 12:03:47 +00:00
|
|
|
else if(tracedata->isect.prim != PRIM_NONE) {
|
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;
|
2013-04-22 14:27:12 +00:00
|
|
|
KernelGlobals *kg = sd->osl_globals;
|
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 */
|
2016-01-06 22:38:13 +00:00
|
|
|
shader_setup_from_ray(kg, sd, &tracedata->isect, &tracedata->ray);
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-08-05 11:53:00 +00: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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|