aboutsummaryrefslogtreecommitdiff
path: root/vrayPlug/plugin/shaveVrayTriShadeData.cpp
diff options
context:
space:
mode:
authorBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
committerBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
commitbd0027e737c6512397f841c22786274ed74b927f (patch)
treef7ffbdb8f3741bb7f24635616cc189cba5cb865c /vrayPlug/plugin/shaveVrayTriShadeData.cpp
downloadshave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.tar.xz
shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.zip
Adding Shave-and-a-Haircut 9.6
Diffstat (limited to 'vrayPlug/plugin/shaveVrayTriShadeData.cpp')
-rw-r--r--vrayPlug/plugin/shaveVrayTriShadeData.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/vrayPlug/plugin/shaveVrayTriShadeData.cpp b/vrayPlug/plugin/shaveVrayTriShadeData.cpp
new file mode 100644
index 0000000..7c1dbc7
--- /dev/null
+++ b/vrayPlug/plugin/shaveVrayTriShadeData.cpp
@@ -0,0 +1,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
+