File: shaders.cpp

package info (click to toggle)
k3d 0.4.3.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 51,716 kB
  • ctags: 81,610
  • sloc: cpp: 283,698; ansic: 64,095; xml: 61,533; sh: 9,026; makefile: 5,282; python: 431; perl: 308; awk: 130
file content (687 lines) | stat: -rw-r--r-- 22,248 bytes parent folder | download
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// K-3D
// Copyright (c) 1995-2004, Timothy M. Shead
//
// Contact: tshead@k-3d.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/** \file
		\brief Implements the RenderManShader plugin, which encapsulates a single RenderMan shader instance
		\author Tim Shead (tshead@k-3d.com)
*/

#include <k3dsdk/application.h>
#include <k3dsdk/classes.h>
#include <k3dsdk/color.h>
#include <k3dsdk/irenderman.h>
#include <k3dsdk/module.h>
#include <k3dsdk/object.h>
#include <k3dsdk/persistence.h>
#include <k3dsdk/string_modifiers.h>
#include <k3dsdk/xml_utility.h>

#ifdef	WIN32
#ifdef	interface
#undef	interface
#endif	//interface
#endif	//WIN32

#ifdef	WIN32
#ifdef	interface
#undef	interface
#endif	//interface
#endif	//WIN32

namespace libk3drenderman
{

/////////////////////////////////////////////////////////////////////////////
// shader_implementation

/// Abstract base class that provides most of the implementation for our shader objects
class shader_implementation :
	public k3d::persistent<k3d::object>
{
	typedef k3d::persistent<k3d::object> base;

public:
	shader_implementation(k3d::idocument& Document, const sdpsl::shader::type_t ShaderType) :
		base(Document),
		m_shader_name(k3d::init_name("shader_name") + k3d::init_description("Shader Name [string]") + k3d::init_value<std::string>("") + k3d::init_values(shader_values(ShaderType)) + k3d::init_document(Document))
	{
		enable_serialization(k3d::persistence::proxy(m_shader_name));
		register_property(m_shader_name);

		m_shader_name.changed_signal().connect(SigC::slot(*this, &shader_implementation::on_shader_changed));
	}

	~shader_implementation()
	{
		clear();
	}

	void load(sdpxml::Document& Document, sdpxml::Element& Element)
	{
		// Look for a shader name, and setup our arguments accordingly, so they can load their own values in the base-class implementation
		m_shader_name.set_value(sdpxml::GetAttribute(k3d::xml::safe_element(k3d::xml::safe_element(Element, "variables"), sdpxml::Element("variable", "", sdpxml::Attribute("name", "shader_name"))), "value", std::string()));
	
		base::load(Document, Element);
	}

protected:
	const std::string shader_name()
	{
		return m_shader_name.value();
	}

	k3d::ri::parameter_list shader_arguments(const k3d::ri::render_state& State)
	{
		k3d::ri::parameter_list results;

		for(arguments_t::iterator argument = m_arguments.begin(); argument != m_arguments.end(); ++argument)
			{
				if(argument->storage.empty())
					{
						// Empty storage is a placeholder for shader argument types that we don't currently support
					}
				else if(argument->storage.type() == typeid(string_storage_t*))
					{
						string_storage_t& storage = *boost::any_cast<string_storage_t*>(argument->storage);
						results.push_back(k3d::ri::parameter(argument->name, k3d::ri::CONSTANT, static_cast<k3d::ri::string>(storage.value())));
					}
				else if(argument->storage.type() == typeid(scalar_storage_t*))
					{
						scalar_storage_t& storage = *boost::any_cast<scalar_storage_t*>(argument->storage);
						results.push_back(k3d::ri::parameter(argument->name, k3d::ri::CONSTANT, static_cast<k3d::ri::real>(storage.value())));
					}
				else if(argument->storage.type() == typeid(color_storage_t*))
					{
						color_storage_t& storage = *boost::any_cast<color_storage_t*>(argument->storage);
						results.push_back(k3d::ri::parameter(argument->name, k3d::ri::CONSTANT, static_cast<k3d::ri::color>(storage.value())));
					}
				else if(argument->storage.type() == typeid(texture_storage_t*))
					{
						texture_storage_t& storage = *boost::any_cast<texture_storage_t*>(argument->storage);
						if(!storage.interface())
							continue;

						results.push_back(k3d::ri::parameter(argument->name, k3d::ri::CONSTANT, static_cast<k3d::ri::string>(storage.interface()->renderman_texture_path(State).native_file_string())));
					}
				else
					{
						std::cerr << error << __PRETTY_FUNCTION__ << ": unknown storage type for shader argument [" << argument->name << "] will be ignored" << std::endl;
						continue;
					}
			}

		return results;
	}

private:
	/// Helper functor for searching for shaders by name
	struct same_name
	{
		same_name(const std::string& Name) : name(Name) {}

		template<typename T>
		bool operator()(const T& LHS)
		{
			return LHS.name == name;
		}

		const std::string name;
	};

	void on_shader_changed()
	{
		setup_arguments();
	}

	void clear()
	{
		// Get rid of old property / persistence proxies
		k3d::persistence::container::clear();

		for(arguments_t::iterator argument = m_arguments.begin(); argument != m_arguments.end(); ++argument)
			{
				// Empty storage is a placeholder for shader argument types that we don't currently support
				if(argument->storage.empty())
					{
					}
				else if(argument->storage.type() == typeid(scalar_storage_t*))
					{
						unregister_property(*boost::any_cast<scalar_storage_t*>(argument->storage));
					}
				else if(argument->storage.type() == typeid(color_storage_t*))
					{
						unregister_property(*boost::any_cast<color_storage_t*>(argument->storage));
					}
				else if(argument->storage.type() == typeid(string_storage_t*))
					{
						unregister_property(*boost::any_cast<string_storage_t*>(argument->storage));
					}
				else if(argument->storage.type() == typeid(texture_storage_t*))
					{
						unregister_property(*boost::any_cast<texture_storage_t*>(argument->storage));
					}
				else
					{
						std::cerr << error << __PRETTY_FUNCTION__ << ": unknown argument storage type for [" << argument->name << "] will not be destroyed" << std::endl;
					}
			}

		for(arguments_t::iterator argument = m_arguments.begin(); argument != m_arguments.end(); ++argument)
			{
				// Empty storage is a placeholder for shader argument types that we don't currently support
				if(argument->storage.empty())
					{
					}
				else if(argument->storage.type() == typeid(scalar_storage_t*))
					{
						k3d::undoable_delete(boost::any_cast<scalar_storage_t*>(argument->storage), document());
					}
				else if(argument->storage.type() == typeid(color_storage_t*))
					{
						k3d::undoable_delete(boost::any_cast<color_storage_t*>(argument->storage), document());
					}
				else if(argument->storage.type() == typeid(string_storage_t*))
					{
						k3d::undoable_delete(boost::any_cast<string_storage_t*>(argument->storage), document());
					}
				else if(argument->storage.type() == typeid(texture_storage_t*))
					{
						k3d::undoable_delete(boost::any_cast<texture_storage_t*>(argument->storage), document());
					}
				else
					{
						std::cerr << error << __PRETTY_FUNCTION__ << ": unknown argument storage type for [" << argument->name << "] will not be destroyed" << std::endl;
					}
			}

		m_arguments.clear();
	}

	class pause_recording
	{
	public:
		pause_recording(k3d::idocument& Document) :
			m_document(Document)
		{
			if(m_document.state_recorder().current_change_set())
				m_change_set = m_document.state_recorder().stop_recording();
		}

		~pause_recording()
		{
			if(m_change_set.get())
				m_document.state_recorder().start_recording(m_change_set);
		}
	
	private:
		k3d::idocument& m_document;
		std::auto_ptr<k3d::istate_change_set> m_change_set;
	};

	void setup_arguments()
	{
		// At the moment, we don't support undo-able changes to the argument-set, so temporarily disable any recording ...
		pause_recording pause(document());
	
		clear();

		enable_serialization(k3d::persistence::proxy(m_shader_name));

		// Try to find a shader description that matches the new shader name ...
		const std::string shader_name = m_shader_name.property_value();
		if(shader_name.empty())
			return;
			
		const sdpsl::shaders_t::const_iterator shader = std::find_if(k3d::application().shaders().begin(), k3d::application().shaders().end(), same_name(shader_name));
		if(shader == k3d::application().shaders().end())
			{
				std::cerr << error << "Unknown shader [" << shader_name << "]" << std::endl;
				return;
			}

		for(sdpsl::shader::arguments_t::const_iterator argument = shader->arguments.begin(); argument != shader->arguments.end(); ++argument)
			{
				switch(argument->extended_type)
					{
						case sdpsl::argument::EX_FLOAT:
						case sdpsl::argument::EX_TIME:
						case sdpsl::argument::EX_ANGLE:
						case sdpsl::argument::EX_DISTANCE:
						case sdpsl::argument::EX_AREA:
						case sdpsl::argument::EX_VOLUME:
						case sdpsl::argument::EX_MASS:
						case sdpsl::argument::EX_FORCE:
						case sdpsl::argument::EX_PRESSURE:
							{
								scalar_storage_t* const scalar_storage = new scalar_storage_t(k3d::init_name(argument->name) + k3d::init_description("Shader Argument") + k3d::init_document(document()) + k3d::init_value(k3d::from_string<double>(argument->default_value, 0.0)));

								enable_serialization(k3d::persistence::proxy(*scalar_storage));
								register_property(*scalar_storage);

								m_arguments.push_back(argument_t(argument->name, boost::any(scalar_storage)));
								break;
							}
						case sdpsl::argument::EX_COLOR:
							{
								color_storage_t* const color_storage = new color_storage_t(k3d::init_name(argument->name) + k3d::init_description("Shader Argument") + k3d::init_document(document()) + k3d::init_value(k3d::from_string<k3d::color>(argument->default_value, k3d::color(1, 1, 1))));

								enable_serialization(k3d::persistence::proxy(*color_storage));
								register_property(*color_storage);

								m_arguments.push_back(argument_t(argument->name, boost::any(color_storage)));
								break;
							}
						case sdpsl::argument::EX_STRING:
						case sdpsl::argument::EX_SPACE:
							{
								string_storage_t* const string_storage = new string_storage_t(k3d::init_name(argument->name) + k3d::init_description("Shader Argument") + k3d::init_document(document()) + k3d::init_value(argument->default_value));

								enable_serialization(k3d::persistence::proxy(*string_storage));
								register_property(*string_storage);

								m_arguments.push_back(argument_t(argument->name, boost::any(string_storage)));
								break;
							}
						case sdpsl::argument::EX_TEXTURE:
							{
								texture_storage_t* const texture_storage = new texture_storage_t(k3d::init_name(argument->name) + k3d::init_description("Shader Argument") + k3d::init_document(document()) + k3d::init_object_value(0));

								enable_serialization(k3d::persistence::object_proxy(*texture_storage));
								register_property(*texture_storage);

								m_arguments.push_back(argument_t(argument->name, boost::any(texture_storage)));
								break;
							}
						case sdpsl::argument::EX_POINT:
						case sdpsl::argument::EX_VECTOR:
						case sdpsl::argument::EX_NORMAL:
						case sdpsl::argument::EX_MATRIX:
							{
								// Empty storage is a placeholder for shader argument types that we don't currently support
								m_arguments.push_back(argument_t(argument->name, boost::any()));
								break;
							}
						default:
							{
								m_arguments.push_back(argument_t(argument->name, boost::any()));
								std::cerr << error << __PRETTY_FUNCTION__ << ": unknown extended argument type for [" << argument->name << "] will not receive storage" << std::endl;
							}
					}
			}
	}

	/// Storage for the shader name
	k3d_list_property(std::string, k3d::immutable_name, k3d::change_signal, k3d::with_undo, k3d::local_storage, k3d::no_constraint) m_shader_name;

	/// Defines storage for a single shader argument instance
	struct argument_t
	{
		argument_t(const std::string& Name, const boost::any Storage) : name(Name), storage(Storage) {}
		const std::string name;
		const boost::any storage;
	};

	/// Defines storage for a collection of shader arguments
	typedef std::list<argument_t> arguments_t;

	/// Stores the current set of shader arguments
	arguments_t m_arguments;

	/// Defines storage for a scalar argument
	typedef k3d_data_property(double, k3d::immutable_name, k3d::change_signal, k3d::no_undo, k3d::local_storage, k3d::no_constraint) scalar_storage_t;
	/// Defines storage for a color argument
	typedef k3d_data_property(k3d::color, k3d::immutable_name, k3d::change_signal, k3d::no_undo, k3d::local_storage, k3d::no_constraint) color_storage_t;
	/// Defines storage for a string argument
	typedef k3d_data_property(std::string, k3d::immutable_name, k3d::change_signal, k3d::no_undo, k3d::local_storage, k3d::no_constraint) string_storage_t;
	/// Defines storage for a texture argument
	typedef k3d_object_property(k3d::ri::itexture, k3d::immutable_name, k3d::no_undo, k3d::local_storage) texture_storage_t;

	/// Returns lists of available shaders of the given type
	const k3d::ilist_property<std::string>::values_t& shader_values(const sdpsl::shader::type_t Type)
	{
		static bool initialized = false;
		static k3d::ilist_property<std::string>::values_t deformation_shader_values;
		static k3d::ilist_property<std::string>::values_t imager_shader_values;
		static k3d::ilist_property<std::string>::values_t light_shader_values;
		static k3d::ilist_property<std::string>::values_t surface_shader_values;
		static k3d::ilist_property<std::string>::values_t transformation_shader_values;
		static k3d::ilist_property<std::string>::values_t volume_shader_values;
		static k3d::ilist_property<std::string>::values_t empty_shader_values;

		if(!initialized)
			{
				for(sdpsl::shaders_t::const_iterator shader = k3d::application().shaders().begin(); shader != k3d::application().shaders().end(); ++shader)
					{
						switch(shader->type)
							{
								case sdpsl::shader::DISPLACEMENT:
									deformation_shader_values.push_back(shader->name);
									break;

								case sdpsl::shader::IMAGER:
									imager_shader_values.push_back(shader->name);
									break;

								case sdpsl::shader::LIGHT:
									light_shader_values.push_back(shader->name);
									break;

								case sdpsl::shader::SURFACE:
									surface_shader_values.push_back(shader->name);
									break;

								case sdpsl::shader::TRANSFORMATION:
									transformation_shader_values.push_back(shader->name);
									break;

								case sdpsl::shader::VOLUME:
									volume_shader_values.push_back(shader->name);
									break;
							}
					}

				deformation_shader_values.push_back(std::string());
				imager_shader_values.push_back(std::string());
				light_shader_values.push_back(std::string());
				surface_shader_values.push_back(std::string());
				transformation_shader_values.push_back(std::string());
				volume_shader_values.push_back(std::string());

				std::sort(deformation_shader_values.begin(), deformation_shader_values.end());
				std::sort(imager_shader_values.begin(), imager_shader_values.end());
				std::sort(light_shader_values.begin(), light_shader_values.end());
				std::sort(surface_shader_values.begin(), surface_shader_values.end());
				std::sort(transformation_shader_values.begin(), transformation_shader_values.end());
				std::sort(volume_shader_values.begin(), volume_shader_values.end());

				initialized = true;
			}

		switch(Type)
			{
				case sdpsl::shader::DISPLACEMENT:
					return deformation_shader_values;

				case sdpsl::shader::IMAGER:
					return imager_shader_values;

				case sdpsl::shader::LIGHT:
					return light_shader_values;

				case sdpsl::shader::SURFACE:
					return surface_shader_values;

				case sdpsl::shader::TRANSFORMATION:
					return transformation_shader_values;

				case sdpsl::shader::VOLUME:
					return volume_shader_values;
			}

		return empty_shader_values;
	}

};

/////////////////////////////////////////////////////////////////////////////
// displacement_shader_implementation

/// Implements a RenderMan displacement shader plugin
class displacement_shader_implementation :
	public shader_implementation,
	public k3d::ri::idisplacement_shader
{
	typedef shader_implementation base;

public:
	displacement_shader_implementation(k3d::idocument& Document) :
		base(Document, sdpsl::shader::DISPLACEMENT)
	{
	}

	void setup_renderman_displacement_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiDisplacementV(shader_name(), shader_arguments(State));
	}

