欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unity虚拟天文馆

程序员文章站 2022-03-25 20:25:37
...

12万颗星,用了gpu instancing以后帧率还行
效果图:(猎户座和昴星团)
Unity虚拟天文馆
3d模式可以在星海*视角转悠
Unity虚拟天文馆

星星类

struct Star
    {
        public Vector3 position;
        public float mag;
        public float abMag;
        public float colorIndex;
    }

ui部分

private void OnGUI()
    {
        if (showUI)
        {
            GUILayout.Label("H: Hide ui");
            UpdatePerFrame = GUILayout.Toggle(UpdatePerFrame, "Update Per Frame");
            
            if (!tDMode)//天文馆
            {
                GUILayout.Label("Size Multiplier:");
                sizeMultiplier = GUILayout.HorizontalSlider(sizeMultiplier, 0, 1);

                GUILayout.Label("Pow Damp:");
                powDamp = GUILayout.HorizontalSlider(powDamp, 0, 1000000);

            
                GUILayout.Label("Pow Multiplier:");
                powMultiplier = GUILayout.HorizontalSlider(powMultiplier, 0, 10f);

                GUILayout.Label("Distance Multiplier:");
                distanceMultiplier = GUILayout.HorizontalSlider(distanceMultiplier, 0, 100000);
            }

            else//3d
            {
                GUILayout.Label("Size Multiplier:");
                sizeMultiplier = GUILayout.HorizontalSlider(sizeMultiplier, 0, 50);

                GUILayout.Label("Distance Multiplier:");
                distanceMultiplier = GUILayout.HorizontalSlider(distanceMultiplier, 0, 1);

                GUILayout.Label("Speed:");
                moveSpeed = GUILayout.HorizontalSlider(moveSpeed, 0, 20000);
            }

            sun = GUILayout.Toggle(sun,"Sun");



            string mode = "3D Mode";
            if (tDMode == true)
                mode = "Flat Mode";
            if(GUILayout.Button(mode))
            {
                tDMode = !tDMode;
                

                if (tDMode)
                {
                    sizeMultiplier = 20f;
                    powMultiplier = 1f;
                    powDamp = 0.5f;
                    distanceMultiplier = 0.1f;

                    GetComponent<Camera>().clearFlags = CameraClearFlags.Color;
                        }
                else
                {
                    sizeMultiplier = 0.05f;
                    powMultiplier = 4.41f;
                    powDamp = 960f;
                    distanceMultiplier = 10000f;

                    GetComponent<Camera>().clearFlags = CameraClearFlags.Skybox;
                }

                transform.position = Vector3.zero;

                SetStars();
            }
        }
    }
相关标签: unity unity3d