aboutsummaryrefslogtreecommitdiff
path: root/vrayPlug/plugin/shaveVrayVoxelPrim.h
blob: b946e40cee6f09891211b3e32821df6338e403e4 (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
#ifndef _HAIR_VR_VOXEL_PRIMITIVE_H_
#define _HAIR_VR_VOXEL_PRIMITIVE_H_

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

/**********************************************************************
 *<
	FILE:			shaveVrayVoxelPrim.h (was shaveVrayVoxelPrim.h)

	DESCRIPTION:	Generic hair voxel primitive

	CREATED BY:		Vladimir Dubovoy <[email protected]>

	HISTORY:		created  02-09-2008 ( as part of 3ds Max + VRay hair shaders)
					merged   30-03-2010 

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

////#include <max.h>			//VRayInterface needs it - ShadeContext
//#include <vraybase.h>
////#include <vrayinterface.h> 
//#include <rayprimitives.h> 
//#include <hairprimitives.h>
//#include <vraygeom.h>
//#include <pool.h>

#include "utils.h"
#include "box.h"
#include "rayserver.h"
#include "vrayplugins.h"
#include "rayserver.h"
#include "geometryclasses.h"

#ifdef VRAY20
#include "pool.h"
#endif

#include "hairAPIvrayutil.h"
#include "shaveVrayShadeData.h"
#include "shaveVrayVoxelPrimBase.h"

class shaveVrayInstance;

class shaveVrayVoxelPrim : public shaveVrayVoxelPrimBase  {
public:
	shaveVrayVoxelPrim(IHairVoxel* vox, VR::VRayCore* vray, shaveVrayInstance* inst);
	virtual ~shaveVrayVoxelPrim();

	enum consts
	{
		eNumSides	 = 4,	//always 4
		eDefNumKnots = 5	//actual value from HairType should be used
	};

	void SetTipFade(bool set){	_tipfade() = set;}
	bool GetTipFade() const	{return tipfade();}

	void SetUseOwnBSDF(bool set){	_ownbsdf() = set;}
	bool GetUseOwnBSDF() const	{return ownbsdf();}

	void SetAmbient(const VR::Color& c) {_ambient() = c;}
	const VR::Color& GetAmbient() const	{return ambient();}

	const VR::Color& GetSpecTint()  const {return spectint();}
	void SetSpecTint(const VR::Color& c) {_spectint() = c;}

	const VR::Color& GetSpecTint2()  const {return spectint2();}
	void SetSpecTint2(const VR::Color& c) {_spectint2() = c;}

	bool  IsColorConst(int strandidx) const;
	void  GetRootColor(int strandidx,VR::Color& c) const;
	void  GetInterpColor(int segmentIdx, int strandidx, float segmentOffset, VR::Color& res) const;
	float GetInterpOpacity(int segmentIdx, int strandidx, float segmentOffset) const;
	float GetOpacity   (int strandidx) const;
	float GetAmbDiff   (int strandidx) const;
	float GetGlossiness(int strandidx) const;
	float GetSpecLevel (int strandidx) const;


	VR::ShadeVec GetHairDir(const VR::ShadeVec& hit, int segmentIdx, int strandidx, float segmentOffset) const;
	VR::ShadeVec GetUVW(int segmentIdx, int strandIdx, float segmentOffset, int channel) const;

	inline shaveVrayInstance* GetInstance() const {return hinst();}

#if defined(VRAY30) || defined(VRAY40)
	virtual VR::ShadeVec getHairDir(const VR::VRayContext &rc) const=0;
#endif
protected:
	
	//const member access
	inline VR::Shadeable*		 shade()	  const {return m_shade;}
	inline VR::VRayShadeInstance*	 shinst()	  const {return m_shinst;}
	//inline VR::VRayShadeData*	 shdata()	  const {return m_shdata;}
	//inline VR::BaseMeshShadeData/*<moving>*/* shdata()  const {return m_shdata;}
	inline shaveVrayShadeData*    shdata()	 const {return m_shdata;}
	inline shaveVrayInstance*     hinst()	 const {return m_hinst;}
	//inline VR::SurfaceProperties* sfprops() const {return m_sfprops;}
#if defined(VRAY20) || defined(VRAY30) || defined(VRAY40)
	inline const VR::FixedPool<true>&   pool_Vector() const {return m_pool_Vector;}
#else
	inline const VR::FixedPool&   pool_Vector() const {return m_pool_Vector;}
#endif
	inline const VR::Color&	      ambient()		const {return m_ambient;}
	inline const VR::Color&		  spectint()	const {return m_spectint;}
	inline const VR::Color&		  spectint2()	const {return m_spectint2;}
	inline int	  numknots()const {return m_numknots;}
	inline float  uc(int i)	const {return m_uc[i];}
	inline float  vc(int i) const {return m_vc[i];}
	inline bool   tipfade()	const {return m_tipfade;}
	inline bool   ownbsdf() const {return m_ownbsdf;}
	
	//ptr access
	inline const float*	puc() const {return m_uc;}
	inline const float*	pvc() const {return m_vc;}
	inline float*	_puc() {return m_uc;}
	inline float*	_pvc() {return m_vc;}
	
	//member access
	inline VR::Shadeable*&		   _shade()	     {return m_shade;}
	inline VR::VRayShadeInstance*&   _shinst()	 {return m_shinst;}
	//inline VR::VRayShadeData*&   _shdata()	 {return m_shdata;}
	inline shaveVrayShadeData*&    _shdata()	 {return m_shdata;}
	inline shaveVrayInstance*&     _hinst()		 {return m_hinst;}
	//inline VR::BaseMeshShadeData/*<moving>*/*& _shdata() {return m_shdata;}
	//inline VR::SurfaceProperties*& _sfprops()	 {return m_sfprops;}
#if defined(VRAY20) || defined(VRAY30) || defined(VRAY40)
	inline VR::FixedPool<true>&   _pool_Vector() {return m_pool_Vector;}
#else
	inline VR::FixedPool&		  _pool_Vector() {return m_pool_Vector;}
#endif
	inline VR::Color&	          _ambient()	 {return m_ambient;}
	inline VR::Color&			  _spectint()	 {return m_spectint;}
	inline VR::Color&			  _spectint2()	 {return m_spectint2;}
	inline int&	   _numknots()  {return m_numknots;}
	inline float&  _uc(int i)   {return m_uc[i];}
	inline float&  _vc(int i)   {return m_vc[i];}
	inline bool&   _tipfade()	{return m_tipfade;}
	inline bool&   _ownbsdf()   {return m_ownbsdf;}

private:

	int			  m_numknots;
	bool		  m_tipfade;
	bool		  m_ownbsdf;
	float         m_uc[eNumSides];
	float         m_vc[eNumSides];
	VR::Color	  m_ambient;
	VR::Color	  m_spectint;
	VR::Color	  m_spectint2;
#if defined(VRAY20) || defined(VRAY30) || defined(VRAY40)
	VR::FixedPool<true>	m_pool_Vector;
#else
	VR::FixedPool		m_pool_Vector;
#endif
	VR::Shadeable*		m_shade; 
	VR::VRayShadeInstance*	m_shinst;   //3ds Max related 
	//VR::VRayShadeData*    m_shdata;	//3ds Max related
	//VR::BaseMeshShadeData/*<moving>*/* m_shdata;
	shaveVrayShadeData* m_shdata;
	shaveVrayInstance*  m_hinst;
	//VR::SurfaceProperties* m_sfprops;	//3ds Max related  
};

#endif	//end of_HAIR_VR_VOXEL_PRIMITIVE_H_