Exemple #1
0
        IEnumerator Start()
        {
            groups = GameObject.FindObjectsOfType <AsyncLodGroup>();

            cull = new CullingGroup();
            cull.targetCamera = Camera.main;
            cull.SetDistanceReferencePoint(Camera.main.transform);

            spheres = new BoundingSphere[groups.Length];
            for (int i = 0; i < spheres.Length; i++)
            {
                spheres[i].radius = 1f;
            }
            cull.SetBoundingSpheres(spheres);
            cull.SetBoundingSphereCount(spheres.Length);

            cull.SetBoundingDistances(distances);
            cull.onStateChanged += (ev) => {
                int level = ev.isVisible ? ev.currentDistance : distances.Length;
                groups[ev.index].SetLevel(level);
            };
            yield return(null);

            GameObject.FindObjectOfType <AsyncUpdateManager>().StartUpdate();
            yield return(null);

            SetActive(true);
        }
Exemple #2
0
    public override void Init(GPUSkinning gpuSkinning)
    {
        base.Init(gpuSkinning);

        newLodMesh           = new Mesh();
        newLodMesh.vertices  = lodMesh.vertices;
        newLodMesh.uv        = lodMesh.uv;
        newLodMesh.triangles = lodMesh.triangles;
        newLodMesh.tangents  = GPUSkinningUtil.ExtractBoneWeights(lodMesh);

        additionalVertexStreames = new GPUSkinning_AdditionalVertexStreames(newLodMesh);

        // Bounding Sphere
        lodBoundingSpheres = new BoundingSphere[gpuSkinning.model.spawnObjects.Length];
        for (int i = 0; i < lodBoundingSpheres.Length; ++i)
        {
            lodBoundingSpheres[i] = new BoundingSphere(gpuSkinning.model.spawnObjects[i].transform.position, 1f);
        }

        // Culling Group
        lodCullingGroup = new CullingGroup();
        lodCullingGroup.targetCamera = Camera.main;
        lodCullingGroup.SetBoundingSpheres(lodBoundingSpheres);
        lodCullingGroup.SetBoundingSphereCount(lodBoundingSpheres.Length);
        lodCullingGroup.SetBoundingDistances(new float[] { 10, 15, 25, 40 });
        lodCullingGroup.SetDistanceReferencePoint(Camera.main.transform);
        lodCullingGroup.onStateChanged = OnLodCullingGroupOnStateChangedHandler;

        newLodMesh.UploadMeshData(true);
    }
Exemple #3
0
        // Base voids
        private void InitializeCulling()
        {
            DestroyCulling();                   // destroy old group
            _CullingGroup = new CullingGroup(); // initialize new culling group

            // Get Cache values
            float   MaxPatchSize = Mathf.Max(Manager.PatchRounded.x, Manager.PatchRounded.y);
            Vector3 Position     = Manager.Terrain.transform.position;

            // Set Settings
            _CullingGroup.targetCamera = Camera.main;

            // set bounding spheres
            _CullingSpheres = new BoundingSphere[Patches.Length];             // initialize bounding spheres
            for (int i = 0; i < _CullingSpheres.Length; i++)
            {
                _CullingSpheres [i] = new BoundingSphere(Position + Patches[i].RelativePosition, MaxPatchSize);
            }

            _CullingGroup.onStateChanged = OnCullingChanged;

            _CullingGroup.SetBoundingDistances(Manager.LODFloatDistances);
            _CullingGroup.SetBoundingSpheres(_CullingSpheres);
            _CullingGroup.SetBoundingSphereCount(_CullingSpheres.Length);
        }
