aboutsummaryrefslogtreecommitdiff
path: root/vrayPlug/plugin/shaveVrayPlugin.h
blob: e0f47e2266bdecb60d966c9057b66b5657114e22 (plain) (blame)
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
#ifndef _HAIR_VRAY_PLUGIN_H_
#define _HAIR_VRAY_PLUGIN_H_

// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962

/**********************************************************************
 *<
	FILE:			shaveVrayPlugin.h  

	DESCRIPTION:	VRay plugin

	CREATED BY:		Vladimir Dubovoy <[email protected]>

	HISTORY:		created  30-03-2010 

 *>
 **********************************************************************/

// V-Ray headers
#include "vraybase.h"
#include "vraymayageom.h"
#include "vrayplugins.h"
#include "meshinfointerface.h"
#include "defparams.h"
#include "charstring.h"

#ifdef VRAY30
    #define VR30_CONST_STR_HACK(x) const_cast<char*>(x)
#else
    #define VR30_CONST_STR_HACK(x) x
#endif

#include <stdio.h>

class shaveVrayPlugin : public VR::VRayStaticGeomSource{
public:
	static const char* version;
	VR::VRayRenderer *vray;

#if defined(VRAY30) || defined(VRAY40)
	int useGlobalHairTree;
	int dynHairTessel;
	float edgeLen;
#endif

	// Cache for the parameters
	//not sure what for these are used
	//PluginBase *meshPlugin;
	//MeshInfoInterface *meshInfoInterface;


	shaveVrayPlugin(VR::VRayPluginDesc *desc);
	~shaveVrayPlugin();

	void freeMem();

	// From VRayPlugin
	void renderBegin(VR::VRayRenderer *vray);
	void renderEnd(VR::VRayRenderer *vray);
	void frameBegin(VR::VRayRenderer *vray);
	void frameEnd(VR::VRayRenderer *vray);

	// From VRayStaticGeomSource
	VR::VRayStaticGeometry* newInstance(
			VR::MaterialInterface *mtl, 
			VR::BSDFInterface *bsdf, int renderID, 
			VR::VolumetricInterface *volume, VR::LightList *lightList,
#ifdef VRAY40
			const VR::Transform &baseTM, 
#else
			const VR::TraceTransform &baseTM, 
#endif
			int objectID, const tchar *userAttributes, int primaryVisibility);

	void deleteInstance(VR::VRayStaticGeometry *instance);

	VR::VRayContext* getVRayContext();

	void SetStackIndex(int idx) {_stackIndex() = idx;}
	int  GetStackIndex() const  {return stackIndex();}

	void SetUseOwnBSDF(bool use) {_ownshader() = use ? 1 : 0;}
	bool GetUseOwnBSDF() const  {return ownshader() != 0;}

	bool GetSquirrel()  const   {return squirrel() != 0;}
	bool GetTipFade()	const	{return tipfade() != 0;} 

	const VR::Color& GetSpecTint()  const {return spectint();}
	const VR::Color& GetSpecTint2()  const {return spectint2();}

	inline bool	 GetCameraVisibility() const {return cameraVisibility() != 0;}
	inline bool	 GetReflVisibility()   const {return reflVisibility() != 0;}
	inline bool	 GetRefrVisibility()   const {return refrVisibility() != 0;}
	inline bool	 GetLightVisibility()  const {return lightVisibility() != 0;}
	inline bool	 GetGiVisibility()	   const {return GiVisibility() != 0;}

	inline float GetSelfShadow() const {return selfShadow();}
	inline bool  GetRecvShadow() const {return recvShadow();}

	//const VR::Vector& GetUVs() const {return uvs();}
	int GetNumFacesPerInst() const {return numFacesPerInst();}
	int GetNumUVSets() const {return numUVSets();}
	
	//does not work  for standalone
	//shaveVrayVectorListParam* GetUVparam() const 
	//{
	//	return m_uvsParam;
	//}
	//shaveVrayIntListParam* GetDataParam() const 
	//{
	//	return m_dataParam;
	//}
	//shaveVrayIntParam* GetDataSizeParam() const 
	//{
	//	return m_dataSizeParam;
	//}

protected:

	int numThreads;
	VR::VRayContext **ctxs; // used for sampling the textures

	void createRayContextes(VR::VRayRenderer *vray);

