public static StringBuilder List(StringBuilder buf, BVH <Value> t, int depth) { if (t == null) { return(buf); } for (var i = 0; i < depth; i++) { buf.Append(" "); } buf.AppendFormat("({0},{1})={2}", t.offset, t.length, t.bb); if (t.IsLeaf()) { buf.AppendFormat(" Values={0}", t.Values.First.Value.id); } buf.AppendLine(); for (var i = 0; i < 2; i++) { List(buf, t.ch [i], depth + 1); } return(buf); }
static void Main(string[] args) { int nx = 300; int ny = 300; int ns = 50; var(world, cam) = Scenes.CornellScene("../../../../SampleObj/teapot.obj", new SunsetquestRandom(), nx, ny); var worldBVH = new BVH(world); var wl = new IHitable[] { worldBVH }; var pathTracer = new PathTracer(nx, ny, ns, false); uint totalRayCount = 0; sw.Start(); var image = pathTracer.RenderScene(wl, cam, ref totalRayCount, (pcComplete => Console.WriteLine($"{pcComplete}%"))); sw.Stop(); image.Save("test.png"); float seconds = sw.ElapsedMilliseconds / 1000f; float rate = totalRayCount / seconds; float mRate = rate / 1_000_000; Console.WriteLine($"totalRayCount: {totalRayCount}"); Console.WriteLine($"BVH max depth: {worldBVH.MaxTestCount}"); Console.WriteLine($"Duration: {seconds} | Rate: {mRate} MRays / sec."); }
public IEnumerator Test4MultipleItemPositionUpdate() { List <GameObject> objects = SetupScene(); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; foreach (GameObject obj in objects) { obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5); bvh.MarkForUpdate(obj); } bvh.Optimize(); bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
public void GenerateMeshTerrain() { _objects = new List <ObjectData>(); for (int i = 0; i <= MeshTerrainMeshSourceList.Count - 1; i++) { if (MeshTerrainMeshSourceList[i].MeshRenderer.GetComponent <MeshFilter>().sharedMesh == null) { continue; } ObjectData o = new ObjectData(MeshTerrainMeshSourceList[i].MeshRenderer, (int)MeshTerrainMeshSourceList[i].TerrainSourceID); if (o.IsValid) { _objects.Add(o); } } BVH.Build(ref _objects, out _nodes, out Tris, out _finalPrims); BVH.BuildLbvhData(_nodes, _finalPrims, out MeshTerrainData.lNodes, out MeshTerrainData.lPrims); MeshTerrainData.Bounds = CalculateTerrainBounds(); #if UNITY_EDITOR EditorUtility.SetDirty(MeshTerrainData); #endif //GenerateCellCoverage(); CreateNativeArrays(); VegetationStudioManager.RefreshTerrainArea(TerrainBounds); }
public IEnumerator Test5AdditionAndUpdate() { List <GameObject> objects = SetupScene(0); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; int last = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; if (t * 5 > last) { last++; GameObject obj = CreateGameObject(); objects.Add(obj); bvh.Add(obj); } foreach (GameObject obj in objects) { obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5); bvh.MarkForUpdate(obj); } bvh.Optimize(); bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
public IEnumerator Test2Addition() { List <GameObject> objects = SetupScene(0); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; int last = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; if (t * 5 > last) { last++; GameObject obj = CreateGameObject(); objects.Add(obj); bvh.Add(obj); } bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
public bool Check(BVH now, string[] items) { foreach (BVH b in bvhNext) { if (b == now) { if (now == BVH.OFFSET && items.Length != 4) { Debug.Log("now == BVH.OFFSET && items.Length != 4"); return(false); } else if (now == BVH.CHANNELS) { int cs = 0; int.TryParse(items[1], out cs); if (items.Length != cs + 2) { Debug.Log("now == BVH.CHANNELS && items.Length != cs + 2"); return(false); } } return(true); } } Debug.Log("now not in bvhNext"); return(false); }
static private void setJointData(Joint jt, int rTop, BVH now, string[] items) { int childCount = jt.jointChilds.Count; if (childCount == 0) { if (now == BVH.OFFSET) { jt.offset = new Vector3( float.Parse(items[1]), float.Parse(items[2]), float.Parse(items[3]) ); } else if (now == BVH.CHANNELS) { for (int i = 2; i < items.Length; i++) { jt.channels.Add(items[i]); } } } else { setJointData(jt.jointChilds[childCount - 1], childCount - 1, now, items); } }
public IEnumerator Test6Destroy() { List <GameObject> objects = SetupScene(); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; int last = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; if (t * 5 > last) { last++; if (objects.Count > 0) { GameObject obj = objects[objects.Count - 1]; bvh.Remove(obj); objects.RemoveAt(objects.Count - 1); Object.Destroy(obj); } } bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
private void ExecuteTests() { /// TEST //// var refPoint = new Point3D(-1, -1, -1); var transPoint = new Point3D(2, 2, 2); var transform = Util.ComputeInitialTransformation(refPoint, transPoint); Ray ray = new Ray(new Point3D(0, 0, 10), new Vector3D(0.01f, 0.08f, -1)); BBox box = new BBox(new Point3D(-1, -1, -1), new Point3D(1, 1, 1)); var hit = box.Intersect(ray); var points = _renderer.ReadData(); _rgbv._bvh = BVH.InitBVH(points); Intersection inter = _rgbv._bvh.Intersect(ray, float.MaxValue); if (inter.Hit()) { Log.WriteLog("Hit detected!!"); } Point3DCollection collection = new Point3DCollection(inter._node._objects); //_renderer.CreatePointCloud(collection, Brushes.White); Log.WriteLog("test end"); /// TEST END /// }
private void CreateSkeleton_Click(object sender, RoutedEventArgs e) { var k = group.Children.Count; for (int i = 5; i < group.Children.Count; i++) { group.Children.RemoveAt(i); } var depthData = _pcv.GetDepthDataFromLatestFrame(); _displayPointCloud = depthData.Item1; // all points _referenceFeatures = depthData.Item2; // only feature points [4] // populate all feature points // _displayPointCloud = Parser3DPoint.GetPopulatedPointCloud(point1, point2, point3, point4, _initialTransformation); //maintain most important feature point; //_thumbReference = _readingFeatures[0]; // Create BVH out of arm var bvh = new BVH(); bvh.AddAllToScene(_displayPointCloud); bvh.InitIndexing(); _rgbv._bvh = bvh; _renderer.CreatePointCloud(_displayPointCloud, Brushes.White, false); _processingStage.CompleteProcessingStage(ProcessingStage.Description.SkeletonArm); }
public void Prepare() { #if BVH if (_Accelerator == null) { _Accelerator = BVH.Construct(_Primitives); } #endif Ready = true; }
private void ExpandBVHNode(TreeNode node, bool force = false) { if (force || (node.Nodes.Count == 1 && node.Nodes[0].Tag == BVHPlaceholder)) { Util.Assert(node.Tag is BVH <Primitive>, "Attempted to expand a tree node without a BVH tag."); node.Nodes.Clear(); BVH <Primitive> bvh = (BVH <Primitive>)node.Tag; node.Nodes.Add(CreateBVHNode(bvh.Left)); node.Nodes.Add(CreateBVHNode(bvh.Right)); } }
private int BuildLBVH(BVH bvhTree, out List <LBVHNode> lbvh, out List <Sphere> spheres, out List <Quad> quads, out List <Cube> cubes, out List <Triangle> triangles) { lbvh = new List <LBVHNode>(); spheres = new List <Sphere>(); quads = new List <Quad>(); cubes = new List <Cube>(); triangles = new List <Triangle>(); if (bvhTree == null || bvhTree.root == null) { return(-1); } return(BuildLBVHNodes(bvhTree.root, ref lbvh, ref spheres, ref quads, ref cubes, ref triangles)); }
private void OpenMenuItem_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.DefaultExt = ".bvh"; dialog.Filter = "BVHファイル(*.bvh)|*.bvh"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { BVH bvh = new BVH(); bvh.Load(dialog.OpenFile()); bvhFrom.BVH = bvh; bvhTo.BVH = bvh.Convert(); menuItemUseAll.IsChecked = false; } }
private TreeNode CreateBVHNode(BVH <Primitive> bvhNode) { TreeNode node = Nodifier.CreateBVHNode(bvhNode); if (!bvhNode.IsLeaf) { node.Nodes.Add(new TreeNode("...") { Tag = BVHPlaceholder }); } return(node); }
private IEnumerator Load() { readyToPlay = false; yield return(new WaitForSeconds(1.0f)); BVH winterdustBvh = new BVH(inputBVHFile, -10, false, 0, -1, false, true, true, true, null); yield return(new WaitForEndOfFrame()); nBones = winterdustBvh.boneCount; bones = winterdustBvh.allBones; nFramesCount = winterdustBvh.frameCount; animationDuration = winterdustBvh.getDurationSec(); //BVH newScaled = winterdustBvh.scale(100.0f); //newScaled.writeToDisk("D:\\Download\\Test\\WinterdustTest\\RescaledTest.bvh", false, true); yield return(new WaitForSeconds(1.0f)); loadedClip = winterdustBvh.makeAnimationClip(); yield return(new WaitForEndOfFrame()); yield return(new WaitForSeconds(1.0f)); loadedClip.legacy = true; //anim = targetAvatar.gameObject.GetComponent<Animation>(); anim.AddClip(loadedClip, loadedClip.name); anim.clip = loadedClip; anim.playAutomatically = false; #if UNITY_EDITOR //AssetDatabase.CreateAsset(newClip, "Assets/" + newClip + ".anim"); // AssetDatabase.SaveAssets(); #endif readyToPlay = true; Debug.Log("<color=cyan>" + "READY TO PLAY" + "</color>"); }
// Use this for initialization void Start() { bhv = new BVH(BVHInput.text); rt = bhv.getRoot(); print(rt.name); mt = bhv.getMotion(); buildBody(rt); sampleBVH(rt, mt, 0.2f, 25); timeFirstKeyFrame = rt.ani.getTime(0); timeLastKeyFrame = rt.ani.getTime(rt.ani.getNumberOfKeyFrames() - 1); }
public void AddNext(BVH now) { cur = now; bvhNext.Clear(); if (now == BVH.HIERARCHY) { bvhNext.Add(BVH.ROOT); bvhNext.Add(BVH.MOTION); } else if (now == BVH.ROOT) { bvhNext.Add(BVH.OFFSET); } else if (now == BVH.OFFSET) { bvhNext.Add(BVH.CHANNELS); } else if (now == BVH.CHANNELS) { bvhNext.Add(BVH.JOINT); bvhNext.Add(BVH.End); } else if (now == BVH.JOINT) { bvhNext.Add(BVH.JOINT); bvhNext.Add(BVH.OFFSET); } else if (now == BVH.End) { bvhNext.Add(BVH.OFFSET); } else if (now == BVH.MOTION) { bvhNext.Add(BVH.FRAMES); } else if (now == BVH.FRAMES) { bvhNext.Add(BVH.FRAME_TIME); } else if (now == BVH.FRAME_TIME) { bvhNext.Add(BVH.MOTION); } }
public IEnumerator Test8AddDestroyAndUpdate() { List <GameObject> objects = SetupScene(); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; int last = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; if (t * 5 > last) { last++; if (Random.Range(0, 2) == 1) { GameObject obj = CreateGameObject(); objects.Add(obj); bvh.Add(obj); } else if (objects.Count > 0) { GameObject obj = objects[objects.Count - 1]; bvh.Remove(obj); objects.RemoveAt(objects.Count - 1); Object.Destroy(obj); } } foreach (GameObject obj in objects) { obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5); bvh.MarkForUpdate(obj); } bvh.Optimize(); bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
static private void addJoint(Joint jt, int rTop, int top, BVH now, string[] items) { int l = jt.jointChilds.Count; if (top == 0) { jt.jointChilds.Add(new Joint()); jt.jointChilds[l].name = items[1]; jt.jointChilds[l].type = JType.JOINT; if (now == BVH.End) { jt.jointChilds[l].type = JType.ENDSITE; } } else { addJoint(jt.jointChilds[l - 1], l - 1, top - 1, now, items); } }
public IEnumerator Test1CreateThroughConstruct() { List <GameObject> objects = SetupScene(); BVH <GameObject> bvh = CreateBVH(objects); float t = 0; while (t < 20) { t += Time.deltaTime; //TODO: use opengl? to render the bvh //bvh.Render(); bvh.RenderDebug(); yield return(null); } DestroyScene(objects); }
public void SetTrigles(TrigleFace[] trigles) { this.trigles = trigles; if (trigles != null && trigles.Length > 0) { Bounds3 bounds = trigles[0].BoundBox; foreach (var item in trigles) { bounds = Bounds3.Union(bounds, item.BoundBox); //item.material = _material; } this.BoundBox = bounds; } else { this.BoundBox = new Bounds3(); } CenterPoint = (BoundBox.pMin + BoundBox.pMax) * 0.5f; BVH = BVH.Build(trigles.AsSpan()); }
public static void Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { string name = req.Query["name"]; int nx = 300; int ny = 300; int ns = 50; string path = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath; path = Path.GetFullPath(path); path = Path.GetDirectoryName(path); path += @"\..\teapot.obj"; log.Info($"Obj path: {path}"); var(world, cam) = Scenes.CornellScene(path, new SunsetquestRandom(), nx, ny); var worldBVH = new BVH(world); var wl = new IHitable[] { worldBVH }; var pathTracer = new PathTracer(nx, ny, ns, false); uint totalRayCount = 0; var sw = Stopwatch.StartNew(); var image = pathTracer.RenderScene(wl, cam, ref totalRayCount, (pcComplete => log.Info($"{pcComplete}%"))); sw.Stop(); //image.Save("test.png"); float seconds = sw.ElapsedMilliseconds / 1000f; float rate = totalRayCount / seconds; float mRate = rate / 1_000_000; log.Info($"totalRayCount: {totalRayCount}"); log.Info($"BVH max depth: {worldBVH.MaxTestCount}"); log.Info($"Duration: {seconds} | Rate: {mRate} MRays / sec."); log.Info($"C# Queue trigger function processed: "); }
void OnDrawGizmos() { m_bvh = new BVH <GameObject>(); for (int i = 0; i < transform.childCount; i++) { var e = transform.GetChild(i).GetComponent <BoxCollider>(); if (e == null) { continue; } var bounds = e.bounds; AABB box = new AABB() { min = bounds.min, max = bounds.max }; Item <GameObject> item = new Item <GameObject>(e.gameObject, box); m_bvh.Insert(item); } Gizmos.color = Color.white; DrawNode(m_bvh.Root); }
public Image Render(ICameraNode camera, int sample, int max_depth) { bvh = new BVH(new List <IVisualNode>(visual_nodes)); if (sample < 1) { sample = 1; } Image image = new Image(camera.View.Width, camera.View.Height); Vector2 half_size = new Vector2(camera.View.Width / 2.0f, camera.View.Height / 2.0f); for (int y = 0; y < camera.View.Height; ++y) { for (int x = 0; x < camera.View.Width; ++x) { Vector2 uv = new Vector2((x - half_size.X) / half_size.X, (half_size.Y - y) / half_size.Y); Vector3 color = Vector3.Zero; for (int n = 0; n < sample; ++n) { Vector2 delta = new Vector2(MathHelper.RandomFloat() / camera.View.Width, MathHelper.RandomFloat() / camera.View.Height); Vector2 new_uv = uv + delta; Ray ray = camera.GetRay(new_uv.X, new_uv.Y); color += Color(ray, 0, max_depth); } color /= sample; image[x, y] = color; } } return(image); }
public static void RowTestByDelegate(int spp, string fileSuffix, Func <float, int, IMaterial> materialFunc) { var dx = 3.65f; var nX = 11; var delta = 1f / (nX - 1); var prims = new List <IPrimitive>(); for (var x = 0; x < nX; x++) { var s1t = Transform.Translate(x * dx, 0, 0); var s1 = new Sphere(s1t, Transform.Invert(s1t), false, 1.5f, -1.5f, 1.5f, 360); var s1g = new GeometricPrimitive(s1, materialFunc(delta * x, x + 1), null); prims.Add(s1g); } var slt = Transform.Translate(5, 2, -4); var slg = new Sphere(slt, Transform.Invert(slt), false, 0.5f, -0.5f, 0.5f, 360); var ls = Spectrum.FromBlackbodyT(7500); var dl = new DiffuseAreaLight(slt, null, ls * 100, 20, slg); var sg = new GeometricPrimitive(slg, new MatteMaterial(new ConstantTexture <Spectrum>(ls), new ConstantTexture <float>(0f), null), dl); prims.Add(sg); var bvh = new BVH(prims.ToArray(), SplitMethod.HLBVH); var mid = bvh.WorldBounds.Centroid; var width = 1200; var height = 140; var from = new Point(mid.X, 6f, -12f); var to = mid; var fov = 5.6f; var aspectRatio = (float)width / height; var transform = Transform.Translate(mid.X, 0f, -50f); var dist = Point.Distance(from, to); var filter = new MitchellFilter(new Vector2(2.5f, 2.5f), 0.7f, 0.15f); var film = new Film(new PixelVector(width, height), new Bounds2D(0, 0, 1, 1), filter, 20f, 1f); var camera = PerspectiveCamera.Create(transform, aspectRatio, 0.0f, dist, fov, film); //var integrator = new WhittedIntegrator(4, camera, new HaltonSampler(spp, film.GetSampleBounds()), // film.CroppedBounds); var integrator = new PathIntegrator(3, camera, new HaltonSampler(spp, film.GetSampleBounds()), film.CroppedBounds, 6f, LightSampleStrategy.Spatial); film.SetSink(new Sink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "row_" + fileSuffix)); var lt = Transform.Translate(mid.X - 60, 200, -80); var s = Spectrum.FromBlackbodyT(4500) * 100000f; var pl1 = new PointLight(lt, null, s); lt = Transform.Translate(mid.X + 100, 100, -200); s = Spectrum.FromBlackbodyT(2200) * 50000f; var pl2 = new PointLight(lt, null, s); lt = Transform.Translate(mid.X, 1000f, 0); s = Spectrum.FromBlackbodyT(7000) * 5f; var pl3 = new DistantLight(lt, s, new Vector(0, -0.5f, 1)); lt = Transform.Translate(mid.X, 10, -300); s = Spectrum.FromBlackbodyT(5500) * 100000f; var pl4 = new PointLight(lt, null, s); var splt = Transform.RotateX(MathF.Rad(18f)).RotateY(MathF.Rad(75)).Translate(0, 10, -8); s = Spectrum.FromBlackbodyT(5500) * 100000f; var sl = new SpotLight(splt, null, s, 5f, 2f); var scene = new Scene(bvh, new ILight[] { pl1, pl2, pl3, pl4, dl, sl }); //var scene = new Scene(bvh, new ILight[] { dl }); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); integrator.Render(scene); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
private FrameElement ConvertFrame(BVH dest, FrameElement srcFrame) { FrameElement destFrame = new FrameElement(dest); foreach (CompositeElement joint in dest.JointList) { JointFrame jfDest = destFrame.GetJointFrame(joint.Name); JointFrame jfSrc = srcFrame.GetJointFrame(GetSrcJointName(joint.Name)); if (jfSrc == null) continue; foreach (string channel in new string[]{"Zrotation", "Xrotation", "Yrotation"}) { jfDest.SetValue(channel, jfSrc.GetValue(channel)); } ConvertJointFrame(jfDest, joint.Name, srcFrame); } return destFrame; }
public BVHConverter(BVH src) { m_src = src; }
private static BVH SLTemplate() { BVH result = new BVH(); string template = @" HIERARCHY ROOT hip { OFFSET 0.000000 0.000000 0.000000 CHANNELS 6 Xposition Yposition Zposition Xrotation Zrotation Yrotation JOINT abdomen { OFFSET 0.000000 3.422050 0.000000 CHANNELS 3 Xrotation Zrotation Yrotation JOINT chest { OFFSET 0.000000 8.486693 -0.684411 CHANNELS 3 Xrotation Zrotation Yrotation JOINT neck { OFFSET 0.000000 10.266162 -0.273764 CHANNELS 3 Xrotation Zrotation Yrotation JOINT head { OFFSET 0.000000 3.148285 0.000000 CHANNELS 3 Xrotation Zrotation Yrotation End Site { OFFSET 0.000000 3.148289 0.000000 } } } JOINT lCollar { OFFSET 3.422053 6.707223 -0.821293 CHANNELS 3 Yrotation Zrotation Xrotation JOINT lShldr { OFFSET 3.285171 0.000000 0.000000 CHANNELS 3 Zrotation Yrotation Xrotation JOINT lForeArm { OFFSET 10.129278 0.000000 0.000000 CHANNELS 3 Yrotation Zrotation Xrotation JOINT lHand { OFFSET 8.486692 0.000000 0.000000 CHANNELS 3 Zrotation Yrotation Xrotation End Site { OFFSET 4.106464 0.000000 0.000000 } } } } } JOINT rCollar { OFFSET -3.558935 6.707223 -0.821293 CHANNELS 3 Yrotation Zrotation Xrotation JOINT rShldr { OFFSET -3.148289 0.000000 0.000000 CHANNELS 3 Zrotation Yrotation Xrotation JOINT rForeArm { OFFSET -10.266159 0.000000 0.000000 CHANNELS 3 Yrotation Zrotation Xrotation JOINT rHand { OFFSET -8.349810 0.000000 0.000000 CHANNELS 3 Zrotation Yrotation Xrotation End Site { OFFSET -4.106464 0.000000 0.000000 } } } } } } } JOINT lThigh { OFFSET 5.338403 -1.642589 1.368821 CHANNELS 3 Xrotation Zrotation Yrotation JOINT lShin { OFFSET -2.053232 -20.121670 0.000000 CHANNELS 3 Xrotation Zrotation Yrotation JOINT lFoot { OFFSET 0.000000 -19.300380 -1.231939 CHANNELS 3 Xrotation Yrotation Zrotation End Site { OFFSET 0.000000 -2.463878 4.653993 } } } } JOINT rThigh { OFFSET -5.338403 -1.642589 1.368821 CHANNELS 3 Xrotation Zrotation Yrotation JOINT rShin { OFFSET 2.053232 -20.121670 0.000000 CHANNELS 3 Xrotation Zrotation Yrotation JOINT rFoot { OFFSET 0.000000 -19.300380 -1.231939 CHANNELS 3 Xrotation Yrotation Zrotation End Site { OFFSET 0.000000 -2.463878 4.653993 } } } } } MOTION Frames: 1 Frame Time: 0.033333 0.000000 43.528519 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 "; byte[] bytes = Encoding.Default.GetBytes(template); using (MemoryStream stream = new MemoryStream(bytes)) { result.Load(stream); } foreach (CompositeElement joint in result.JointList) { switch (joint.Channels.ChannelList.Length) { case 3: joint.Channels.ChannelList[0] = "Zrotation"; joint.Channels.ChannelList[1] = "Xrotation"; joint.Channels.ChannelList[2] = "Yrotation"; break; case 6: joint.Channels.ChannelList[0] = "Xposition"; joint.Channels.ChannelList[1] = "Yposition"; joint.Channels.ChannelList[2] = "Zposition"; joint.Channels.ChannelList[3] = "Zrotation"; joint.Channels.ChannelList[4] = "Xrotation"; joint.Channels.ChannelList[5] = "Yrotation"; break; } } return result; }
// Use this for initialization void Awake() { bvh = new BVH(transform, bvhSplitMethod, 4); bvh.CreateBVH(); box = bvh; }
public IEnumerator Test9RadialRetrival() { List <GameObject> objects = SetupScene(0); BVH <GameObject> bvh = CreateBVH(objects); GameObject insideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube); insideObj1.name = "In Radius 3"; insideObj1.transform.localScale = Vector3.one * 0.01f; insideObj1.transform.position = new Vector3(0, 5, 0); GameObject insideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube); insideObj2.name = "In Radius 1"; insideObj2.transform.localScale = Vector3.one * 5; insideObj2.transform.position = new Vector3(0, -4.5f, 0); GameObject insideObj3 = GameObject.CreatePrimitive(PrimitiveType.Cube); insideObj3.name = "In Radius 2"; insideObj3.transform.localScale = Vector3.one * 5; insideObj3.transform.position = new Vector3(-5, 0, 0); GameObject outsideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube); outsideObj1.name = "Outside Radius 1"; outsideObj1.transform.localScale = Vector3.one * 5; outsideObj1.transform.position = new Vector3(0, -40, 0); GameObject outsideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube); outsideObj2.name = "Outside Radius 2"; outsideObj2.transform.localScale = Vector3.one * 5; outsideObj2.transform.position = new Vector3(-5.1f, 0, 0); objects.Add(insideObj1); bvh.Add(insideObj1); objects.Add(insideObj2); bvh.Add(insideObj2); objects.Add(insideObj3); bvh.Add(insideObj3); objects.Add(outsideObj1); bvh.Add(outsideObj1); objects.Add(outsideObj2); bvh.Add(outsideObj2); float t = 0; while (t < TIME_PER_TEST) { t += Time.deltaTime; bvh.RenderDebug(); Vector3 center = new Vector3(0, 5, 0); float radius = 10f; List <BVHNode <GameObject> > hit = bvh.Traverse(BVHHelper.RadialNodeTraversalTest(center, radius)); Debug.DrawLine(center, center + new Vector3(radius, 0, 0), Color.red); Debug.DrawLine(center, center + new Vector3(0, radius, 0), Color.green); Debug.DrawLine(center, center + new Vector3(0, 0, radius), Color.blue); Debug.Log("Traversed " + hit.Count + " nodes"); int objectCount = 0; foreach (var g in hit) { if (g.GObjects != null) { foreach (GameObject obj in g.GObjects) { Debug.Log("Found Object: " + obj.name); Assert.AreNotSame(obj.name, "Outside Radius"); objectCount++; } } } Debug.Log("Found " + objectCount + " leaf nodes"); yield return(null); } DestroyScene(objects); }
public void BuildPipeline() { if (IsInitialized) { return; } if (m_PathTracingShader == null) { return; } if (m_Camera == null) { return; } m_KernelIndex = m_PathTracingShader.FindKernel(m_KernelName); if (m_KernelIndex < 0) { return; } if (m_EnableNEE) { m_PathTracingShader.EnableKeyword("ENABLE_NEXT_EVENT_ESTIMATION"); } else { m_PathTracingShader.DisableKeyword("ENABLE_NEXT_EVENT_ESTIMATION"); } if (m_EnableThinLens) { m_PathTracingShader.EnableKeyword("ENABLE_THIN_LENS"); } else { m_PathTracingShader.DisableKeyword("ENABLE_THIN_LENS"); } if (m_EnableSampleTexture) { m_PathTracingShader.EnableKeyword("ENABLE_SAMPLE_TEXTURE"); } else { m_PathTracingShader.DisableKeyword("ENABLE_SAMPLE_TEXTURE"); } if (m_EnableTangentSpace) { m_PathTracingShader.EnableKeyword("ENABLE_TANGENT_SPACE"); } else { m_PathTracingShader.DisableKeyword("ENABLE_TANGENT_SPACE"); } m_RenderTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat); m_RenderTexture.enableRandomWrite = true; m_RenderTexture.Create(); m_DispatchThreadGroupsX = Mathf.CeilToInt((float)m_RenderTexture.width / kTileSize); m_DispatchThreadGroupsY = Mathf.CeilToInt((float)m_RenderTexture.height / kTileSize); List <PTMaterial> materials; List <Primitive> primitives; List <Texture2D> baseColorTextures = null; List <Texture2D> mroTextures = null; List <Texture2D> normalTextures = null; if (m_EnableSampleTexture) { baseColorTextures = new List <Texture2D>(); } if (m_EnableTangentSpace) { mroTextures = new List <Texture2D>(); normalTextures = new List <Texture2D>(); } CollectPrimitives(out materials, out primitives, ref baseColorTextures, ref mroTextures, ref normalTextures); BVH bvhTree = new BVH(); bvhTree.Build(primitives); List <Sphere> spheres; List <Quad> quads; List <Cube> cubes; List <Triangle> triangles; List <LBVHNode> bvh; int bvhRoot = BuildLBVH(bvhTree, out bvh, out spheres, out quads, out cubes, out triangles); if (m_EnableSampleTexture) { m_baseColorTextureArray = CreateTextureArray(baseColorTextures); m_PathTracingShader.SetTexture(m_KernelIndex, "_Textures", m_baseColorTextureArray); } if (m_EnableTangentSpace) { m_mroTextureArray = CreateTextureArray(mroTextures); m_normalTextureArray = CreateTextureArray(normalTextures); m_PathTracingShader.SetTexture(m_KernelIndex, "_MROTextures", m_mroTextureArray); m_PathTracingShader.SetTexture(m_KernelIndex, "_NormalTextures", m_normalTextureArray); } m_NodesBuffer = CreateComputeBuffer <LBVHNode>(bvh); m_SpheresBuffer = CreateComputeBuffer <Sphere>(spheres); m_QuadsBuffer = CreateComputeBuffer <Quad>(quads); m_CubeBuffer = CreateComputeBuffer <Cube>(cubes); m_TrianglesBuffer = CreateComputeBuffer <Triangle>(triangles); m_MaterialsBuffer = CreateComputeBuffer <PTMaterial>(materials); m_PathTracingShader.SetBuffer(m_KernelIndex, "_Spheres", m_SpheresBuffer); m_PathTracingShader.SetBuffer(m_KernelIndex, "_Quads", m_QuadsBuffer); m_PathTracingShader.SetBuffer(m_KernelIndex, "_Cubes", m_CubeBuffer); m_PathTracingShader.SetBuffer(m_KernelIndex, "_Triangles", m_TrianglesBuffer); m_PathTracingShader.SetBuffer(m_KernelIndex, "_BVHTree", m_NodesBuffer); m_PathTracingShader.SetBuffer(m_KernelIndex, "_Materials", m_MaterialsBuffer); m_PathTracingShader.SetInt("_BVHRootNodeIndex", bvhRoot); m_PathTracingShader.SetInt("_BVHNodeCount", bvh.Count); IsInitialized = true; m_PathTracingShader.SetTexture(m_KernelIndex, "_Result", m_RenderTexture); m_PathTracingShader.SetInt("_ScreenWidth", m_RenderTexture.width); m_PathTracingShader.SetInt("_ScreenHeight", m_RenderTexture.height); Debug.Log($"BVH Root:{bvhRoot}, BVH Childs:{bvh.Count}"); }
private static IScene Build() { var white = new MatteMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 1f }, SpectrumType.Illuminant)), new ConstantTexture <float>(0), null); var red = new PlasticMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 0f, 0f }, SpectrumType.Illuminant)), new ConstantTexture <Spectrum>(new Spectrum(0.3f)), new ConstantTexture <float>(0.0f), null, true); var yellow = new MatteMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 0f }, SpectrumType.Illuminant)), new ConstantTexture <float>(0), null); var cyan = new MatteMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0f, 1f, 1f }, SpectrumType.Illuminant)), new ConstantTexture <float>(0), null); var metal = new MetalMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.8f, 0.8f, 0.8f }, SpectrumType.Illuminant)), new ConstantTexture <Spectrum>(Spectrum.One), new ConstantTexture <float>(0.01f), null, null, null, true); var mirror = new MirrorMaterial( new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.8f, 0.8f, 0.8f }, SpectrumType.Illuminant)), null); var s1t = Transform.Translate(278, 278, 100); var s1 = new Sphere(s1t, Transform.Invert(s1t), false, 100f, -100, 100, 360); var s1g = new GeometricPrimitive(s1, mirror, null); var s2t = Transform.Translate(340, 100, 80); var s2 = new Sphere(s2t, Transform.Invert(s2t), false, 120f, -120, 120, 360); var s2g = new GeometricPrimitive(s2, cyan, null); var s3t = Transform.Translate(0, 278, 200); var s3 = new Sphere(s3t, Transform.Invert(s3t), false, 300f, -300, 300, 360); var s3g = new GeometricPrimitive(s3, yellow, null); var s4t = Transform.Translate(400, 500, 150); var s4 = new Sphere(s4t, Transform.Invert(s4t), false, 180f, -180, 180, 360); var s4g = new GeometricPrimitive(s4, metal, null); var s5t = Transform.Translate(420, 200, 250); var s5 = new Sphere(s5t, Transform.Invert(s5t), false, 180f, -180, 180, 360); var s5g = new GeometricPrimitive(s5, white, null); var s6t = Transform.Translate(500, 30, 180); var s6 = new Sphere(s6t, Transform.Invert(s6t), false, 200f, -200, 200, 360); var s6g = new GeometricPrimitive(s6, red, null); var bvh = new BVH(new IPrimitive[] { s1g, s2g, s3g, s4g, s5g, s6g }, SplitMethod.HLBVH); var lt = Transform.Translate(400, 900, -800); var s = Spectrum.FromBlackbodyT(5500) * 2000000f; var pointLight = new PointLight(lt, null, s); return(new Scene(bvh, new ILight[] { pointLight })); }