Exemple #4
0
    void OnEnable()
    {
        m_camera    = GetComponent <Camera>();
        m_cullGroup = new CullingGroup();
        m_cullGroup.SetBoundingSpheres(m_spheres);

        //Break dependance on Resources? Could cause stalls for people grmbl
        m_vaporCompute         = Resources.Load <ComputeShader>("VaporSim");
        m_densityKernel        = m_vaporCompute.FindKernel("FogDensity");
        ZoneKernel             = m_vaporCompute.FindKernel("ZoneWrite");
        LightPointKernel       = m_vaporCompute.FindKernel("LightPoint");
        LightSpotKernel        = new VaporKernel(m_vaporCompute, "LightSpot");
        LightDirKernel         = new VaporKernel(m_vaporCompute, "LightDirectional");
        m_lightClearKernel     = m_vaporCompute.FindKernel("LightClear");
        m_scatterKernel        = m_vaporCompute.FindKernel("Scatter");
        m_integrateKernel      = m_vaporCompute.FindKernel("Integrate");
        m_integrateClearKernel = m_vaporCompute.FindKernel("IntegrateClear");
        m_fogMat           = new Material(Shader.Find("Hidden/VaporPost"));
        m_fogMat.hideFlags = HideFlags.HideAndDontSave;

        m_blueNoiseTex = Resources.Load <Texture2D>("BlueNoise");

        CreateTextures();
        MarkInstantRender();
    }
	void OnDisable()
	{
		// コルーチンを停止してcullinggroupを破棄
		StopCoroutine (spawnFlow);
		cullingGroup.Dispose ();
		cullingGroup = null;
	}
 public void SetCamera(Camera cam)
 {
     if (cam != null)
     {
         if (mCullingSpheres == null)
         {
             InitCapacity(m_CullingCapacity);
         }
         if (mCullingGroup == null)
         {
             if (mDistanceLvs == null)
             {
                 mDistanceLvs = new float[4];
             }
             mDistanceLvs[0] = m_DistanceLv.x;
             mDistanceLvs[1] = m_DistanceLv.y;
             mDistanceLvs[2] = m_DistanceLv.z;
             mDistanceLvs[3] = m_DistanceLv.w;
             mCullingGroup   = new CullingGroup();
             mCullingGroup.SetBoundingDistances(mDistanceLvs);
             mCullingGroup.SetDistanceReferencePoint(transform);
             mCullingGroup.SetBoundingSpheres(mCullingSpheres);
             mCullingGroup.SetBoundingSphereCount(mCullLength);
             mCullingGroup.onStateChanged = OnCullStateChanged;
         }
         mCullingGroup.targetCamera = cam;
         mCullingGroup.enabled      = true;
     }
     else if (mCullingGroup != null)
     {
         mCullingGroup.enabled = false;
     }
 }
    private void OnEnable()
    {
        Cam  = Camera.GetComponent <Camera>();
        objT = obj[0].gameObject.GetComponent <Transform>();

        group = new CullingGroup();

        // Adding a foreach loop, which iterates through each element in the list of gameobjects "obj" and adds them to the culling list of game objects.
        foreach (GameObject item in obj)
        {
            Culling.Add(item);
        }
        //Culling.Add(obj[0]);
        //Culling[1] = obj[1];


        //spheres[0] = new BoundingSphere(new Vector3(0, 0.4f, 0), 5f);

        Debug.Log(Culling[0] + " Culling OBJ");

        group.onStateChanged = StateChangedMethod;
        group.SetBoundingSpheres(spheres);
        group.SetBoundingSphereCount(1);

        Debug.Log(spheres[0] + " Spheres");

        group.targetCamera = Cam;

        // group.IsVisible(0);
    }
Exemple #8
0
    private void Start()
    {
        m_group = new CullingGroup();

        // 設置相機進行剔除
        m_group.targetCamera = Camera.main;

        // 設置用於測量距離和距離水平的中心座標
        // 1:1米2:5米3:10米,4:30米,5:100米或更長:看不見的處理
        m_group.SetDistanceReferencePoint(Camera.main.transform);
        m_group.SetBoundingDistances(new float[] { 1, 5, 10, 30, 100 });

        // Search layer of all gameobjects in hierarchy.
        var array = Shinn.Utility.Bitmask2Array(layer.value);

        targets = FindGameObjectsWithLayer(array);

        // 設置列表以執行可見性確定
        m_bounds = new BoundingSphere[targets.Length];
        for (int i = 0; i < m_bounds.Length; i++)
        {
            m_bounds[i].radius = 1.5f;
        }

        // 註冊對列表的引用
        m_group.SetBoundingSpheres(m_bounds);
        m_group.SetBoundingSphereCount(targets.Length);

        // 註冊當對象可見性發生變化時的回調
        m_group.onStateChanged = OnChange;
    }
    void OnEnable()
    {
        // Do we need custom culling?
        if (target.proceduralSimulationSupported)
        {
            Debug.Log(name + " does not need custom culling");
            enabled = false;
            return;
        }

        if (m_ParticleRenderers == null)
        {
            m_ParticleRenderers = target.GetComponentsInChildren <Renderer>();
        }

        if (m_CullingGroup == null)
        {
            m_CullingGroup = new CullingGroup();
            m_CullingGroup.targetCamera = Camera.main;
            m_CullingGroup.SetBoundingSpheres(new[] { new BoundingSphere(transform.position, cullingRadius) });
            m_CullingGroup.SetBoundingSphereCount(1);
            m_CullingGroup.onStateChanged += OnStateChanged;
        }

        // We need to sync the culled state.
        Cull(m_CullingGroup.IsVisible(0));
        m_CullingGroup.enabled = true;
    }
        private float modelRadius = 0.4f; // Temp data

        public CullingGroupManager()
        {
            // Temp data
            groupCount = 500;

            boundingSpheresIndex = 0;
            boundingSpheres      = new BoundingSphere[groupCount]; // Temp count

            cullingGroup = new CullingGroup();
            cullingGroup.SetBoundingSpheres(boundingSpheres);
            cullingGroup.SetBoundingSphereCount(groupCount);
            cullingGroup.onStateChanged = HandleCullingStateChange;
            cullingGroup.targetCamera   = Camera.main;

            boundingSpheresDic = new Dictionary <int, UnitRender>();
            usedIndexPool      = new List <int>();
            unusedIndexPool    = new List <int>();

            for (int i = 0; i < groupCount; i++)
            {
                unusedIndexPool.Add(i);
            }

            SetCullMode();
        }
