Example #1
0
        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);
        }
Example #2
0
        public void AddMesh(TriangleMesh mesh)
        {
            uint meshId = (uint)TinyEmbreeCore.AddTriangleMesh(sceneId, mesh.Vertices, mesh.NumVertices,
                                                               mesh.Indices, mesh.NumFaces * 3);

            meshMap[meshId] = mesh;
        }
Example #3
0
 void Free()
 {
     if (scene != IntPtr.Zero)
     {
         TinyEmbreeCore.DeleteScene(scene);
         scene = IntPtr.Zero;
     }
 }
Example #4
0
 public Raytracer()
 {
     sceneId = TinyEmbreeCore.InitScene();
 }
Example #5
0
 public void CommitScene()
 {
     TinyEmbreeCore.FinalizeScene(sceneId);
 }
Example #6
0
 /// <summary>
 /// Builds the acceleration structure
 /// </summary>
 public void CommitScene()
 {
     TinyEmbreeCore.FinalizeScene(scene);
     isReady = true;
 }