Пример #1
0
    public Fluid(int width, int height, int depth, int cellSize, float force, float diffusion, float viscosity)
    {
        this.width = width;
        this.height = height;
        this.depth = depth;
        this.cellSize = cellSize;
        this.force = force;
        this.diffusion = diffusion;
        this.viscosity = viscosity;

        windManager = WindManager.instance;

        fullWidth = width + 2;
        fullHeight = height + 2;
        fullDepth = depth + 2;
        fullSliceSize = fullWidth * fullHeight;
        fullSize = fullSliceSize * fullDepth;
        max = Mathf.Max(width, height, depth);
        u = new float[fullSize];
        uPrev = new float[fullSize];
        v = new float[fullSize];
        vPrev = new float[fullSize];
        w = new float[fullSize];
        wPrev = new float[fullSize];
        d = new float[fullSize];
        dPrev = new float[fullSize];
        obstacles = new bool[fullSize];

        reset();
    }
Пример #2
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     wd      = Path.GetDirectoryName(def.graphicData.texPath);
     windMan = Map.windManager;
     LongEventHandler.ExecuteWhenFinished(GetGraphicArray);
 }
Пример #3
0
    private void OnDestroy()
    {
        if (GameManager.Instance)
        {
            GameManager.Instance.OnSpeedModified -= HandleSpeedModified;
        }

        m_instance = null;
    }
Пример #4
0
 void Awake()
 {
     if (s_instance == null) {
         s_instance = this;
     }
     else {
         Destroy(gameObject);
     }
 }
Пример #5
0
 void Awake()
 {
     if (s_instance == null) {
         s_instance = this;
     }
     else {
         Debug.LogWarning( "Deleting gameobject \"" + gameObject.name + "\" because it has a duplicate WindManager." );
         Destroy(gameObject);
     }
 }
Пример #6
0
    private void Start()
    {
        if (!_wind)
        {
            _wind = FindObjectOfType <WindManager>();
        }

        _renderer  = _system.GetComponent <ParticleSystemRenderer>();
        _particles = new ParticleSystem.Particle[_system.main.maxParticles];
    }
Пример #7
0
    void Start()
    {
        drawDebug = GameObject.FindObjectOfType<DrawDebug>();
        windManager = WindManager.instance;

        fluidWidth = windManager.width;
        fluidHeight = windManager.height;
        drawDebug.selectedWidthIndex = fluidWidth / 2;
        drawDebug.selectedHeightIndex = fluidHeight / 2;
    }
Пример #8
0
 public void Inject(WindManager wind, AbstractUnityClock fixedClock, FixedUnityCoroutineScheduler scheduler)
 {
     _scheduler = scheduler;
     for (int i = 0; i < Sections.Count; i++)
     {
         var section = Sections[i];
         section.Cell.Airfoil.WindManager = wind;
         section.Cell.Airfoil.FixedClock  = fixedClock;
     }
 }
Пример #9
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(this);
     }
 }
Пример #10
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
Пример #11
0
 void Awake()
 {
     if (s_instance == null)
     {
         s_instance = this;
     }
     else
     {
         Debug.LogWarning("Deleting gameobject \"" + gameObject.name + "\" because it has a duplicate WindManager.");
         Destroy(gameObject);
     }
 }
Пример #12
0
        private static float BaseWindSpeedAt2(WindManager __instance, int ticksAbs)
        {
            if (windNoise(__instance) == null)
            {
                int seed = Gen.HashCombineInt(map(__instance).Tile, 122049541) ^ Find.World.info.Seed;
                windNoise(__instance) = new Perlin(3.9999998989515007E-05, 2.0, 0.5, 4, seed, QualityMode.Medium);
                windNoise(__instance) = new ScaleBias(1.5, 0.5, windNoise(__instance));
                windNoise(__instance) = new Clamp(WindSpeedRange.min, WindSpeedRange.max, windNoise(__instance));
            }

            return((float)windNoise(__instance).GetValue(ticksAbs, 0.0, 0.0));
        }
Пример #13
0
 // Use this for initialization
 void Start()
 {
     gameObject.tag = "Player";
     windManager    = FindObjectOfType <WindManager>();
     if (!windManager)
     {
         Debug.Log("No WindManager Script Present");
     }
     rigidBody = GetComponent <Rigidbody>();
     ourMass   = rigidBody.mass;
     ourDrag   = rigidBody.drag;
 }
Пример #14
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        Change(new Vector3(0, 0, 1));
    }
Пример #15
0
    GameObject stonehenge;     // To tell what y-level wind should be applied to

    // Start is called before the first frame update
    void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(this);
        }

        StartCoroutine(SetMagnitude());
    }
Пример #16
0
    // Use this for initialization
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            //DontDestroyOnLoad(gameObject);
        }

        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }
