// Returns index of triangle intersected by central axis of lightfield cell's beam // Returns -1 if no triangle is intersected private int BeamTriangleSimpleIntersect(Coord4D lfCoord, RenderContext context) { // switch to tracing the canonical ray associated with this lightfield entry, instead of the original ray (to avoid biasing values in lightfield) Vector cellRayStart; Vector cellRayDir; lightFieldCache.Coord4DToRay(lfCoord, out cellRayStart, out cellRayDir); // TODO: once the light field cache 'fills up', do we cease tracing rays? Prove/measure this! // trace a primary ray against all triangles in scene // TODO: trace multiple rays to find the triangle with largest cross-section in the beam corresponding to this lightfield cell? // This may also avoid incorrectly storing 'missing triangle' value when primary ray misses because there are no triangles along central axis of cell's beam. IntersectionInfo intersection = geometry_subdivided.IntersectRay(cellRayStart, cellRayDir, context); if (intersection == null) { return(-1); } else { Contract.Assert(intersection.triIndex >= 0); return(intersection.triIndex); } }
private uint CalcColorForCoord(Coord4D lfCoord, RenderContext context) { // Index into light field cache using 4D spherical coordinates uint lfCacheEntry = lightFieldCache.ReadCache(lfCoord.Item1, lfCoord.Item2, lfCoord.Item3, lfCoord.Item4); if (lfCacheEntry != lightFieldCache.EmptyCacheEntry) { // lightfield stores colors, and we found a color entry to return return(lfCacheEntry); } // switch to tracing the ray associated with this lightfield entry, instead of the original ray (to avoid biasing values in lightfield) Vector rayStart; Vector rayDir; lightFieldCache.Coord4DToRay(lfCoord, out rayStart, out rayDir); // TODO: once the light field cache 'fills up', do we cease tracing rays? Prove/measure this! // we did not find a color in the light field corresponding to this ray, so trace this ray against the geometry // TODO: this line is the major performance bottleneck! IntersectionInfo info = geometry.IntersectRay(rayStart, rayDir, context); if (info == null) { // ray did not hit the geometry, so cache background color into the 4D light field lightFieldCache.WriteCache(lfCoord.Item1, lfCoord.Item2, lfCoord.Item3, lfCoord.Item4, backgroundColor); return(backgroundColor); } // TODO: this is where lots of other AO, shadow code etc used to execute // cache ray colors in a 4D light field? lightFieldCache.WriteCache(lfCoord.Item1, lfCoord.Item2, lfCoord.Item3, lfCoord.Item4, info.color); return(info.color); }