Exemple #1
0
        public static GHydraulicErosionParams Create()
        {
            GHydraulicErosionParams param = new GHydraulicErosionParams();

            param.Iteration      = 10;
            param.Rain           = 0.5f;
            param.Transportation = 0.1f;
            param.AngleMin       = 5;
            param.Evaporation    = 0.1f;
            param.Dimension      = Vector3.one;

            return(param);
        }
Exemple #2
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GHydraulicErosionParams erosionParam = param.HydraulicErosion;
            RenderTexture           writeRt      = null; //buffer to write to
            RenderTexture           readRt       = null; //buffer to read from
            RenderTexture           tmp          = null; //temp buffer for swapping

            CloneBg(targetRt, out writeRt, out readRt);

            //init height field & water level
            Mat.SetTexture("_HeightMap", targetRt);
            GCommon.DrawQuad(writeRt, GCommon.FullRectUvPoints, Mat, 0);
            GCommon.DrawQuad(readRt, GCommon.FullRectUvPoints, Mat, 0);

            //simulate
            for (int i = 0; i < erosionParam.Iteration; ++i)
            {
                Mat.SetTexture("_HeightMap", readRt);
                Mat.SetVector("_Dimension", erosionParam.Dimension);
                Mat.SetFloat("_Rain", erosionParam.Rain);
                Mat.SetFloat("_Transportation", erosionParam.Transportation);
                Mat.SetFloat("_MinAngle", erosionParam.AngleMin);
                Mat.SetFloat("_Evaporation", erosionParam.Evaporation);
                Mat.SetTexture("_WaterSourceMap", erosionParam.WaterSourceMap);
                Mat.SetTexture("_HardnessMap", erosionParam.HardnessMap);
                //Mat.SetFloat("_Seed", Random.value);
                GCommon.DrawQuad(writeRt, GCommon.FullRectUvPoints, Mat, 1);

                //swap buffer
                tmp     = readRt;
                readRt  = writeRt;
                writeRt = tmp;
            }

            //copy result
            GCommon.CopyToRT(writeRt, targetRt);
        }