	//const member access
	inline int stackIndex()		const {return m_stackIndex;}
	inline int instanced()		const {return m_instanced;}
	inline int ownshader()		const {return m_ownshader;}
	inline int numFacesPerInst()const {return m_numFacesPerInst;}
	inline int numUVSets()		const {return m_numUVSets;}
	//inline const VR::Vector& uvs() const {return m_uvs;}
	inline int squirrel()		const {return m_squirrel;}
	inline int tipfade()		const {return m_tipfade;}
	inline const VR::Color& spectint() const {return m_spectint;}
	inline const VR::Color& spectint2()const {return m_spectint2;}
	inline int	 cameraVisibility() const {return m_cameraVisibility;}
	inline int	 reflVisibility()	const {return m_reflVisibility;}
	inline int	 refrVisibility()	const {return m_refrVisibility;}
	inline int	 lightVisibility()  const {return m_lightVisibility;}
	inline int	 GiVisibility()		const {return m_GiVisibility;}
	inline float selfShadow()		const {return m_selfShadow;}
	inline int	 recvShadow()		const {return m_recvShadow;}

	//member access
	inline int& _stackIndex()		{return m_stackIndex;}
	inline int& _instanced()		{return m_instanced;}
	inline int& _ownshader()		{return m_ownshader;}
	inline int& _numFacesPerInst()	{return m_numFacesPerInst;}
	inline int& _numUVSets()		{return m_numUVSets;}
	//inline VR::Vector& _uvs()     {return m_uvs;}
	inline int& _squirrel()		    {return m_squirrel;}
	inline int&	_tipfade()			{return m_tipfade;}
	inline VR::Color& _spectint()	{return m_spectint;}
	inline VR::Color& _spectint2()	{return m_spectint2;}
	inline int&	 _cameraVisibility(){return m_cameraVisibility;}
	inline int&	 _reflVisibility()	{return m_reflVisibility;}
	inline int&	 _refrVisibility()	{return m_refrVisibility;}
	inline int&	 _lightVisibility() {return m_lightVisibility;}
	inline int&	 _GiVisibility()	{return m_GiVisibility;}
	inline float& _selfShadow()		{return m_selfShadow;}
	inline int&	 _recvShadow()		{return m_recvShadow;}

	static void pause(int minSeconds, int maxSeconds);

private:

	int						m_instanced;
	int						m_stackIndex;
	int						m_ownshader;
	int						m_numFacesPerInst;
	int						m_numUVSets;
	int						m_squirrel;
	int						m_tipfade;
	VR::Color				m_spectint;
	VR::Color				m_spectint2;
	VR::CharString			m_libPath;
	//VR::Vector				m_uvs;
	int						m_cameraVisibility;
	int						m_reflVisibility;
	int						m_refrVisibility;
	int						m_lightVisibility;
	int						m_GiVisibility;
	float					m_selfShadow;
	int						m_recvShadow;
	
public:
	static VR::CharString   draFile;
};

#define DO_LOGS
#ifdef  DO_LOGS

#ifdef WIN32 
	extern FILE* alog;
#define LOGMSG(prefix, msg) {if(alog){ fprintf(alog,"%s> %s\n",prefix,msg);fflush(alog);}}
#else 
#define LOGMSG(prefix, msg)  {fprintf(stdout,"%s> %s\n",prefix,msg);fflush(stdout);}
#endif

#ifdef WIN32 
	extern FILE* alog;
#define LOGMSGS(prefix, msg1, msg2) {if(alog){ fprintf(alog,"%s> %s %s\n",prefix,msg1,msg2);;fflush(alog);}}
#else
#define LOGMSGS(prefix, msg1, msg2) {fprintf(stdout,"%s> %s %s\n",prefix,msg1,msg2);fflush(stdout);}
#endif

#ifdef WIN32 
	extern FILE* alog;
#define LOGMSGI(prefix, msg1, i) {if(alog){ fprintf(alog,"%s> %s %i\n",prefix,msg1,i);;fflush(alog);}}
#else
#define LOGMSGI(prefix, msg1, i) {fprintf(stdout,"%s> %s %i\n",prefix,msg1,i);fflush(stdout);}
#endif

#ifdef WIN32 
	extern FILE* alog;
#define LOGMSGI3(prefix, msg1, i1, i2, i3){if(alog) {fprintf(alog,"%s> %s %i %i %i\n",prefix,msg1,i1,i2,i3);fflush(alog);}}
#else
#define LOGMSGI3(prefix, msg1, i1, i2, i3) {fprintf(stdout,"%s> %s %i %i %i\n",prefix,msg1,i1,i2,i3);fflush(stdout);}
#endif

#else	//DO_LOGS

#define LOGMSG(prefix, msg) {;}
#define LOGMSGS(prefix, msg1, msg2) {;}
#define LOGMSGI(prefix, msg1, i) {;}
#define LOGMSGI3(prefix, msg1, i1, i2, i3){;}

#endif	//DO_LOGS

#endif	//end of_HAIR_VRAY_PLUGIN_H_