Пример #17
0
    // Start is called before the first frame update
    void Start()
    {
        var baloon = GameObject.FindGameObjectWithTag("Baloon");
        var cart   = GameObject.FindGameObjectWithTag("Cart");

        balloonRigidBody = baloon.GetComponentInChildren <Rigidbody>();

        BaloonWeight = baloon.GetComponentInChildren <Rigidbody>().mass;
        CartWeight   = cart.GetComponentInChildren <Rigidbody>().mass;

        WindManager = GameObject.FindGameObjectWithTag("WindManager").GetComponent <WindManager>();
        var tst = GameObject.FindGameObjectWithTag("WindManager");
    }
Пример #18
0
    void Start()
    {
        windManager = GameObject.FindObjectOfType<WindManager>();
        drawDebug = GameObject.FindObjectOfType<DrawDebug>();
        cameraOrigin = GameObject.Find("CameraOrigin").transform;

        cellSize = windManager.cellSize;
        fluidWidth = windManager.width;
        fluidHeight = windManager.height;
        fluidDepth = windManager.depth;
        drawDebug.selectedWidthIndex = windManager.width / 2;
        drawDebug.selectedHeightIndex = windManager.height / 2;
        drawDebug.selectedDepthIndex = windManager.depth / 2;
    }
Пример #19
0
        public static Material MatFrom(TriColorMaterialRequest req)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a material from a different thread.", false);
                return(null);
            }
            if (req.mainTex == null)
            {
                Log.Error("MatFrom with null sourceTex.", false);
                return(BaseContent.BadMat);
            }
            if (req.shader == null)
            {
                Log.Warning("Matfrom with null shader.", false);
                return(BaseContent.BadMat);
            }
            Material material;

            if (!TriColorMaterialPool.matDictionary.TryGetValue(req, out material))
            {
                material             = new Material(req.shader);
                material.name        = req.shader.name + "_" + req.mainTex.name;
                material.mainTexture = req.mainTex;
                material.color       = req.color;
                material.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
                material.SetColor(ShaderPropertyIDs.ColorTwo, req.colorTwo);
                material.SetColor(TriColorShaderDatabase.ColorThree, req.colorThree);
                material.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
                if (req.renderQueue != 0)
                {
                    material.renderQueue = req.renderQueue;
                }
                if (!req.shaderParameters.NullOrEmpty <ShaderParameter>())
                {
                    for (int i = 0; i < req.shaderParameters.Count; i++)
                    {
                        req.shaderParameters[i].Apply(material);
                    }
                }
                TriColorMaterialPool.matDictionary.Add(req, material);
                if (req.shader == ShaderDatabase.CutoutPlant || req.shader == ShaderDatabase.TransparentPlant)
                {
                    WindManager.Notify_PlantMaterialCreated(material);
                }
            }
            return(material);
        }
Пример #20
0
        public World(WorldSettings settings)
        {
            this.settings = settings;
            // Size.x = 9.1 because it will be improperly aligned otherwise
            // This is because the Hex Sprites are not even hexagon on all sides and need to be stretched
            layout = new Layout(Layout.pointy, new Point(9.235, 8.0), new Point(0, 0));

            numOfHexes  = settings.width * settings.height;
            pixelW      = (int)(settings.width * (Mathf.Sqrt(3) * layout.size.x));
            pixelH      = (int)(settings.height * (2 * layout.size.y) * 3 / 4);
            size        = new Vector2Int(settings.width, settings.height);
            m_tileData  = HexTileObjectDictionary.New <HexTileObjectDictionary>();
            plates      = new List <Plate>(settings.plates + 1);
            worldTemp   = new WorldTemp(WorldTemp.EARTH_TEMP, GameManager.Singleton.Generator);
            windManager = new WindManager(WindManager.PROGRADE_SPIN, WindManager.CellLayout.EARTH, this);
        }
Пример #21
0
 void Start()
 {
     grassMaterial = GetComponent <Renderer>().sharedMaterials[grassIsFirstMaterial ? 0 : 1]; // *ASSUMES GRASS IS THE SECOND MATERIAL IF grassIsFirstMaterial IS FALSE
     if (findWindManagerInScene)
     {
         var windManagerGameObject = GameObject.FindGameObjectWithTag("WindManager");
         if (windManagerGameObject != null)
         {
             windManager = windManagerGameObject.GetComponent <WindManager>();
         }
     }
     else
     {
         windManager = windManagerObject.GetComponent <WindManager>();
     }
 }
Пример #22
0
        /// <summary>
        /// Downloads the wind and updates the wind tables.
        /// If failed, errors are logged and displayed.
        /// </summary>
        /// <returns></returns>
        public async Task DownloadWind()
        {
            view.ShowWindStatus(WindDownloadStatus.Downloading);

            try
            {
                windTableLocator.Instance = await WindManager.LoadWindAsync();

                view.ShowWindStatus(WindDownloadStatus.FinishedDownload);
                WindAvailable = true;
            }
            catch (Exception ex)
            {
                Log(ex);
                view.ShowWindStatus(WindDownloadStatus.FailedToDownload);
            }
        }
