Example #1
0
        public void CheckPrototypeChanges()
        {
            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();

            if (GPUInstancerConstants.gpuiSettings.shaderBindings != null)
            {
                GPUInstancerConstants.gpuiSettings.shaderBindings.ClearEmptyShaderInstances();

                CheckForShaderBindings(detailPrototypes);
                CheckForShaderBindings(treePrototypes);
                CheckForShaderBindings(prefabPrototypes);
            }
            if (GPUInstancerConstants.gpuiSettings.billboardAtlasBindings != null)
            {
                GPUInstancerConstants.gpuiSettings.billboardAtlasBindings.ClearEmptyBillboardAtlases();

                CheckForBillboardBindinds(detailPrototypes);
                CheckForBillboardBindinds(treePrototypes);
                CheckForBillboardBindinds(prefabPrototypes);
            }
        }
 public static GPUInstancerSettings GetGPUInstancerSettings()
 {
     if (GPUInstancerConstants.gpuiSettings == null)
     {
         GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
     }
     return(GPUInstancerConstants.gpuiSettings);
 }
Example #3
0
 public static ShaderVariantCollection GetShaderVariantCollection()
 {
     if (GPUInstancerConstants.gpuiSettings.shaderVariantCollection == null)
     {
         GPUInstancerConstants.gpuiSettings.shaderVariantCollection = GPUInstancerSettings.GetDefaultShaderVariantCollection();
     }
     return(GPUInstancerConstants.gpuiSettings.shaderVariantCollection);
 }
Example #4
0
        private void Start()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                CheckPrototypeChanges();
            }
            else
            {
#endif
            MapMagic.MapMagic.OnApplyCompleted += MapMagicTerrainAddDetailManager;
            MapMagic.MapMagic.OnApplyCompleted += MapMagicTerrainAddTreeManager;
            if (useSinglePrefabManager)
            {
                MapMagic.MapMagic.OnApplyCompleted += MapMagicTerrainAddPrefabManagerSingleton;
            }
            else
            {
                MapMagic.MapMagic.OnApplyCompleted += MapMagicTerrainAddPrefabManager;
            }

            // for pinned terrains
            Terrain[] activeTerrains = Terrain.activeTerrains;
            if (activeTerrains != null)
            {
                foreach (Terrain terrain in activeTerrains)
                {
                    MapMagicTerrainAddDetailManager(terrain);
                    MapMagicTerrainAddTreeManager(terrain);
                    if (useSinglePrefabManager)
                    {
                        MapMagicTerrainAddPrefabManagerSingleton(terrain);
                    }
                    else
                    {
                        MapMagicTerrainAddPrefabManager(terrain);
                    }
                }
            }
#if UNITY_EDITOR
        }
#endif
            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();
        }
        public virtual void GeneratePrototypes(bool forceNew = false)
        {
            ClearInstancingData();

            if (forceNew || prototypeList == null)
            {
                prototypeList = new List <GPUInstancerPrototype>();
            }
            else
            {
                prototypeList.RemoveAll(p => p == null);
            }

            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();
        }
        static GPUInstancerDefines()
        {
            List <string> defineList = new List <string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup).Split(';'));

            if (!defineList.Contains(DEFINE_GPU_INSTANCER))
            {
                defineList.Add(DEFINE_GPU_INSTANCER);
                string defines = string.Join(";", defineList.ToArray());
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
            }

            GetBillboardExtensions();

            GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            SetVersionNo();

            if (previewCache == null)
            {
                previewCache = new GPUInstancerPreviewCache();
            }
        }
        public static GPUInstancerSettings GetDefaultGPUInstancerSettings()
        {
            GPUInstancerSettings gpuiSettings = Resources.Load <GPUInstancerSettings>(GPUInstancerConstants.SETTINGS_PATH + GPUInstancerConstants.GPUI_SETTINGS_DEFAULT_NAME);

            if (gpuiSettings == null)
            {
                gpuiSettings = ScriptableObject.CreateInstance <GPUInstancerSettings>();
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    if (!System.IO.Directory.Exists(GPUInstancerConstants.GetDefaultPath() + GPUInstancerConstants.RESOURCES_PATH + GPUInstancerConstants.SETTINGS_PATH))
                    {
                        System.IO.Directory.CreateDirectory(GPUInstancerConstants.GetDefaultPath() + GPUInstancerConstants.RESOURCES_PATH + GPUInstancerConstants.SETTINGS_PATH);
                    }

                    AssetDatabase.CreateAsset(gpuiSettings, GPUInstancerConstants.GetDefaultPath() + GPUInstancerConstants.RESOURCES_PATH + GPUInstancerConstants.SETTINGS_PATH + GPUInstancerConstants.GPUI_SETTINGS_DEFAULT_NAME + ".asset");
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
#endif
            }
            gpuiSettings.SetDefultBindings();
            return(gpuiSettings);
        }