Exemple #11
0
    void Start()
    {
        // All the objects that have a sphere tag
        var gobjs = GameObject.FindGameObjectsWithTag("Sphere");

        targets = new Transform[gobjs.Length];
        for (int i = 0; i < gobjs.Length; i++)
        {
            targets[i] = gobjs[i].transform;
        }

        cullingGroup = new CullingGroup();

        cullingGroup.targetCamera = Camera.main;
        // Will automatically track the transform
        cullingGroup.SetDistanceReferencePoint(transform);
        // The distance points when the event will trigger
        cullingGroup.SetBoundingDistances(new float[] { 25.0f });
        // Creating Boundingspheres
        bounds = new BoundingSphere[targets.Length];
        for (int i = 0; i < bounds.Length; i++)
        {
            bounds[i].radius = 1.5f;
        }
        // Assigning the Bounding spheres
        cullingGroup.SetBoundingSpheres(bounds);
        // if not set it will use all of the array elements(so below code is redundant)
        cullingGroup.SetBoundingSphereCount(targets.Length);
        // Assigning an event when the distance changes
        cullingGroup.onStateChanged = OnChange;
    }
        public BatchCulling([NotNull] Camera camera, [NotNull] WetDecalSystem.MaterialBatch batch)
        {
            if (camera == null)
            {
                throw new ArgumentNullException("camera");
            }
            if (batch == null)
            {
                throw new ArgumentNullException("batch");
            }

            _camera = camera;
            _batch  = batch;

            _visibleIndices     = new int[8];
            _distanceThresholds = new[] { camera.nearClipPlane, camera.farClipPlane };

            _culling = new CullingGroup {
                targetCamera = camera
            };
            _culling.SetBoundingDistances(_distanceThresholds);
            _culling.SetDistanceReferencePoint(camera.transform);
            _culling.SetBoundingSpheres(batch.BoundingSpheres);
            _culling.SetBoundingSphereCount(batch.Decals.Count);
        }
