__host__ __device__ void shade(const Ray& ray, KernelArray<Light> lights, KernelArray<Renderable> objects, uchar4* bgnd, uchar4* out) const { // An object shader doesn't really do too much other than // supply a few critical bits of geometric information // for a surface shader. It must must compute: // // 1. the point of intersection (p) // 2. a unit-length surface normal (n) // 3. a unit-length vector towards the ray's origin (v) // Vector3Df p = ray.getOrigin() + ray.getT() * ray.getDirection(); Vector3Df v = -ray.getDirection(); Vector3Df n; switch(type) { case SPHERE: { const Vector3Df& center = parameter.data[0]; n = p - center; } break; case PLANE: { const Vector3Df& planeNormal = parameter.data[0]; n = planeNormal; } break; } n.normalize(); surface.shade<depth>(p, n, v, lights, objects, bgnd, out); }
void fix_normals(void) { for (unsigned j = 0; j<g_trianglesNo; j++) { Vector3Df worldPointA = g_vertices[g_triangles[j]._idx1]; Vector3Df worldPointB = g_vertices[g_triangles[j]._idx2]; Vector3Df worldPointC = g_vertices[g_triangles[j]._idx3]; Vector3Df AB = worldPointB; AB -= worldPointA; Vector3Df AC = worldPointC; AC -= worldPointA; Vector3Df cr = cross(AB, AC); cr.normalize(); g_triangles[j]._normal = cr; g_vertices[g_triangles[j]._idx1]._normal += cr; g_vertices[g_triangles[j]._idx2]._normal += cr; g_vertices[g_triangles[j]._idx3]._normal += cr; } for (unsigned j = 0; j<g_trianglesNo; j++) { g_vertices[g_triangles[j]._idx1]._normal.normalize(); g_vertices[g_triangles[j]._idx2]._normal.normalize(); g_vertices[g_triangles[j]._idx3]._normal.normalize(); } }
void InteractiveCamera::strafe(float m){ Vector3Df strafeAxis = cross(viewDirection, Vector3Df(0, 1, 0)); strafeAxis.normalize(); centerPosition += strafeAxis * m; }