	k3d::iplugin_factory& factory()
	{
		return get_factory();
	}

	static k3d::iplugin_factory& get_factory()
	{
		static k3d::plugin_factory<
			k3d::document_plugin<displacement_shader_implementation>,
				k3d::interface_list<k3d::ri::idisplacement_shader> > factory(
			k3d::classes::RenderManDisplacementShader(),
			"RenderManDisplacementShader",
			"Encapsulates a RenderMan displacement shader instance",
			"Objects",
			k3d::iplugin_factory::STABLE);

		return factory;
	}
};

/////////////////////////////////////////////////////////////////////////////
// imager_shader_implementation

/// Implements a RenderMan imager shader plugin
class imager_shader_implementation :
	public shader_implementation,
	public k3d::ri::iimager_shader
{
	typedef shader_implementation base;

public:
	imager_shader_implementation(k3d::idocument& Document) :
		base(Document, sdpsl::shader::IMAGER)
	{
	}

	void setup_renderman_imager_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiImagerV(shader_name(), shader_arguments(State));
	}

	k3d::iplugin_factory& factory()
	{
		return get_factory();
	}

	static k3d::iplugin_factory& get_factory()
	{
		static k3d::plugin_factory<
			k3d::document_plugin<imager_shader_implementation>,
				k3d::interface_list<k3d::ri::iimager_shader> > factory(
			k3d::classes::RenderManImagerShader(),
			"RenderManImagerShader",
			"Encapsulates a RenderMan imager shader instance",
			"Objects",
			k3d::iplugin_factory::STABLE);

		return factory;
	}
};