Пример #23
0
        public async Task DownloadWind()
        {
            downloadBtn.Enabled = false;
            loadFileBtn.Enabled = false;
            ShowWindStatus(WindDownloadStatus.Downloading);

            try
            {
                windTableLocator.Instance = await WindManager.LoadWindAsync();

                ShowWindStatus(WindDownloadStatus.FinishedDownload);
                windAvailable = true;
            }
            catch (Exception ex)
            {
                Log(ex);
                ShowWindStatus(WindDownloadStatus.FailedToDownload);
            }

            downloadBtn.Enabled = true;
            loadFileBtn.Enabled = true;
        }
Пример #24
0
        public static bool WindManagerTick(WindManager __instance)
        {
            __instance.cachedWindSpeed = __instance.BaseWindSpeedAt(Find.TickManager.TicksAbs) * __instance.map.weatherManager.CurWindSpeedFactor;
            float curWindSpeedOffset = __instance.map.weatherManager.CurWindSpeedOffset;

            if (curWindSpeedOffset > 0f)
            {
                FloatRange floatRange = WindManager.WindSpeedRange * __instance.map.weatherManager.CurWindSpeedFactor;
                float      num        = (__instance.cachedWindSpeed - floatRange.min) / (floatRange.max - floatRange.min) * (floatRange.max - curWindSpeedOffset);
                __instance.cachedWindSpeed = curWindSpeedOffset + num;
            }

            List <Thing> list = __instance.map.listerThings.ThingsInGroup(ThingRequestGroup.WindSource);

            for (int i = 0; i < list.Count; i++)
            {
                CompWindSource compWindSource = list[i].TryGetComp <CompWindSource>();
                __instance.cachedWindSpeed = Mathf.Max(__instance.cachedWindSpeed, compWindSource.wind);
            }

            if (Prefs.PlantWindSway)
            {
                __instance.plantSwayHead += Mathf.Min(__instance.WindSpeed, 1f);
            }
            else
            {
                __instance.plantSwayHead = 0f;
            }

            if (Find.CurrentMap != __instance.map)
            {
                return(false);
            }
            plantSwayHead       = __instance.plantSwayHead;
            plantMaterialsCount = WindManager.plantMaterials.Count;
            return(false);
        }
Пример #25
0
        public static bool WindManagerTick(WindManager __instance)
        {
            cachedWindSpeed(__instance) = BaseWindSpeedAt2(__instance, Find.TickManager.TicksAbs) * map(__instance).weatherManager.CurWindSpeedFactor;
            float curWindSpeedOffset = map(__instance).weatherManager.CurWindSpeedOffset;

            if (curWindSpeedOffset > 0f)
            {
                FloatRange floatRange = WindSpeedRange * map(__instance).weatherManager.CurWindSpeedFactor;
                float      num        = (cachedWindSpeed(__instance) - floatRange.min) / (floatRange.max - floatRange.min) * (floatRange.max - curWindSpeedOffset);
                cachedWindSpeed(__instance) = curWindSpeedOffset + num;
            }

            List <Thing> list = map(__instance).listerThings.ThingsInGroup(ThingRequestGroup.WindSource);

            for (int i = 0; i < list.Count; i++)
            {
                CompWindSource compWindSource = list[i].TryGetComp <CompWindSource>();
                cachedWindSpeed(__instance) = Mathf.Max(cachedWindSpeed(__instance), compWindSource.wind);
            }

            if (Prefs.PlantWindSway)
            {
                plantSwayHead(__instance) += Mathf.Min(__instance.WindSpeed, 1f);
            }
            else
            {
                plantSwayHead(__instance) = 0f;
            }

            if (Find.CurrentMap == map(__instance))
            {
                RimThreaded.plantSwayHead       = plantSwayHead(__instance);
                RimThreaded.plantMaterialsCount = plantMaterials.Count;
            }
            return(false);
        }
Пример #26
0
 void Start()
 {
     windManager = WindManager.instance;
     cellSize = windManager.cellSize;
     fluidWidth = windManager.width;
     fluidHeight = windManager.height;
 }
Пример #27
0
 // Start is called before the first frame update
 void Start()
 {
     windManager = windManagerObject.GetComponent <WindManager>();
 }
Пример #28
0
    void Start()
    {
        windManager = GameObject.FindObjectOfType<WindManager>();
        cameraOrigin = GameObject.Find("CameraOrigin").transform;
        cellSize = windManager.cellSize;
        fluidWidth = windManager.width;
        fluidHeight = windManager.height;
        fluidDepth = windManager.depth;

        cameraOrigin.position = new Vector3(fluidWidth * cellSize / 2, fluidHeight * cellSize / 2, fluidDepth * cellSize / 2);
    }
