Cycles / Ray Depth:
[blender.git] / intern / cycles / kernel / osl / osl_services.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifndef __OSL_SERVICES_H__
20 #define __OSL_SERVICES_H__
21
22 /* OSL Render Services
23  *
24  * Implementation of OSL render services, to retriever matrices, attributes,
25  * textures and point clouds. In principle this should only be accessing
26  * kernel data, but currently we also reach back into the Scene to retrieve
27  * attributes.
28  */
29
30 #include <OSL/oslexec.h>
31 #include <OSL/oslclosure.h>
32
33 CCL_NAMESPACE_BEGIN
34
35 class Object;
36 class Scene;
37 class Shader;
38 struct ShaderData;
39 struct float3;
40 struct KernelGlobals;
41
42 class OSLRenderServices : public OSL::RendererServices
43 {
44 public:
45         OSLRenderServices();
46         ~OSLRenderServices();
47         
48         void thread_init(KernelGlobals *kernel_globals, OSL::TextureSystem *ts);
49
50         bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
51         bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
52         
53         bool get_matrix(OSL::Matrix44 &result, ustring from, float time);
54         bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time);
55         
56         bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform);
57         bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform);
58         
59         bool get_matrix(OSL::Matrix44 &result, ustring from);
60         bool get_inverse_matrix(OSL::Matrix44 &result, ustring from);
61
62         bool get_array_attribute(void *renderstate, bool derivatives,
63                                  ustring object, TypeDesc type, ustring name,
64                                  int index, void *val);
65         bool get_attribute(void *renderstate, bool derivatives, ustring object,
66                            TypeDesc type, ustring name, void *val);
67
68         bool get_userdata(bool derivatives, ustring name, TypeDesc type,
69                           void *renderstate, void *val);
70         bool has_userdata(ustring name, TypeDesc type, void *renderstate);
71
72         int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &center,
73                               float radius, int max_points, bool sort, size_t *out_indices,
74                               float *out_distances, int derivs_offset);
75
76         int pointcloud_get(ustring filename, size_t *indices, int count, ustring attr_name,
77                            TypeDesc attr_type, void *out_data);
78
79         bool trace(TraceOpt &options, OSL::ShaderGlobals *sg,
80                    const OSL::Vec3 &P, const OSL::Vec3 &dPdx,
81                    const OSL::Vec3 &dPdy, const OSL::Vec3 &R,
82                    const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy);
83
84         bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name,
85                         TypeDesc type, void *val, bool derivatives);
86
87         bool texture(ustring filename, TextureOpt &options,
88                      OSL::ShaderGlobals *sg,
89                      float s, float t, float dsdx, float dtdx,
90                      float dsdy, float dtdy, float *result);
91
92         bool texture3d(ustring filename, TextureOpt &options,
93                        OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
94                        const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
95                        const OSL::Vec3 &dPdz, float *result);
96
97         bool environment(ustring filename, TextureOpt &options,
98                          OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
99                          const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result);
100
101         bool get_texture_info(ustring filename, int subimage,
102                               ustring dataname, TypeDesc datatype, void *data);
103
104         static bool get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
105                         TypeDesc type, bool derivatives, void *val);
106         static bool get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
107                         TypeDesc type, bool derivatives, void *val);
108
109         static ustring u_distance;
110         static ustring u_index;
111         static ustring u_camera;
112         static ustring u_screen;
113         static ustring u_raster;
114         static ustring u_ndc;
115         static ustring u_object_location;
116         static ustring u_object_index;
117         static ustring u_geom_dupli_generated;
118         static ustring u_geom_dupli_uv;
119         static ustring u_material_index;
120         static ustring u_object_random;
121         static ustring u_particle_index;
122         static ustring u_particle_age;
123         static ustring u_particle_lifetime;
124         static ustring u_particle_location;
125         static ustring u_particle_rotation;
126         static ustring u_particle_size;
127         static ustring u_particle_velocity;
128         static ustring u_particle_angular_velocity;
129         static ustring u_geom_numpolyvertices;
130         static ustring u_geom_trianglevertices;
131         static ustring u_geom_polyvertices;
132         static ustring u_geom_name;
133         static ustring u_is_smooth;
134         static ustring u_is_curve;
135         static ustring u_curve_thickness;
136         static ustring u_curve_tangent_normal;
137         static ustring u_path_ray_length;
138         static ustring u_path_ray_depth;
139         static ustring u_trace;
140         static ustring u_hit;
141         static ustring u_hitdist;
142         static ustring u_N;
143         static ustring u_Ng;
144         static ustring u_P;
145         static ustring u_I;
146         static ustring u_u;
147         static ustring u_v;
148         static ustring u_empty;
149
150 private:
151         KernelGlobals *kernel_globals;
152         OSL::TextureSystem *osl_ts;
153 };
154
155 CCL_NAMESPACE_END
156
157 #endif /* __OSL_SERVICES_H__  */
158