/////////////////////////////////////////////////////////////////////////////
// light_shader_implementation

/// Implements a RenderMan light shader plugin
class light_shader_implementation :
	public shader_implementation,
	public k3d::ri::ilight_shader
{
	typedef shader_implementation base;

public:
	light_shader_implementation(k3d::idocument& Document) :
		base(Document, sdpsl::shader::LIGHT)
	{
	}

	void setup_renderman_light_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiLightSourceV(shader_name(), shader_arguments(State));
	}

	k3d::iplugin_factory& factory()
	{
		return get_factory();
	}

	static k3d::iplugin_factory& get_factory()
	{
		static k3d::plugin_factory<
			k3d::document_plugin<light_shader_implementation>,
				k3d::interface_list<k3d::ri::ilight_shader> > factory(
			k3d::classes::RenderManLightShader(),
			"RenderManLightShader",
			"Encapsulates a RenderMan light shader instance",
			"Objects",
			k3d::iplugin_factory::STABLE);

		return factory;
	}
};

/////////////////////////////////////////////////////////////////////////////
// surface_shader_implementation

/// Implements a RenderMan surface shader plugin
class surface_shader_implementation :
	public shader_implementation,
	public k3d::ri::isurface_shader
{
	typedef shader_implementation base;

public:
	surface_shader_implementation(k3d::idocument& Document) :
		base(Document, sdpsl::shader::SURFACE)
	{
	}

	void setup_renderman_surface_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiSurfaceV(shader_name(), shader_arguments(State));
	}

	k3d::iplugin_factory& factory()
	{
		return get_factory();
	}

	static k3d::iplugin_factory& get_factory()
	{
		static k3d::plugin_factory<
			k3d::document_plugin<surface_shader_implementation>,
				k3d::interface_list<k3d::ri::isurface_shader> > factory(
			k3d::classes::RenderManSurfaceShader(),
			"RenderManSurfaceShader",
			"Encapsulates a RenderMan surface shader instance",
			"Objects",
			k3d::iplugin_factory::STABLE);

		return factory;
	}
};