Exemple #13
0
    public static int set_onStateChanged(IntPtr l)
    {
        int result;

        try
        {
            CullingGroup cullingGroup = (CullingGroup)LuaObject.checkSelf(l);
            CullingGroup.StateChanged stateChanged;
            int num = LuaObject.checkDelegate <CullingGroup.StateChanged>(l, 2, out stateChanged);
            if (num == 0)
            {
                cullingGroup.onStateChanged = stateChanged;
            }
            else if (num == 1)
            {
                CullingGroup cullingGroup2 = cullingGroup;
                cullingGroup2.onStateChanged = (CullingGroup.StateChanged)Delegate.Combine(cullingGroup2.onStateChanged, stateChanged);
            }
            else if (num == 2)
            {
                CullingGroup cullingGroup3 = cullingGroup;
                cullingGroup3.onStateChanged = (CullingGroup.StateChanged)Delegate.Remove(cullingGroup3.onStateChanged, stateChanged);
            }
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemple #14
0
        public void ApplyLods()
        {
            LodsCount = LodLevels.Length;
            float[] RenderDistances = new float[LodsCount];
            for (int i = 0; i < LodsCount; i++)
            {
                if (LodLevels[i].Lod == null)
                {
                    LodLevels[i].Lod = new HashSet <Matrix4x4>();
                }
                else
                {
                    LodLevels[i].Lod.Clear();
                }

                RenderDistances[i] = LodLevels[i].Distance;
            }

            _matrices      = new Matrix4x4[1023];
            InstancesArray = new RenderInstance[MaxMemoryAllocation];
            SpheresArray   = new BoundingSphere[MaxMemoryAllocation];
            Instances      = new HashSet <RenderInstance>();
            Count          = 0;

            if (Culling == null)
            {
                Culling = new CullingGroup();
                Culling.SetBoundingDistances(RenderDistances);
                Culling.onStateChanged = UpdateLods;
                Culling.targetCamera   = CameraControler.Current.Cam;
            }
        }
Exemple #15
0
        /// <summary>
        /// Disposes the managed members and unregisters events
        /// </summary>
        public void Dispose()
        {
            _cullingGroup.Dispose();
            _cullingGroup = null;

            Aura.OnPreCullEvent -= Aura_onPreCullEvent;
        }
                public void Initialize(int numRequests, CullingGroup cullingGroup)
                {
                    Assert.IsNull(m_CullingGroup);

                    m_NumRequest   = numRequests;
                    m_CullingGroup = cullingGroup;
                }
Exemple #17
0
    void Start()
    {
        /*
         * if (!m_UsedCamera)
         *  m_UsedCamera = Camera.main;
         */

        for (int i = 0; i < m_ManagedTerrains.Length; i++)
        {
            TreeSystemTerrain terrain = m_ManagedTerrains[i];

            if (terrain.m_ManagedTerrain != null)
            {
                terrain.m_ManagedTerrain.drawTreesAndFoliage = false;
            }

            terrain.m_CellsStructured = new TreeSystemStructuredTrees[terrain.m_CellCount, terrain.m_CellCount];

            CullingGroup cullingGroup = new CullingGroup();

            BoundingSphere[] bounds = new BoundingSphere[terrain.m_Cells.Length];

            for (int j = 0; j < terrain.m_Cells.Length; j++)
            {
                // TODO: maybe allocate dinamically at runtime based on cell visibility to save memory
                terrain.m_Cells[j].m_InstanceData = new TreeSystemLODInstance[terrain.m_Cells[j].m_Instances.Length];

                // TODO: structure cell data

                // Create the culling group data
                bounds[j] = new BoundingSphere(terrain.m_Cells[j].m_BoundsSphere.m_CenterRadius);

                // Structure cell data
                RowCol pos = terrain.m_Cells[j].m_Position;
                terrain.m_CellsStructured[pos.m_Row, pos.m_Col] = terrain.m_Cells[j];
            }

            if (!m_Settings.m_UsedCamera)
            {
                cullingGroup.targetCamera = Camera.main;
            }
            else
            {
                cullingGroup.targetCamera = m_Settings.m_UsedCamera;
            }

            cullingGroup.SetBoundingSpheres(bounds);
            cullingGroup.SetBoundingSphereCount(bounds.Length);

            // Save the bounds just in case we might need them
            terrain.m_CullingGroupSpheres = bounds;
            terrain.m_CullingGroup        = cullingGroup;
        }

        if (m_Settings.m_ApplyTreeColliders)
        {
            SetApplyColliders(true);
        }
    }
 /// <summary>
 /// Raises the disable event.
 /// </summary>
 void OnDisable()
 {
     if (group != null)
     {
         group.Dispose();
         group = null;
     }
 }
Exemple #19
0
 void OnDisable()
 {
     if (Culling != null)
     {
         Culling.Dispose();
         Culling = null;
     }
 }
Exemple #20
0
 public void Dispose()
 {
     if (cullingGroup != null)
     {
         cullingGroup.Dispose();
         cullingGroup = null;
     }
 }
Exemple #21
0
 public void Dispose()
 {
     if (CullingGroup != null)
     {
         CullingGroup.Dispose();
         CullingGroup = null;
     }
 }
Exemple #22
0
        public CullingHelper()
        {
            boundingSpheres = new BoundingSphere[1];

            cullingGroup = new CullingGroup();
            cullingGroup.SetBoundingSpheres(boundingSpheres);
            cullingGroup.SetBoundingSphereCount(1);
        }
Exemple #23
0
 private void OnDestroy()
 {
     cullingGroup.targetCamera    = null;
     cullingGroup.onStateChanged -= OnStateChanged;
     cullingGroup.Dispose();
     cullingGroup              = null;
     SceneManager.sceneLoaded -= SceneLoaded;
 }
Exemple #24
0
 private void SetupCullingGroup()
 {
     cullGroup = new CullingGroup();
     cullGroup.targetCamera = Camera.main;
     cullGroup.SetBoundingSpheres(new BoundingSphere[] { new BoundingSphere(transform.position, cullRadius) });
     cullGroup.SetBoundingSphereCount(1);
     cullGroup.onStateChanged += OnStateChanged;
 }
 private void DestroyCullingGroup()
 {
     if (cullingGroup != null)
     {
         cullingGroup.Dispose();
         cullingGroup = null;
     }
 }
 void OnDestroy()
 {
     if (group != null)
     {
         group.Dispose();
         group = null;
     }
 }
 void Awake()
 {
     Distances = new float[4] {
         10f, 20f, 45f, 100f
     };
     group = new CullingGroup();
     group.targetCamera = GetComponent <Camera>();
 }
Exemple #28
0
 void ClearCullingGroup()
 {
     if (culling_group != null)
     {
         culling_group.Dispose();
         culling_group = null;
     }
 }
Exemple #29
0
        public void PrepareCull(CullingGroup cullingGroup, PlanarReflectionProbe[] planarReflectionProbesArray)
        {
            Assert.IsNull(m_CullingGroup, "Culling was prepared but not used nor disposed");
            Assert.IsNull(m_Probes, "Culling was prepared but not used nor disposed");

            m_CullingGroup = cullingGroup;
            m_Probes       = planarReflectionProbesArray;
        }
Exemple #30
0
 public void CullPlanarReflectionProbes(CullingGroup cullingGroup, PlanarReflectionProbe[] planarReflectionProbes)
 {
     visiblePlanarReflectionProbeCount = cullingGroup.QueryIndices(true, m_PlanarReflectionProbeIndices, 0);
     for (var i = 0; i < visiblePlanarReflectionProbeCount; ++i)
     {
         m_VisiblePlanarReflectionProbes[i] = planarReflectionProbes[m_PlanarReflectionProbeIndices[i]];
     }
 }
Exemple #31
0
 private void OnDestroy()
 {
     if (_cullingGroup != null)
     {
         _cullingGroup.Dispose();
         _cullingGroup = null;
     }
 }
Exemple #32
0
    // we use the horizontal distance and the vertical difference between the y components to determine when to draw an object
    private bool IsBeyondDrawDistance(Vector3 playerPosition, Vector3 objectPosition, CullingGroup cullingGroup)
    {
        Vector3 playerHorizontalPosition = playerPosition;
        playerHorizontalPosition.y = 0;
        Vector3 objectHorizontalPosition = objectPosition;
        objectHorizontalPosition.y = 0;

        return cullingGroup.horizontalCulling && (Vector3.Distance(playerHorizontalPosition, objectHorizontalPosition) > cullingGroup.horizontalCullDistance)
            || cullingGroup.verticalUpwardsCulling && ((playerPosition.y - objectPosition.y) < -cullingGroup.verticalUpwardsCullDistance)
            || cullingGroup.verticalDownwardsCulling && ((playerPosition.y - objectPosition.y) > cullingGroup.verticalDownwardsCullDistance);
    }
	void SetupCullinggroup()
	{
		// culling groupの初期化
		cullingGroup = new CullingGroup ();
		cullingGroup.targetCamera = Camera.main;

		// 敵を生成する座標の登録
		BoundingSphere[] bounds = new BoundingSphere[targetPositions.Length];
		for (int i = 0; i < targetPositions.Length; i++) {
			bounds [i].position = targetPositions [i].position;
			bounds [i].radius = 1;
		}
		cullingGroup.SetBoundingSpheres (bounds);
		cullingGroup.SetBoundingSphereCount (targetPositions.Length);
	}
Exemple #34
0
 void OnDestroy()
 {
     culling_group.Dispose();
     culling_group = null;
 }
Exemple #35
0
 void Awake()
 {
     agent_prefab.CreatePool( max_agents );
     character_prefab.CreatePool( character_pool_size );
     culling_group = new CullingGroup();
 }