I don't understand what this functions do exactly.
Please help me.
Please help me.
Point3 RayContext::DUVW(int channel) { // return UVW derivs for point if (duvwCache==channel) return duvw; duvwCache=channel; if (!rayresult.sd) return duvw=Point3(0,0,0); VR::Vector derivs[2]; ((VR::ShadeData*) rayresult.sd)->getUVWderivs(*this, channel, derivs); duvw=computeDiags(derivs[0], derivs[1]); if (!_finite(duvw.x+duvw.y+duvw.z)) { duvw=Point3(0.0f, 0.0f, 0.0f); } return duvw; }
void DefaultShadeData::getUVWderivs(const VR::VRayContext &vri, int channel, VR::Vector derivs[2]) { if (static_cast<const SequenceData&>(vri.vray->getSequenceData()).inMtlEditor) channel=1; RayContext &rc=*((RayContext*) &vri); VR::Vector tv[3]; if (!getTexCoords(tv, channel, rc)) { derivs[0].makeZero(); derivs[1].makeZero(); return; } VR::Vector te0=tv[1]-tv[0]; VR::Vector te1=tv[2]-tv[0]; VR::Vector offs=VR::Vector(rc.rayresult.wpoint)-rc.rayresult.faceBase; VR::Vector &e0=rc.rayresult.faceEdge0; VR::Vector &e1=rc.rayresult.faceEdge1; VR::Vector nrm=e0^e1; double D=e0*(e1^nrm); if (nrm.lengthSqr()>(D*D)*1e18f) { derivs[0].makeZero(); derivs[1].makeZero(); return; } nrm/=D; // double inverse=1.0f/D; VR::Vector su=(e1^nrm); VR::Vector sv=(nrm^e0); double dudx=rc.rayresult.dPdx*su; double dvdx=rc.rayresult.dPdx*sv; double dudy=rc.rayresult.dPdy*su; double dvdy=rc.rayresult.dPdy*sv; derivs[0]=(te0*dudx+te1*dvdx); derivs[1]=(te0*dudy+te1*dvdy); }
void RayContext::DPdUVW(Point3 dP[3], int channel) { // Bump vectors for UVW (camera space) if (!rayresult.sd) return; VR::Vector bases[3]; if (getVRayFlag(VR::VOUT_SMOOTH_UVW_DERIVS)) { ((VR::ShadeData*) rayresult.sd)->getSmoothUVWbases(*this, channel, bases); } else { ((VR::ShadeData*) rayresult.sd)->getUVWbases(*this, channel, bases); } bases[0].makeNormalized0(); bases[1].makeNormalized0(); bases[2].makeNormalized0(); if (!_finite(bases[0].x) || !_finite(bases[0].y) || !_finite(bases[0].z)) vray->getSequenceData().progress->DumpMsg(MID_RENDER, PWRN_START, "Invalid bump basis (XYZ %g, %g, %g).\n", bases[0].x, bases[0].y, bases[0].z); dP[0]=_VectorFrom(toPoint3(bases[0]), REF_WORLD); dP[1]=_VectorFrom(toPoint3(bases[1]), REF_WORLD); dP[2]=_VectorFrom(toPoint3(bases[2]), REF_WORLD); }
void DefaultShadeData::getUVWbases(const VR::VRayContext &vri, int channel, VR::Vector bases[3]) { if (static_cast<const SequenceData&>(vri.vray->getSequenceData()).inMtlEditor) channel=1; RayContext &rc=*((RayContext*) &vri); VR::Vector tv[3]; if (!getTexCoords(tv, channel, rc)) { bases[0].makeZero(); bases[1].makeZero(); bases[2].makeZero(); return; } float du0=tv[1].x-tv[0].x; float du1=tv[2].x-tv[0].x; float dv0=tv[1].y-tv[0].y; float dv1=tv[2].y-tv[0].y; VR::Vector &e0=rc.rayresult.faceEdge0; VR::Vector &e1=rc.rayresult.faceEdge1; double D=du0*dv1-du1*dv0; double DD=D*D; VR::Vector b0=(e0*dv1-e1*dv0); VR::Vector b1=(e1*du0-e0*du1); if (b0.lengthSqr()<DD*1e18f) bases[0]=b0/D; else { if (e0.lengthSqr()<(du0*du0)*1e18f) bases[0]=e0/du0; else if (e1.lengthSqr()<(du1*du1)*1e18f) bases[0]=e1/du1; else bases[0].makeZero(); } if (b1.lengthSqr()<DD*1e18f) bases[1]=b1/D; else { if (e0.lengthSqr()<(dv0*dv0)*1e18f) bases[1]=e0/dv0; else if (e1.lengthSqr()<(dv1*dv1)*1e18f) bases[1]=e1/dv1; else bases[1].makeZero(); } bases[2]=bases[0]^bases[1]; }
Comment