Esempio n. 1
0
        private void Start()
        {
            UnityEngine.Random.InitState(DateTime.Now.Second); //todo to provider

            GpuInstancingGrassInstanceContainer gpuInstancingGrassContainer = new GpuInstancingGrassInstanceContainer();
            GameObjectGrassInstanceContainer    gameObjectContainer         = new GameObjectGrassInstanceContainer();

            _rootInstanceContainer  = new RootInstanceContainer(gameObjectContainer, gpuInstancingGrassContainer);
            _grassInstanceContainer = _rootInstanceContainer;
            Material grassMaterial = new Material(Shader.Find("Custom/Vegetation/Grass.Instanced"));

            var meshGenerator = new GrassMeshGenerator();

            var singleGrassMeshProvider          = new SingleGrassMeshProvider(meshGenerator);
            var singleGrassUpdater               = new SingleGrassEntitySplatUpdater(singleGrassMeshProvider);
            var grassTuftLodEntitySplatGenerator = new GenericEntitySplatGenerator((position) =>
                                                                                   new LodEntitySplat(position,
                                                                                                      new SingleGrassLodResolver(),
                                                                                                      new GpuInstancingEntitySplatGenerator(new GrassTuftGenerator(),
                                                                                                                                            new SingleGrassUniformPositionProvider(),
                                                                                                                                            new GrassTuftAbstractSettingGenerator(), grassMaterial,
                                                                                                                                            new ConstantCount(20), singleGrassMeshProvider, gpuInstancingGrassContainer,
                                                                                                                                            new GpuInstancingGrassInstanceGenerator()),
                                                                                                      singleGrassUpdater));

            var singleGrassLodEntitySplatGenerator = new GenericEntitySplatGenerator((position) =>
                                                                                     new LodEntitySplat(position,
                                                                                                        new SingleGrassLodResolver(),
                                                                                                        new GpuInstancingEntitySplatGenerator(new GrassSingleGenerator(),
                                                                                                                                              new SingleGrassUniformPositionProvider(),
                                                                                                                                              new GrassSingleAbstractSettingGenerator(), grassMaterial,
                                                                                                                                              new ConstantCount(20), singleGrassMeshProvider, gpuInstancingGrassContainer,
                                                                                                                                              new GpuInstancingGrassInstanceGenerator()),
                                                                                                        singleGrassUpdater));


            var lodGroupProvider =
                new LodGroupsProvider(new List <ILodEntitySplatGenerator>
            {
                singleGrassLodEntitySplatGenerator,
                grassTuftLodEntitySplatGenerator
            });

            var mapSize             = new Vector2(100, 100);
            var splatSize           = mapSize / 10;
            var singleLevelDistance = (int)splatSize.x * 2;
            var singleLevelMargin   = 0.1f;
            var lodMarginPowCoef    = 0.8f;

            _grassLodManager =
                new GrassLodManager(new LodLevelResolver(7, singleLevelDistance, singleLevelMargin, lodMarginPowCoef),
                                    new GrassLodManager.MultithreadLodGroupsActioner(lodGroupProvider), mapSize, splatSize);
            _grassLodManager.InitializeGroups(new Vector3(0, 0, 0));
            _grassLodManager.UpdateLod(new Vector3(0, 0, 0));
        }
        private void Start()
        {
            Random.InitState(DateTime.Now.Second);
            _rootInstanceContainer = new RootInstanceContainer();
            Material grassMaterial = new Material(Shader.Find("Custom/testSurfaceShader23.Instanced"));

            var meshGenerator = new GrassMeshGenerator();

            var grassTuftLodEntitySplatGenerator = new GrassTuftLodEntitySplatGenerator(
                new GrassTuftGenerator(),
                new SingleGrassUniformPositionProvider(),
                new GrassTuftAbstractSettingGenerator(),
                _rootInstanceContainer,
                meshGenerator,
                grassMaterial);

            var singleGrassLodEntitySplatGenerator = new SingleGrassLodEntitySplatGenerator(
                new GrassSingleGenerator(),
                new SingleGrassUniformPositionProvider(),
                new GrassSingleAbstractSettingGenerator(),
                _rootInstanceContainer,
                meshGenerator,
                grassMaterial);

            var lodGroupProvider = new LodGroupsProvider(new List <ILodEntitySplatGenerator> {
                singleGrassLodEntitySplatGenerator, grassTuftLodEntitySplatGenerator
            });

            var mapSize             = new Vector2(100, 100);
            var splatSize           = mapSize / 10;
            var singleLevelDistance = (int)splatSize.x * 2;
            var singleLevelMargin   = 0.1f;
            var lodMarginPowCoef    = 0.8f;

            _grassLodManager = new GrassLodManager(new LodLevelResolver(7, singleLevelDistance, singleLevelMargin, lodMarginPowCoef), lodGroupProvider, mapSize, splatSize);
            _grassLodManager.UpdateLod(new Vector3(0, 0, 0));
        }