public Hit Trace(Ray ray) { var minHit = TinyEmbreeCore.TraceSingle(sceneId, ray); if (minHit.meshId == uint.MaxValue) { return(new Hit()); } Hit hit = new Hit { BarycentricCoords = new Vector2(minHit.u, minHit.v), Distance = minHit.distance, Mesh = meshMap[minHit.meshId], PrimId = minHit.primId }; // Compute the position and face normal from the barycentric coordinates hit.Position = hit.Mesh.ComputePosition((int)hit.PrimId, hit.BarycentricCoords); hit.Normal = hit.Mesh.FaceNormals[hit.PrimId]; // Compute the error offset (formula taken from Embree example renderer) hit.ErrorOffset = Math.Max( Math.Max(Math.Abs(hit.Position.X), Math.Abs(hit.Position.Y)), Math.Max(Math.Abs(hit.Position.Z), hit.Distance) ) * 32.0f * 1.19209e-07f; return(hit); }
public void AddMesh(TriangleMesh mesh) { uint meshId = (uint)TinyEmbreeCore.AddTriangleMesh(sceneId, mesh.Vertices, mesh.NumVertices, mesh.Indices, mesh.NumFaces * 3); meshMap[meshId] = mesh; }
void Free() { if (scene != IntPtr.Zero) { TinyEmbreeCore.DeleteScene(scene); scene = IntPtr.Zero; } }
public Raytracer() { sceneId = TinyEmbreeCore.InitScene(); }
public void CommitScene() { TinyEmbreeCore.FinalizeScene(sceneId); }
/// <summary> /// Builds the acceleration structure /// </summary> public void CommitScene() { TinyEmbreeCore.FinalizeScene(scene); isReady = true; }