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
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OSL_SERVICES_H__
|
|
|
|
#define __OSL_SERVICES_H__
|
|
|
|
|
|
|
|
/* OSL Render Services
|
|
|
|
*
|
|
|
|
* Implementation of OSL render services, to retriever matrices, attributes,
|
|
|
|
* textures and point clouds. In principle this should only be accessing
|
|
|
|
* kernel data, but currently we also reach back into the Scene to retrieve
|
|
|
|
* attributes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
#include <OSL/oslclosure.h>
|
|
|
|
|
2013-11-28 00:38:23 +00:00
|
|
|
#ifdef WITH_PTEX
|
|
|
|
class PtexCache;
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Object;
|
|
|
|
class Scene;
|
|
|
|
class Shader;
|
2012-09-05 20:50:10 +00:00
|
|
|
struct ShaderData;
|
|
|
|
struct float3;
|
|
|
|
struct KernelGlobals;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
class OSLRenderServices : public OSL::RendererServices
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OSLRenderServices();
|
|
|
|
~OSLRenderServices();
|
|
|
|
|
2013-06-28 13:05:21 +00:00
|
|
|
void thread_init(KernelGlobals *kernel_globals, OSL::TextureSystem *ts);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
|
|
|
|
bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
|
2012-09-02 01:10:31 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool get_matrix(OSL::Matrix44 &result, ustring from, float time);
|
|
|
|
bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time);
|
2012-09-02 01:10:31 +00:00
|
|
|
|
|
|
|
bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform);
|
2012-10-16 10:59:35 +00:00
|
|
|
bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform);
|
|
|
|
|
2012-09-02 01:10:31 +00:00
|
|
|
bool get_matrix(OSL::Matrix44 &result, ustring from);
|
2012-10-16 10:59:35 +00:00
|
|
|
bool get_inverse_matrix(OSL::Matrix44 &result, ustring from);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
bool get_array_attribute(void *renderstate, 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
|
|
|
bool get_attribute(void *renderstate, bool derivatives, ustring object,
|
2012-06-04 22:44:58 +00:00
|
|
|
TypeDesc type, ustring name, void *val);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
bool get_userdata(bool derivatives, ustring name, TypeDesc type,
|
2012-06-04 22:44:58 +00:00
|
|
|
void *renderstate, void *val);
|
2011-04-27 11:58:34 +00:00
|
|
|
bool has_userdata(ustring name, TypeDesc type, void *renderstate);
|
2012-09-14 23:11:47 +00:00
|
|
|
|
2012-09-02 01:10:31 +00:00
|
|
|
int 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);
|
2012-09-02 01:10:31 +00:00
|
|
|
|
2014-02-04 21:48:32 +00:00
|
|
|
int pointcloud_get(OSL::ShaderGlobals *sg, ustring filename, size_t *indices, int count,
|
|
|
|
ustring attr_name, TypeDesc attr_type, void *out_data);
|
|
|
|
|
|
|
|
bool pointcloud_write(OSL::ShaderGlobals *sg,
|
|
|
|
ustring filename, const OSL::Vec3 &pos,
|
|
|
|
int nattribs, const ustring *names,
|
|
|
|
const TypeDesc *types,
|
|
|
|
const void **data);
|
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
|
|
|
bool 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);
|
|
|
|
|
|
|
|
bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name,
|
|
|
|
TypeDesc type, void *val, bool derivatives);
|
|
|
|
|
2012-11-20 17:40:21 +00:00
|
|
|
bool texture(ustring filename, TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg,
|
|
|
|
float s, float t, float dsdx, float dtdx,
|
|
|
|
float dsdy, float dtdy, float *result);
|
|
|
|
|
|
|
|
bool texture3d(ustring filename, TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
|
|
|
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
|
|
|
const OSL::Vec3 &dPdz, float *result);
|
|
|
|
|
|
|
|
bool environment(ustring filename, TextureOpt &options,
|
|
|
|
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
|
|
|
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result);
|
|
|
|
|
|
|
|
bool get_texture_info(ustring filename, int subimage,
|
|
|
|
ustring dataname, TypeDesc datatype, void *data);
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
static bool get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
|
|
|
|
TypeDesc type, bool derivatives, void *val);
|
|
|
|
static bool get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
|
|
|
|
TypeDesc type, bool derivatives, void *val);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static ustring u_distance;
|
|
|
|
static ustring u_index;
|
|
|
|
static ustring u_camera;
|
|
|
|
static ustring u_screen;
|
|
|
|
static ustring u_raster;
|
|
|
|
static ustring u_ndc;
|
2012-12-01 19:15:05 +00:00
|
|
|
static ustring u_object_location;
|
|
|
|
static ustring u_object_index;
|
|
|
|
static ustring u_geom_dupli_generated;
|
|
|
|
static ustring u_geom_dupli_uv;
|
|
|
|
static ustring u_material_index;
|
|
|
|
static ustring u_object_random;
|
|
|
|
static ustring u_particle_index;
|
|
|
|
static ustring u_particle_age;
|
|
|
|
static ustring u_particle_lifetime;
|
|
|
|
static ustring u_particle_location;
|
|
|
|
static ustring u_particle_rotation;
|
|
|
|
static ustring u_particle_size;
|
|
|
|
static ustring u_particle_velocity;
|
|
|
|
static ustring u_particle_angular_velocity;
|
|
|
|
static ustring u_geom_numpolyvertices;
|
|
|
|
static ustring u_geom_trianglevertices;
|
|
|
|
static ustring u_geom_polyvertices;
|
|
|
|
static ustring u_geom_name;
|
2013-05-11 09:31:58 +00:00
|
|
|
static ustring u_is_smooth;
|
2013-01-03 12:08:54 +00:00
|
|
|
static ustring u_is_curve;
|
2012-12-29 01:57:32 +00:00
|
|
|
static ustring u_curve_thickness;
|
|
|
|
static ustring u_curve_tangent_normal;
|
2012-12-01 19:15:05 +00:00
|
|
|
static ustring u_path_ray_length;
|
2013-07-31 20:30:37 +00:00
|
|
|
static ustring u_path_ray_depth;
|
2014-04-21 12:20:29 +00:00
|
|
|
static ustring u_path_transparent_depth;
|
2012-12-01 19:15:05 +00:00
|
|
|
static ustring u_trace;
|
|
|
|
static ustring u_hit;
|
|
|
|
static ustring u_hitdist;
|
|
|
|
static ustring u_N;
|
|
|
|
static ustring u_Ng;
|
|
|
|
static ustring u_P;
|
|
|
|
static ustring u_I;
|
|
|
|
static ustring u_u;
|
|
|
|
static ustring u_v;
|
2011-04-27 11:58:34 +00:00
|
|
|
static ustring u_empty;
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
KernelGlobals *kernel_globals;
|
2013-06-28 13:05:21 +00:00
|
|
|
OSL::TextureSystem *osl_ts;
|
2013-11-28 00:38:23 +00:00
|
|
|
#ifdef WITH_PTEX
|
|
|
|
PtexCache *ptex_cache;
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __OSL_SERVICES_H__ */
|
|
|
|
|