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
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
/**********************************************************************
*<
FILE: shaveVrayShadeable.cpp -- implementation file ( HairVrShadeable.cpp )
DESCRIPTION: Used to shade a surface
CREATED BY: Vladimir Dubovoy <[email protected]>
HISTORY: created 21-08-2008 ( as part of 3ds Max + VRay hair shaders)
merged 31-03-2010
*>
**********************************************************************/
#include "shaveVrayShadeable.h"
#include "hairAPIvray.h"
#include "shaveVrayPlugin.h"
#include "shaveVrayInstance.h"
#if (defined WIN32) ||(defined LINUX)
;
#else
#include "shaveVrayBaseBSDFPool.h" // I did not split it for osx yet
#endif
#include "shaveVraySharedFunctions.h"
shaveVrayShadeable::shaveVrayShadeable(shaveVrayVoxelPrim *hair)
{
_prim() = hair;
#ifdef USE_WHITE_BRDF
;
#else
_bsdfPool() = NULL;
#if (defined WIN32) ||(defined LINUX)
//_bsdfPool() = new shaveVrayBaseBSDFPool();
if(CreateShaveBSDFPool != NULL)
{
_bsdfPool() = CreateShaveBSDFPool();
}
if(!bsdfPool())
{
LOGMSG("SHADE","shaveVrayShadeable: can not create BSDF pool.");
}
#else //osx
_bsdfPool() = new shaveVrayBaseBSDFPool();
#endif
#endif
}
shaveVrayShadeable::~shaveVrayShadeable()
{
freeBSDFpool();
}
/*
| from Shadeable
*/
void shaveVrayShadeable::shade(VR::VRayContext &rc)
{
//no trace
//if(rc.rayparams.diffuseLevel > 1)
//{
// rc.mtlresult.makeOpaque();
// return;
//}
BSDFShadeable::shade(rc);
//////just a test - no trace ////
//rc.mtlresult.alpha.r = 0.0f;
//rc.mtlresult.alpha.g = 0.0f;
//rc.mtlresult.alpha.b = 0.0f;
//rc.mtlresult.transp.r = 0.f;
//rc.mtlresult.transp.g = 0.f;
//rc.mtlresult.transp.b = 0.f;
//rc.mtlresult.alphaTransp.r = 0.0f;
//rc.mtlresult.alphaTransp.g = 0.0f;
//rc.mtlresult.alphaTransp.b = 0.0f;
//int strandIdx = rc.rayresult.faceIndex;
//VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong
//int segmentIdx=(int) rc.rayresult.extraf;
//float segmentOffset=rc.rayresult.bary[2];
//if(prim()->IsColorConst(strandIdx))
// prim()->GetRootColor(strandIdx,diffCol);
//else
// prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol);
//rc.mtlresult.color = diffCol;
//////////////////////////////
#ifdef USE_WHITE_BRDF
VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong
int strandIdx, segmentIdx;
float segmentOffset;
shaveVrayGetHairParams(rc, strandIdx, segmentIdx, segmentOffset);
if(prim()->IsColorConst(strandIdx))
prim()->GetRootColor(strandIdx,diffCol);
else
prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol);
rc.mtlresult.color *= diffCol;
#endif
}
/*
| from Shadeable
*/
tchar* shaveVrayShadeable::getName(VR::VRayContext &rc)
{
return const_cast<tchar*>("shaveVrayShadeable");
}
VR::BSDFSampler* shaveVrayShadeable::newBSDF (const VR::VRayContext &rc, VR::BSDFFlags flags)
{
#ifdef USE_WHITE_BRDF
VR::WhiteBRDF *bsdf = _bsdfPool().newBRDF(rc);
return bsdf;
#else
//shaveVrayBaseBSDF* bsdf = _bsdfPool().newBRDF(rc);
IShaveVrayBSDF* bsdf = NULL;
if(bsdfPool())
{
bsdf =_bsdfPool()->newBRDF(rc);
}
if (!bsdf)
return NULL;
VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong
int strandIdx, segmentIdx;
float segmentOffset;
shaveVrayGetHairParams(rc, strandIdx, segmentIdx, segmentOffset);
if(prim()->IsColorConst(strandIdx))
prim()->GetRootColor(strandIdx,diffCol);
else
prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol);
VR::Color specCol = VR::Color(1.0f, 1.0f, 1.0f);
float opacity = 1.0f;
//hair is opaque for GI prepass steps to speedup computations -- 08-11-2010
if(rc.rayparams.currentPass != RPASS_GI)
if(rc.rayparams.currentPass != RPASS_LIGHTMAP)
{
if(prim()->GetTipFade())
opacity = prim()->GetInterpOpacity(segmentIdx, strandIdx, segmentOffset);
else
opacity = prim()->GetOpacity(strandIdx);
}
//transparency
float t=1.0f-opacity;
VR::Color trsp = VR::Color(t, t, t);
//ambient color [not used yet]
VR::Color ambientCol = prim()->GetAmbient();
//abient/diffuse factor
float ambDiff = prim()->GetAmbDiff(strandIdx);
//glossines
float gloss = prim()->GetGlossiness(strandIdx);
float splvl = prim()->GetSpecLevel(strandIdx);
//specular tints
VR::Color spCol = prim()->GetSpecTint();
VR::Color spCol2= prim()->GetSpecTint2();
// printf("spec_tint %f %f %f \n",spCol.r, spCol.g, spCol.b);
// printf("spec_tint2 %f %f %f \n",spCol2.r, spCol2.g, spCol2.b);
#if defined(VRAY30) || defined(VRAY40)
VR::ShadeVec hairDir=prim()->getHairDir(rc);
#else
VR::ShadeVec hairDir=prim()->GetHairDir(rc.rayresult.origPoint, segmentIdx, strandIdx, segmentOffset);
#endif
shaveVrayInstance* inst = prim()->GetInstance();
//printf("inst get selfShadow %f\n",inst->GetSelfShadow());fflush(stdout);
bsdf->init(rc,specCol,diffCol,ambientCol,spCol,spCol2,ambDiff,splvl,gloss,0,trsp, hairDir, t,
inst->GetCameraVisibility(),
inst->GetReflVisibility(),
inst->GetRefrlVisibility(),
inst->GetLightVisibility(),
inst->GetGiVisibility(),
inst->GetSelfShadow(),
inst->GetRecvShadow());
return bsdf;
#endif
}
void shaveVrayShadeable::deleteBSDF(const VR::VRayContext &rc, VR::BSDFSampler *bsdf)
{
if(!bsdf)
return;
#ifdef USE_WHITE_BRDF
VR::WhiteBRDF *dbsdf = static_cast<VR::/*DiffuseBRDF*/WhiteBRDF*>(bsdf);
_bsdfPool().deleteBRDF(rc, dbsdf);
#else
//shaveVrayBaseBSDF* dbsdf = static_cast<shaveVrayBaseBSDF*>(bsdf);
//_bsdfPool().deleteBRDF(rc, dbsdf);
IShaveVrayBSDF* dbsdf = static_cast<IShaveVrayBSDF*>(bsdf);
if(bsdfPool())
{
_bsdfPool()->deleteBRDF(rc, dbsdf);
}
#endif
}
#if defined(VRAY40)
int shaveVrayShadeable::getBSDFFlags()
{
return VR::bsdfFlag_none;
}
#endif
void shaveVrayShadeable::initBSDFpool(VR::VRayCore *vray)
{
#ifdef USE_WHITE_BRDF
const VR::VRaySequenceData &sdata=vray->getSequenceData();
_bsdfPool().init(sdata.maxRenderThreads);
#else
if(bsdfPool())
{
_bsdfPool()->init(vray);
}
#endif
}
void shaveVrayShadeable::freeBSDFpool()
{
#ifdef USE_WHITE_BRDF
_bsdfPool().freeMem();
#else
if(bsdfPool())
{
_bsdfPool()->freeMem();
}
#endif
}
|