bool RayTesselatedSpherePrimitive::Intersect(const Ray& ray, Intersection* intersection) { Vec3f p; float r; float rayEpsilon; Matrix4d m; Matrix4d mi; _ResolveSphereAttrib(p,r,m,mi); // xform the ray Ray xformRay = ray; xformRay.Transform(mi); float t; bool hit = IntersectSphere(p, r, xformRay, &t, &rayEpsilon); if(hit) { intersection->rayEpsilon = rayEpsilon; intersection->t = t; intersection->dp.P = xformRay.Eval(t); intersection->dp.Ng = (intersection->dp.P - p).GetNormalized(); intersection->dp.N = intersection->dp.Ng; intersection->dp.uv[0] = (atan2f(intersection->dp.N[0], intersection->dp.N[1]) + (float)PI) / (float)(2*PI); intersection->dp.uv[1] = acosf(intersection->dp.N[2]) / (float)PI; intersection->dp.GenerateTuTv(); intersection->dp.st = intersection->dp.uv; intersection->m = material; } // xform back if(hit) { intersection->Transform(m); } return hit; }
bool RayTesselatedSpherePrimitive::Intersect(const Ray& ray) { Vec3f p; float r; Matrix4d m; Matrix4d mi; _ResolveSphereAttrib(p,r,m,mi); Ray xformRay = ray; xformRay.Transform(mi); float t, rayEpsilon; return IntersectSphere(p, r, xformRay, &t, &rayEpsilon); }
bool GeometryNode::ColourTrace(Ray R, double& closestDist, HitInfo& Hit, Matrix4x4& M) { R.Transform(m_invtrans); if (m_primitive->DepthTrace(R, closestDist, Hit, M * m_trans)) { Hit.Mat = m_material.get(); return true; } return false; }
bool GeometryNode::DepthTrace(Ray R, double& closestDist, HitInfo& Hit, Matrix4x4& M) { R.Transform(m_invtrans); bool ret = false; if (m_primitive->DepthTrace(R, closestDist, Hit, M * m_trans)) { ret = true; } return ret; }
bool GeometryNode::TimeTrace(Ray R, double& closestDist, HitInfo& Hit, Matrix4x4& M, const double& Time) { Matrix4x4 m_timetrans = M * m_trans; if (Velocity != Vector3D()) { m_timetrans.translate(Time * Velocity); R.Transform(m_timetrans.invert()); } else { R.Transform(m_invtrans); } // std::cout << "Scene:" << R.Start << "," << R.Direction << std::endl; if (m_primitive->DepthTrace(R, closestDist, Hit, m_timetrans)) { Hit.Mat = m_material.get(); return true; } return false; }
bool SceneNode::SimpleTrace(Ray R) { R.Transform(m_invtrans); for (auto iter = m_children.begin(); iter != m_children.end(); ++iter) { auto& Node = *iter; if (Node->SimpleTrace(R)) { return true; } } return false; }
bool SceneNode::ColourTrace(Ray R, double& closestDist, HitInfo& Hit, Matrix4x4& M) { R.Transform(m_invtrans); Matrix4x4 T(M * m_trans); bool ret = false; for (auto iter = m_children.begin(); iter != m_children.end(); ++iter) { auto& Node = *iter; if (Node->ColourTrace(R, closestDist, Hit, T)) { ret = true; } } return ret; }