Welcome to mirror list, hosted at ThFree Co, Russian Federation.

osl_services.h « osl « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2701abb483c801c46f9666b1df59da8f68475a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright 2011-2013 Blender Foundation
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

#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>

#ifdef WITH_PTEX
class PtexCache;
#endif

CCL_NAMESPACE_BEGIN

class Object;
class Scene;
class Shader;
struct ShaderData;
struct float3;
struct KernelGlobals;
class OSLRenderServices : public OSL::RendererServices
{
public:
	OSLRenderServices();
	~OSLRenderServices();
	
	void thread_init(KernelGlobals *kernel_globals, OSL::TextureSystem *ts);

	bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
	bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
	
	bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from, float time);
	bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring to, float time);
	
	bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform);
	bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform);
	
	bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from);
	bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from);

	bool get_array_attribute(OSL::ShaderGlobals *sg, bool derivatives,
	                         ustring object, TypeDesc type, ustring name,
	                         int index, void *val);
	bool get_attribute(OSL::ShaderGlobals *sg, bool derivatives, ustring object,
	                   TypeDesc type, ustring name, void *val);
	bool get_attribute(ShaderData *sd, bool derivatives, ustring object_name,
	                   TypeDesc type, ustring name, void *val);

	bool get_userdata(bool derivatives, ustring name, TypeDesc type,
	                  OSL::ShaderGlobals *sg, void *val);
	bool has_userdata(ustring name, TypeDesc type, OSL::ShaderGlobals *sg);

	int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &center,
	                      float radius, int max_points, bool sort, size_t *out_indices,
	                      float *out_distances, int derivs_offset);

	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);

	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);

	bool texture(ustring filename,
	             TextureSystem::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);

	bool 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);

	bool environment(ustring filename, TextureOpt &options,
	                 OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
	                 const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy,
	                 int nchannels, float *result);

	bool get_texture_info(OSL::ShaderGlobals *sg, ustring filename, int subimage,
	                      ustring dataname, TypeDesc datatype, void *data);

	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);

	static ustring u_distance;
	static ustring u_index;
	static ustring u_world;
	static ustring u_camera;
	static ustring u_screen;
	static ustring u_raster;
	static ustring u_ndc;
	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;
	static ustring u_is_smooth;
	static ustring u_is_curve;
	static ustring u_curve_thickness;
	static ustring u_curve_tangent_normal;
	static ustring u_path_ray_length;
	static ustring u_path_ray_depth;
	static ustring u_path_transparent_depth;
	static ustring u_path_transmission_depth;
	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;
	static ustring u_empty;

private:
	KernelGlobals *kernel_globals;
	OSL::TextureSystem *osl_ts;
#ifdef WITH_PTEX
	PtexCache *ptex_cache;
#endif
};

CCL_NAMESPACE_END

#endif /* __OSL_SERVICES_H__  */