Пример #29
0
        public void Init()
        {
            var timeNow = DateTime.Now;

            Debug.Log("##### Start preparing simulation #####");

            if (Settings == null)
            {
                Settings = new SimulationSettings();
            }
            if (EditorSettings == null)
            {
                EditorSettings = new EditorSettings();
            }
            if (CollisionCamera == null)
            {
                CollisionCamera = GameObject.FindWithTag("GrassSimulationCollisionCamera").GetComponent <Camera>();
            }
            if (BillboardTextureCamera == null)
            {
                BillboardTextureCamera = GameObject.FindWithTag("BillboardTextureCamera").GetComponent <Camera>();
            }
            BillboardTexturePatchContainer = null;
            BillboardTexturePatchContainer = CreateInstance <BillboardTexturePatchContainer>();

            if (BladeContainer == null)
            {
                BladeContainer = CreateInstance <BladeContainer>();
            }
            BladeContainer.Init(this);
            BlossomCount = BladeContainer.GetBlossomCount();
            var timeTextureArrays = DateTime.Now;

            BladeTexture2DArray0   = BladeContainer.GetGeoemetryTexture2DArray(0);
            BladeTexture2DArray1   = BladeContainer.GetGeoemetryTexture2DArray(2);
            BlossomTexture2DArray0 = BladeContainer.GetGeoemetryTexture2DArray(1);
            BlossomTexture2DArray1 = BladeContainer.GetGeoemetryTexture2DArray(3);
            Debug.Log("\t Created Texture Arrays for LookUp- and Surface-Textures for " + BladeContainer.Blades.Length + " Blades and " + BlossomCount + " Blossoms in " + (int)(DateTime.Now - timeTextureArrays).TotalMilliseconds + "ms");
            if (!Transform || !Camera || !CollisionCamera || !BillboardTextureCamera || !GrassSimulationComputeShader || !CollisionDepthShader || !GrassSimulationShader || !DimensionsInput || !GrassMapInput || !HeightInput || !NormalInput || !PositionInput || !PatchContainer || BladeTexture2DArray0 == null || BladeTexture2DArray1 == null)
            {
                Debug.LogWarning("GrassSimulation: Not all dependencies are set.");
                if (!Transform)
                {
                    Debug.Log("GrassSimulation: Transform not set.");
                }
                if (!Camera)
                {
                    Debug.Log("GrassSimulation: Camera not set.");
                }
                if (!CollisionCamera)
                {
                    Debug.Log("GrassSimulation: Could not find Camera on GameObject with Tag GrassSimulationCollisionCamera");
                }
                if (!BillboardTextureCamera)
                {
                    Debug.Log("GrassSimulation: Could not find Camera on GameObject with Tag BillboardTextureCamera");
                }
                if (!GrassSimulationComputeShader)
                {
                    Debug.Log("GrassSimulation: GrassSimulationComputeShader not set.");
                }
                if (!CollisionDepthShader)
                {
                    Debug.Log("GrassSimulation: CollisionDepthShader not set.");
                }
                if (!GrassSimulationShader)
                {
                    Debug.Log("GrassSimulation: GrassSimulationShader not set.");
                }
                if (!DimensionsInput)
                {
                    Debug.Log("GrassSimulation: DimensionsInput not set.");
                }
                if (!GrassMapInput)
                {
                    Debug.Log("GrassSimulation: GrassMapInput not set.");
                }
                if (!HeightInput)
                {
                    Debug.Log("GrassSimulation: HeightInput not set.");
                }
                if (!NormalInput)
                {
                    Debug.Log("GrassSimulation: NormalInput not set.");
                }
                if (!PositionInput)
                {
                    Debug.Log("GrassSimulation: PositionInput not set.");
                }
                if (!PatchContainer)
                {
                    Debug.Log("GrassSimulation: PatchContainer not set.");
                }
                if (BladeTexture2DArray0 == null || BladeTexture2DArray1 == null)
                {
                    Debug.Log("GrassSimulation: No Grass Blades set. Cannot create Textures.");
                }
                IsReady = false;
                return;
            }

            //Create a single random object
            Random = new Random(Settings.RandomSeed);

            //Find kernels for ComputeShaders
            KernelPhysics         = GrassSimulationComputeShader.FindKernel("PhysicsMain");
            KernelSimulationSetup = GrassSimulationComputeShader.FindKernel("SimulationSetup");

            //Create Material Variants

            GrassGeometry            = new Material(GrassSimulationShader);
            GrassBillboardGeneration = new Material(GrassGeometry);
            GrassBillboardCrossed    = new Material(GrassGeometry);
            GrassBillboardScreen     = new Material(GrassGeometry);


            //if (BlossomCount > 0)
            //{
            GrassBlossom = new Material(GrassGeometry);
            GrassBlossomBillboardGeneration = new Material(GrassGeometry);
            GrassBlossom.EnableKeyword("GRASS_BLOSSOM");
            GrassBlossom.DisableKeyword("GRASS_GEOMETRY");
            GrassBlossom.DisableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassBlossom.DisableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassBlossom.SetTexture("GrassBlossom0", BlossomTexture2DArray0);
            GrassBlossom.SetTexture("GrassBlossom1", BlossomTexture2DArray1);
            GrassBlossom.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassBlossom.SetInt("VertexCount", (int)Settings.GetMinAmountBladesPerPatch());
            GrassBlossom.SetInt("BlossomCount", BlossomCount);
            GrassBlossom.SetFloat("BladeTextureMaxMipmapLevel", Settings.BladeTextureMaxMipmapLevel);
            GrassBlossom.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassBlossom.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBlossom.SetFloat("LodInstancesGeometry",
                                  Settings.LodInstancesGeometry / (float)Settings.LodGeometryTransitionSegments);
            GrassBlossom.SetFloat("LodGeometryTransitionSegments", Settings.LodGeometryTransitionSegments);
            GrassBlossom.SetFloat("LodDistanceGeometryStart", Settings.LodDistanceGeometryStart);
            GrassBlossom.SetFloat("LodDistanceGeometryEnd", Settings.LodDistanceGeometryEnd);
            GrassBlossom.SetFloat("LodTessellationMin", Settings.LodTessellationMin);
            GrassBlossom.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBlossom.SetFloat("LodDistanceTessellationMin", Settings.LodDistanceTessellationMin);
            GrassBlossom.SetFloat("LodDistanceTessellationMax", Settings.LodDistanceTessellationMax);

            GrassBlossomBillboardGeneration.EnableKeyword("BILLBOARD_GENERATION");
            GrassBlossomBillboardGeneration.EnableKeyword("GRASS_BLOSSOM");
            GrassBlossomBillboardGeneration.DisableKeyword("GRASS_GEOMETRY");
            GrassBlossomBillboardGeneration.DisableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassBlossomBillboardGeneration.DisableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassBlossomBillboardGeneration.SetTexture("GrassBlossom0", BlossomTexture2DArray0);
            GrassBlossomBillboardGeneration.SetTexture("GrassBlossom1", BlossomTexture2DArray1);
            GrassBlossomBillboardGeneration.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassBlossomBillboardGeneration.SetInt("VertexCount", (int)Settings.BillboardGrassCount);
            GrassBlossomBillboardGeneration.SetInt("BlossomCount", BlossomCount);
            GrassBlossomBillboardGeneration.SetFloat("BladeTextureMaxMipmapLevel", Settings.BladeTextureMaxMipmapLevel);
            GrassBlossomBillboardGeneration.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassBlossomBillboardGeneration.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBlossomBillboardGeneration.SetFloat("LodInstancesGeometry",
                                                     Settings.LodInstancesGeometry / (float)Settings.LodGeometryTransitionSegments);
            GrassBlossomBillboardGeneration.SetFloat("LodGeometryTransitionSegments", Settings.LodGeometryTransitionSegments);
            //GrassBlossomBillboardGeneration.SetFloat("LodDistanceGeometryStart", 0);
            GrassBlossomBillboardGeneration.SetFloat("LodDistanceGeometryStart", 1);
            GrassBlossomBillboardGeneration.SetFloat("LodDistanceGeometryEnd", 100);
            GrassBlossomBillboardGeneration.SetFloat("LodTessellationMin", Settings.LodTessellationMin);
            GrassBlossomBillboardGeneration.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBlossomBillboardGeneration.SetFloat("LodDistanceTessellationMin", Settings.LodDistanceTessellationMin);
            GrassBlossomBillboardGeneration.SetFloat("LodDistanceTessellationMax", Settings.LodDistanceTessellationMax);

            /*} else
             * {
             *      GrassBlossom = null;
             *      GrassBlossomBillboardGeneration = null;
             * }*/

            GrassGeometry.EnableKeyword("GRASS_GEOMETRY");
            GrassGeometry.DisableKeyword("GRASS_BLOSSOM");
            GrassGeometry.DisableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassGeometry.DisableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassGeometry.SetTexture("GrassBlades0", BladeTexture2DArray0);
            GrassGeometry.SetTexture("GrassBlades1", BladeTexture2DArray1);
            GrassGeometry.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassGeometry.SetInt("VertexCount", (int)Settings.GetMinAmountBladesPerPatch());
            GrassGeometry.SetFloat("BladeTextureMaxMipmapLevel", Settings.BladeTextureMaxMipmapLevel);
            GrassGeometry.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassGeometry.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassGeometry.SetFloat("LodInstancesGeometry", Settings.LodInstancesGeometry / (float)Settings.LodGeometryTransitionSegments);
            GrassGeometry.SetFloat("LodGeometryTransitionSegments", Settings.LodGeometryTransitionSegments);
            GrassGeometry.SetFloat("LodDistanceGeometryStart", Settings.LodDistanceGeometryStart);
            GrassGeometry.SetFloat("LodDistanceGeometryEnd", Settings.LodDistanceGeometryEnd);
            GrassGeometry.SetFloat("LodTessellationMin", Settings.LodTessellationMin);
            GrassGeometry.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassGeometry.SetFloat("LodDistanceTessellationMin", Settings.LodDistanceTessellationMin);
            GrassGeometry.SetFloat("LodDistanceTessellationMax", Settings.LodDistanceTessellationMax);

            GrassBillboardGeneration.EnableKeyword("BILLBOARD_GENERATION");
            GrassBillboardGeneration.EnableKeyword("GRASS_GEOMETRY");
            GrassBillboardGeneration.DisableKeyword("GRASS_BLOSSOM");
            GrassBillboardGeneration.DisableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassBillboardGeneration.DisableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassBillboardGeneration.SetTexture("GrassBlades0", BladeTexture2DArray0);
            GrassBillboardGeneration.SetTexture("GrassBlades1", BladeTexture2DArray1);
            GrassBillboardGeneration.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassBillboardGeneration.SetInt("VertexCount", (int)Settings.BillboardGrassCount);
            GrassBillboardGeneration.SetFloat("BladeTextureMaxMipmapLevel", Settings.BladeTextureMaxMipmapLevel);
            GrassBillboardGeneration.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassBillboardGeneration.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBillboardGeneration.SetFloat("LodInstancesGeometry", Settings.LodInstancesGeometry / (float)Settings.LodGeometryTransitionSegments);
            GrassBillboardGeneration.SetFloat("LodGeometryTransitionSegments", Settings.LodGeometryTransitionSegments);
            //GrassBillboardGeneration.SetFloat("LodDistanceGeometryStart", 0);
            GrassBillboardGeneration.SetFloat("LodDistanceGeometryStart", 1);
            GrassBillboardGeneration.SetFloat("LodDistanceGeometryEnd", 100);
            GrassBillboardGeneration.SetFloat("LodTessellationMin", Settings.LodTessellationMin);
            GrassBillboardGeneration.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassBillboardGeneration.SetFloat("LodDistanceTessellationMin", Settings.LodDistanceTessellationMin);
            GrassBillboardGeneration.SetFloat("LodDistanceTessellationMax", Settings.LodDistanceTessellationMax);

            GrassBillboardCrossed.SetOverrideTag("Queue", "AlphaTest");
            GrassBillboardCrossed.SetOverrideTag("RenderType", "TransparentCutout");
            GrassBillboardCrossed.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            GrassBillboardCrossed.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            //GrassBillboardCrossed.SetInt("_ZWrite", 0);
            GrassBillboardCrossed.SetInt("_AlphaToMask", 1);
            GrassBillboardCrossed.renderQueue = 3000;
            GrassBillboardCrossed.DisableKeyword("GRASS_GEOMETRY");
            GrassBillboardCrossed.DisableKeyword("GRASS_BLOSSOM");
            GrassBillboardCrossed.EnableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassBillboardCrossed.DisableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassBillboardCrossed.SetTexture("GrassBlades0", BladeTexture2DArray0);
            GrassBillboardCrossed.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassBillboardCrossed.SetInt("VertexCount", (int)Settings.GetMinAmountBillboardsPerPatch());
            GrassBillboardCrossed.SetFloat("BillboardAlphaCutoff", Settings.BillboardAlphaCutoff);
            GrassBillboardCrossed.SetFloat("BillboardHeightAdjustment", Settings.BillboardHeightAdjustment);
            GrassBillboardCrossed.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassBillboardCrossed.SetFloat("LodInstancesBillboardCrossed", Settings.LodInstancesBillboardCrossed / (float)Settings.LodBillboardCrossedTransitionSegments);
            GrassBillboardCrossed.SetFloat("LodBillboardCrossedTransitionSegments", Settings.LodBillboardCrossedTransitionSegments);
            GrassBillboardCrossed.SetFloat("LodDistanceBillboardCrossedStart", Settings.LodDistanceBillboardCrossedStart);
            GrassBillboardCrossed.SetFloat("LodDistanceBillboardCrossedPeak", Settings.LodDistanceBillboardCrossedPeak);
            GrassBillboardCrossed.SetFloat("LodDistanceBillboardCrossedEnd", Settings.LodDistanceBillboardCrossedEnd);

            GrassBillboardScreen.SetOverrideTag("Queue", "AlphaTest");
            GrassBillboardScreen.SetOverrideTag("RenderType", "TransparentCutout");
            GrassBillboardScreen.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            GrassBillboardScreen.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            //GrassBillboardScreen.SetInt("_ZWrite", 0);
            GrassBillboardScreen.SetInt("_AlphaToMask", 1);
            GrassBillboardScreen.renderQueue = 2900;
            GrassBillboardScreen.DisableKeyword("GRASS_GEOMETRY");
            GrassBillboardScreen.DisableKeyword("GRASS_BLOSSOM");
            GrassBillboardScreen.DisableKeyword("GRASS_BILLBOARD_CROSSED");
            GrassBillboardScreen.EnableKeyword("GRASS_BILLBOARD_SCREEN");
            GrassBillboardScreen.SetTexture("GrassBlades0", BladeTexture2DArray0);
            GrassBillboardScreen.SetInt("EnableHeightTransition", Settings.EnableHeightTransition ? 1 : 0);
            GrassBillboardScreen.SetInt("VertexCount", (int)Settings.GetMinAmountBillboardsPerPatch());
            GrassBillboardScreen.SetFloat("BillboardAlphaCutoff", Settings.BillboardAlphaCutoff);
            GrassBillboardScreen.SetFloat("BillboardHeightAdjustment", Settings.BillboardHeightAdjustment);
            GrassBillboardScreen.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassBillboardScreen.SetFloat("LodInstancesBillboardScreen", Settings.LodInstancesBillboardScreen / (float)Settings.LodBillboardScreenTransitionSegments);
            GrassBillboardScreen.SetFloat("LodBillboardScreenTransitionSegments", Settings.LodBillboardScreenTransitionSegments);
            GrassBillboardScreen.SetFloat("LodDistanceBillboardScreenStart", Settings.LodDistanceBillboardScreenStart);
            GrassBillboardScreen.SetFloat("LodDistanceBillboardScreenPeak", Settings.LodDistanceBillboardScreenPeak);
            GrassBillboardScreen.SetFloat("LodDistanceBillboardScreenEnd", Settings.LodDistanceBillboardScreenEnd);

            GrassSimulationComputeShader.SetInt("WindLayerCount", Settings.WindLayerCount);
            GrassSimulationComputeShader.SetFloat("GrassDataResolution", Settings.GrassDataResolution);
            GrassSimulationComputeShader.SetFloat("BladeHeightCullingThreshold", Settings.BladeHeightCullingThreshold);
            GrassSimulationComputeShader.SetFloat("RecoveryFactor", Settings.RecoveryFactor);
            GrassSimulationComputeShader.SetFloat("LodTessellationMin", Settings.LodTessellationMin);
            GrassSimulationComputeShader.SetFloat("LodTessellationMax", Settings.LodTessellationMax);
            GrassSimulationComputeShader.SetFloat("LodDistanceTessellationMin", Settings.LodDistanceTessellationMin);
            GrassSimulationComputeShader.SetFloat("LodDistanceTessellationMax", Settings.LodDistanceTessellationMax);

            //If possible initialize the Data Providers
            // ReSharper disable SuspiciousTypeConversion.Global
            if (DimensionsInput is IInitializableWithCtx)
            {
                ((IInitializableWithCtx)DimensionsInput).Init(this);
            }
            else if (DimensionsInput is IInitializable)
            {
                ((IInitializable)DimensionsInput).Init();
            }

            if (GrassMapInput is IInitializableWithCtx)
            {
                ((IInitializableWithCtx)GrassMapInput).Init(this);
            }
            else if (GrassMapInput is IInitializable)
            {
                ((IInitializable)GrassMapInput).Init();
            }

            if (HeightInput is IInitializableWithCtx)
            {
                ((IInitializableWithCtx)HeightInput).Init(this);
            }
            else if (HeightInput is IInitializable)
            {
                ((IInitializable)HeightInput).Init();
            }

            if (NormalInput is IInitializableWithCtx)
            {
                ((IInitializableWithCtx)NormalInput).Init(this);
            }
            else if (NormalInput is IInitializable)
            {
                ((IInitializable)NormalInput).Init();
            }

            if (PositionInput is IInitializableWithCtx)
            {
                ((IInitializableWithCtx)PositionInput).Init(this);
            }
            else if (PositionInput is IInitializable)
            {
                ((IInitializable)PositionInput).Init();
            }


            GrassInstance = new GrassInstance(this);

            var timePatchConstruction = DateTime.Now;

            PatchContainer.Init(this);
            PatchContainer.SetupContainer();
            Debug.Log("\t Created and initialized " + (Settings.PatchSize * Settings.PatchSize) + " patches and hierarchy in " + (int)(DateTime.Now - timePatchConstruction).TotalMilliseconds + "ms");

            CollisionTextureRenderer = new CollisionTextureRenderer(this, PatchContainer.GetBounds());
            if (WindManager == null)
            {
                WindManager = new WindManager(this);
            }
            else
            {
                WindManager.InitBuffer();
            }
            WindManager.Update();
            //ProceduralWind = new ProceduralWind(this);
            //ProceduralWind.Update();

            var timeBillboardTextures = DateTime.Now;

            //Create Billboard Textures
            BillboardTexturePatchContainer.Init(this);
            BillboardTexturePatchContainer.SetupContainer();
            BillboardTexturePatchContainer.Draw();

            Debug.Log("\t Rendered Billboard Textures in " + (int)(DateTime.Now - timeBillboardTextures).TotalMilliseconds + "ms");

            //Needs to be reset here, since BillboardTexturePatchContainer sets its own NormalHeightTexture
            GrassSimulationComputeShader.SetTexture(KernelPhysics, "NormalHeightTexture", GrassInstance.NormalHeightTexture);
            GrassSimulationComputeShader.SetTexture(KernelSimulationSetup, "NormalHeightTexture", GrassInstance.NormalHeightTexture);

            GrassBillboardCrossed.SetTexture("GrassBillboards", BillboardTexturePatchContainer.BillboardTextures);
            GrassBillboardCrossed.SetTexture("GrassBillboardNormals", BillboardTexturePatchContainer.BillboardNormals);
            GrassBillboardCrossed.SetFloat("BillboardAspect", BillboardTexturePatchContainer.BillboardAspect);
            GrassBillboardCrossed.SetInt("RepetitionCount", (int)PositionInput.GetRepetitionCount());
            GrassBillboardScreen.SetTexture("GrassBillboards", BillboardTexturePatchContainer.BillboardTextures);
            GrassBillboardScreen.SetTexture("GrassBillboardNormals", BillboardTexturePatchContainer.BillboardNormals);
            GrassBillboardScreen.SetFloat("BillboardAspect", BillboardTexturePatchContainer.BillboardAspect);
            GrassBillboardScreen.SetInt("RepetitionCount", (int)PositionInput.GetRepetitionCount());

            Debug.Log("\t Finished Simulation Preperation in " + (int)(DateTime.Now - timeNow).TotalMilliseconds + "ms");

            Settings.LogSettings();

            //Everything is ready.
            IsReady = true;
        }