/////////////////////////////////////////////////////////////////////////////
// volume_shader_implementation

/// Implements a RenderMan volume shader plugin
class volume_shader_implementation :
	public shader_implementation,
	public k3d::ri::ivolume_shader
{
	typedef shader_implementation base;

public:
	volume_shader_implementation(k3d::idocument& Document) :
		base(Document, sdpsl::shader::VOLUME)
	{
	}

	void setup_renderman_atmosphere_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiAtmosphereV(shader_name(), shader_arguments(State));
	}

	void setup_renderman_interior_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiInteriorV(shader_name(), shader_arguments(State));
	}

	void setup_renderman_exterior_shader(const k3d::ri::render_state& State)
	{
		State.engine.RiExteriorV(shader_name(), shader_arguments(State));
	}

	k3d::iplugin_factory& factory()
	{
		return get_factory();
	}

	static k3d::iplugin_factory& get_factory()
	{
		static k3d::plugin_factory<
			k3d::document_plugin<volume_shader_implementation>,
				k3d::interface_list<k3d::ri::ivolume_shader> > factory(
			k3d::classes::RenderManVolumeShader(),
			"RenderManVolumeShader",
			"Encapsulates a RenderMan volume shader instance",
			"Objects",
			k3d::iplugin_factory::STABLE);

		return factory;
	}
};

/////////////////////////////////////////////////////////////////////////////
// shader factories

k3d::iplugin_factory& displacement_shader_factory()
{
	return displacement_shader_implementation::get_factory();
}

k3d::iplugin_factory& imager_shader_factory()
{
	return imager_shader_implementation::get_factory();
}

k3d::iplugin_factory& light_shader_factory()
{
	return light_shader_implementation::get_factory();
}

k3d::iplugin_factory& surface_shader_factory()
{
	return surface_shader_implementation::get_factory();
}

k3d::iplugin_factory& volume_shader_factory()
{
	return volume_shader_implementation::get_factory();
}

} // namespace libk3drenderman