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
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
#include "shaveVrayTriShadeData.h"
#include "shaveVrayInstanceI.h"
#include "shaveVrayTriVoxelPrim.h"
#include "shaveVrayStaticTriVoxelPrim.h"
#include "misc_ray.h"
shaveVrayTriShadeData::shaveVrayTriShadeData(shaveVrayInstanceI *instance)
: BaseShadeData(instance)
{
}
void shaveVrayTriShadeData::init(const VR::TraceTransform &itm)
{
this->itm=itm*0.01f;
}
bool shaveVrayTriShadeData::getUVWTriVerts(const VR::VRayContext &rc, VR::ShadeVec &t0, VR::ShadeVec &t1, VR::ShadeVec &t2)
{
shaveVrayInstanceI* I = static_cast<shaveVrayInstanceI*>(instance);
const VR::RayResult& rres = rc.rayresult;
assert(PRIM_TYPE_STATIC_TRIANGLE == rres.primitive->type() ||
PRIM_TYPE_MOVING_TRIANGLE == rres.primitive->type());
if(PRIM_TYPE_STATIC_TRIANGLE != rres.primitive->type() &&
PRIM_TYPE_MOVING_TRIANGLE != rres.primitive->type())
return false;
int fidx = rres.faceIndex;
if(I->GetNumFacesPerInst() == 0)
return false;
int tidx = fidx % I->GetNumFacesPerInst();
int i0 = tidx*3;
int i1 = i0 + 1;
int i2 = i1 + 1;
t0 = toShadeVec(I->GetUV(i0));
t1 = toShadeVec(I->GetUV(i1));
t2 = toShadeVec(I->GetUV(i2));
return true;
}
#if defined(VRAY30)
VR::Transform shaveVrayTriShadeData::getLocalUVWTransform(const VR::VRayContext &rc, int channel)
{
(void) channel; //unused
VR::Transform result(1);
VR::Vector t0, t1, t2;
if (!getUVWTriVerts(rc, t0, t1, t2)) {
return result;
}
const VR::RayResult& rres = rc.rayresult;
const VR::Vector& bary = rres.bary;
result.offs = bary.x*t0 + bary.y*t1 + bary.z*t2;
VR::Vector dt0 = t1 - t0;
VR::Vector dt1 = t2 - t0;
if(!computeUVWMatrix(rres.faceEdge0, rres.faceEdge1, dt0, dt1, result.m))
result.m = VR::Matrix(1);
return result;
}
VR::Vector shaveVrayTriShadeData::getLocalUVWCoordinates(const VR::VRayContext &rc, int channel)
{
(void) channel; //unused
VR::Vector t0, t1, t2;
if (!getUVWTriVerts(rc, t0, t1, t2)) {
return VR::Vector();
}
const VR::RayResult& rres = rc.rayresult;
const VR::Vector& bary = rres.bary;
VR::Vector t = bary.x*t0 + bary.y*t1 + bary.z*t2;
return t;
}
#elif defined(VRAY40)
void shaveVrayTriShadeData::getLocalUVWTransform(const VR::VRayContext &rc, int channel, VR::ShadeTransform &result)
{
(void) channel; //unused
VR::ShadeVec t0, t1, t2;
if (!getUVWTriVerts(rc, t0, t1, t2)) {
result.makeIdentity();
return;
}
const VR::RayResult& rres = rc.rayresult;
const VR::ShadeVec& bary = rres.bary;
result.offs = VR::x(bary)*t0 + VR::y(bary)*t1 + VR::z(bary)*t2;
VR::ShadeVec dt0 = t1 - t0;
VR::ShadeVec dt1 = t2 - t0;
if(!VUtils::computeUVWMatrix(rres.faceEdge0, rres.faceEdge1, dt0, dt1, result.m))
result.m.makeIdentity();
}
void shaveVrayTriShadeData::getLocalUVWCoordinates(const VR::VRayContext &rc, int channel, VR::ShadeVec &result)
{
(void) channel; //unused
VR::ShadeVec t0, t1, t2;
if (!getUVWTriVerts(rc, t0, t1, t2)) {
result.makeZero();
}
const VR::RayResult& rres = rc.rayresult;
const VR::ShadeVec& bary = rres.bary;
result = VR::x(bary)*t0 + VR::y(bary)*t1 + VR::z(bary)*t2;
}
int shaveVrayTriShadeData::getLocalUVWTransformByName(const VR::VRayContext &rc, const VR::StringID &channelName, VR::ShadeTransform &result)
{
(void) rc;
(void) channelName;
(void) result;
return channelNotFound;
}
int shaveVrayTriShadeData::getUVWCoordinatesByName(const VR::VRayContext &rc, const VR::StringID &channelName, VR::ShadeVec &result)
{
(void) rc;
(void) channelName;
(void) result;
return channelNotFound;
}
VR::ShadeVec shaveVrayTriShadeData::getMapChannelVertexVector(int mapChannelIdx, int vertexIdx)
{
(void)mapChannelIdx;
(void)vertexIdx;
return VR::ShadeVec(0.0f);
}
VR::ShadeVec shaveVrayTriShadeData::getUVWcoords(const VR::VRayContext &rc, int channel) {
return getMappedUVWcoords(rc, *this, channel);
}
void shaveVrayTriShadeData::getUVWderivs(const VR::VRayContext &rc, int channel, VR::ShadeVec derivs[2]) {
getMappedUVWderivs(rc, *this, channel, derivs);
}
void shaveVrayTriShadeData::getUVWbases(const VR::VRayContext &rc, int channel, VR::ShadeVec bases[3]) {
getMappedUVWbases(rc, *this, channel, bases);
}
VR::ShadeVec shaveVrayTriShadeData::getUVWnormal(const VR::VRayContext &rc, int channel) {
return getMappedUVWnormal(rc, *this, channel);
}
#endif
|