Example #8
0
        public void SetUpWithGeneratorsAsset()
        {
#if UNITY_EDITOR
            Undo.RecordObject(this, "GPUI Map Magic Setup");
#endif
            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();

            terrainDetailPrototypes = new List <DetailPrototype>();
            terrainTreePrototypes   = new List <TreePrototype>();
            prefabs = new List <GameObject>();
            if (selectedPrefabs == null)
            {
                selectedPrefabs = new List <GameObject>();
            }

            if (mapMagicInstance == null)
            {
                return;
            }

            FillListsWithGeneratorsAsset(mapMagicInstance.gens);

            if (selectedPrefabs.Count > 0)
            {
                selectedPrefabs.RemoveAll(p => !prefabs.Contains(p));
            }
            else if (_selectAllPrefabs)
            {
                selectedPrefabs.AddRange(prefabs);
                _selectAllPrefabs = false;
            }
        }
        public virtual void Awake()
        {
            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();
            GPUInstancerUtility.SetPlatformDependentVariables();

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                CheckPrototypeChanges();
            }
#endif
            if (Application.isPlaying && activeManagerList == null)
            {
                activeManagerList = new List <GPUInstancerManager>();
            }

            if (SystemInfo.supportsComputeShaders)
            {
                if (_visibilityComputeShader == null)
                {
                    switch (GPUInstancerUtility.matrixHandlingType)
                    {
                    case GPUIMatrixHandlingType.MatrixAppend:
                        _visibilityComputeShader = (ComputeShader)Resources.Load(GPUInstancerConstants.VISIBILITY_COMPUTE_RESOURCE_PATH_VULKAN);
                        GPUInstancerConstants.DETAIL_STORE_INSTANCE_DATA = true;
                        GPUInstancerConstants.COMPUTE_MAX_LOD_BUFFER     = 3;
                        break;

                    case GPUIMatrixHandlingType.CopyToTexture:
                        _visibilityComputeShader        = (ComputeShader)Resources.Load(GPUInstancerConstants.VISIBILITY_COMPUTE_RESOURCE_PATH);
                        _bufferToTextureComputeShader   = (ComputeShader)Resources.Load(GPUInstancerConstants.BUFFER_TO_TEXTURE_COMPUTE_RESOURCE_PATH);
                        _bufferToTextureComputeKernelID = _bufferToTextureComputeShader.FindKernel(GPUInstancerConstants.BUFFER_TO_TEXTURE_KERNEL);
                        break;

                    default:
                        _visibilityComputeShader = (ComputeShader)Resources.Load(GPUInstancerConstants.VISIBILITY_COMPUTE_RESOURCE_PATH);
                        break;
                    }

                    _instanceVisibilityComputeKernelIDs = new int[GPUInstancerConstants.VISIBILITY_COMPUTE_KERNELS.Length];
                    for (int i = 0; i < _instanceVisibilityComputeKernelIDs.Length; i++)
                    {
                        _instanceVisibilityComputeKernelIDs[i] = _visibilityComputeShader.FindKernel(GPUInstancerConstants.VISIBILITY_COMPUTE_KERNELS[i]);
                    }
                    GPUInstancerConstants.TEXTURE_MAX_SIZE = SystemInfo.maxTextureSize;

                    _cameraComputeShader = (ComputeShader)Resources.Load(GPUInstancerConstants.CAMERA_COMPUTE_RESOURCE_PATH);
#if UNITY_2017_2_OR_NEWER
                    if (isOcclusionCulling && UnityEngine.XR.XRSettings.enabled && GPUInstancerConstants.gpuiSettings.testBothEyesForVROcclusion)
#else
                    if (isOcclusionCulling && UnityEngine.VR.VRSettings.enabled && GPUInstancerConstants.gpuiSettings.testBothEyesForVROcclusion)
#endif
                    {
                        _cameraComputeShader = (ComputeShader)Resources.Load(GPUInstancerConstants.CAMERA_VR_COMPUTE_RESOURCE_PATH);
                    }
                    _cameraComputeKernelIDs = new int[GPUInstancerConstants.CAMERA_COMPUTE_KERNELS.Length];
                    for (int i = 0; i < _cameraComputeKernelIDs.Length; i++)
                    {
                        _cameraComputeKernelIDs[i] = _cameraComputeShader.FindKernel(GPUInstancerConstants.CAMERA_COMPUTE_KERNELS[i]);
                    }
                }

                GPUInstancerConstants.SetupComputeRuntimeModification();
                GPUInstancerConstants.SetupComputeSetDataPartial();
            }
            else if (Application.isPlaying)
            {
                Debug.LogError("Target Graphics API does not support Compute Shaders. Please refer to Minimum Requirements on GPUInstancer/ReadMe.txt for detailed information.");
                this.enabled = false;
            }

            showRenderedAmount = false;

            InitializeCameraData();