Пример #30
0
        // Token: 0x06001CE6 RID: 7398 RVA: 0x000F20B4 File Offset: 0x000F02B4
        public static Material MatFrom(AvaliMaterialRequest req)
        {
            //Log.Message("thisine");
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a material from a different thread.", false);
                return(null);
            }
            if (req.mainTex == null)
            {
                Log.Error("MatFrom with null sourceTex.", false);
                return(AvaliBaseContent.BadMat);
            }
            if (req.shader == null)
            {
                Log.Warning("Matfrom with null shader.", false);
                return(AvaliBaseContent.BadMat);
            }

            /*
             * if (req.maskTex != null && !req.shader.SupportsMaskTex())
             * {
             *      Log.Error("MaterialRequest has maskTex but shader does not support it. req=" + req.ToString(), false);
             *      req.maskTex = null;
             * }
             */
#pragma warning disable CS1717 // Assignment made to same variable
            req.color      = req.color;
            req.colorTwo   = req.colorTwo;
            req.colorThree = req.colorThree;
#pragma warning restore CS1717
            Material material;
            if (!AvaliMaterialPool.matDictionary.TryGetValue(req, out material))
            {
                material             = AvaliMaterialAllocator.Create(req.shader);
                material.name        = req.shader.name + "_" + req.mainTex.name;
                material.mainTexture = req.mainTex;
                material.color       = req.color;
                material.SetTexture(AvaliShaderPropertyIDs.MaskTex, req.maskTex);
                material.SetColor(AvaliShaderPropertyIDs.ColorTwo, req.colorTwo);
                material.SetColor(AvaliShaderPropertyIDs.ColorThree, req.colorThree);
                // liQd Comment there it is
                material.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
                //Log.Message("thisthinghascolor3: " + req.colorThree);
                if (req.renderQueue != 0)
                {
                    material.renderQueue = req.renderQueue;
                }
                if (!req.shaderParameters.NullOrEmpty <ShaderParameter>())
                {
                    for (int i = 0; i < req.shaderParameters.Count; i++)
                    {
                        req.shaderParameters[i].Apply(material);
                    }
                }
                AvaliMaterialPool.matDictionary.Add(req, material);
                if (req.shader == ShaderDatabase.CutoutPlant || req.shader == ShaderDatabase.TransparentPlant)
                {
                    WindManager.Notify_PlantMaterialCreated(material);
                }
            }
            return(material);
        }
Пример #31
0
 // Start is called before the first frame update
 void Start()
 {
     boatRB            = GetComponent <Rigidbody>();
     windManagerScript = windManager.GetComponent <WindManager>();
 }
Пример #32
0
 // Start is called before the first frame update
 void Start()
 {
     windManagerScript = windManager.GetComponent <WindManager>();
 }
Пример #33
0
	//Constructor
	public WindParticle(WindManager.particleData setData) {
		data = setData;
	}
Пример #34
0
 void Awake()
 {
     balls         = new List <Rigidbody2D>();
     instance      = this;
     windAnimation = GetComponentInChildren <WindAnimation>();
 }
Пример #35
0
 private void Awake()
 {
     _wind = FindObjectOfType <WindManager>();
 }