#if UNITY_EDITOR && UNITY_2017_2_OR_NEWER
            EditorApplication.playModeStateChanged -= HandlePlayModeStateChanged;
            EditorApplication.playModeStateChanged += HandlePlayModeStateChanged;
#endif
        }
        public virtual void CheckPrototypeChanges()
        {
            if (GPUInstancerConstants.gpuiSettings == null)
            {
                GPUInstancerConstants.gpuiSettings = GPUInstancerSettings.GetDefaultGPUInstancerSettings();
            }
            GPUInstancerConstants.gpuiSettings.SetDefultBindings();

            if (prototypeList == null)
            {
                GeneratePrototypes();
            }
            else
            {
                prototypeList.RemoveAll(p => p == null);
            }

            if (GPUInstancerConstants.gpuiSettings != null && GPUInstancerConstants.gpuiSettings.shaderBindings != null)
            {
                GPUInstancerConstants.gpuiSettings.shaderBindings.ClearEmptyShaderInstances();
                foreach (GPUInstancerPrototype prototype in prototypeList)
                {
                    if (prototype.prefabObject != null)
                    {
                        GPUInstancerUtility.GenerateInstancedShadersForGameObject(prototype);
                        if (string.IsNullOrEmpty(prototype.warningText))
                        {
                            if (prototype.prefabObject.GetComponentInChildren <MeshRenderer>() == null)
                            {
                                prototype.warningText = "Prefab object does not contain any Mesh Renderers.";
                            }
                        }
                    }
                    else
                    {
                        if (GPUInstancerConstants.gpuiSettings.IsStandardRenderPipeline())
                        {
                            GPUInstancerConstants.gpuiSettings.AddShaderVariantToCollection(GPUInstancerConstants.SHADER_GPUI_FOLIAGE);
                        }
                        else if (GPUInstancerConstants.gpuiSettings.isURP)
                        {
                            if (Shader.Find(GPUInstancerConstants.SHADER_GPUI_FOLIAGE_URP) != null)
                            {
                                GPUInstancerConstants.gpuiSettings.AddShaderVariantToCollection(GPUInstancerConstants.SHADER_GPUI_FOLIAGE_URP);
                            }
                        }
                        else if (GPUInstancerConstants.gpuiSettings.isLWRP)
                        {
                            if (Shader.Find(GPUInstancerConstants.SHADER_GPUI_FOLIAGE_LWRP) != null)
                            {
                                GPUInstancerConstants.gpuiSettings.AddShaderVariantToCollection(GPUInstancerConstants.SHADER_GPUI_FOLIAGE_LWRP);
                            }
                        }
                    }
                }
            }
            if (GPUInstancerConstants.gpuiSettings != null && GPUInstancerConstants.gpuiSettings.billboardAtlasBindings != null)
            {
                GPUInstancerConstants.gpuiSettings.billboardAtlasBindings.ClearEmptyBillboardAtlases();
                //foreach (GPUInstancerPrototype prototype in prototypeList)
                //{
                //    if (prototype.prefabObject != null && prototype.useGeneratedBillboard &&
                //        (prototype.billboard == null || prototype.billboard.albedoAtlasTexture == null || prototype.billboard.normalAtlasTexture == null))
                //        GPUInstancerUtility.GeneratePrototypeBillboard(prototype, billboardAtlasBindings);
                //}
            }
        }