public static bool Validate(PWater water)
        {
            bool validate         = true;
            bool validateBackFace = true;

            if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Builtin)
            {
                validate =
                    water.MaterialToRender.shader == WaterBasicShader ||
                    water.MaterialToRender.shader == WaterAdvancedShader ||
                    water.MaterialToRender.shader == RiverShader;
                validateBackFace =
                    water.ShouldRenderBackface && water.MaterialBackFace.shader == WaterBackFaceShader;
            }
            else if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Universal)
            {
                validate =
                    water.MaterialToRender.shader == WaterBasicShaderURP ||
                    water.MaterialToRender.shader == WaterAdvancedShaderURP ||
                    water.MaterialToRender.shader == RiverShaderURP;
                validateBackFace =
                    water.ShouldRenderBackface && water.MaterialBackFace.shader == WaterBackFaceShaderURP;
            }

            return(validate && validateBackFace);
        }
Example #2
0
 public void Create(PWater water)
 {
     this.water = water;
     Init();
     GenerateGrid();
     UpdateMesh();
 }
Example #3
0
        public static void WaterPivotToSplineCenter(PWater water)
        {
            PSpline spline = water.Spline;
            List <PSplineAnchor> anchors = spline.Anchors;

            if (anchors.Count == 0)
            {
                return;
            }

            Vector3 splineCenterLocal = Vector3.zero;

            for (int i = 0; i < anchors.Count; ++i)
            {
                splineCenterLocal += anchors[i].Position;
            }

            splineCenterLocal = splineCenterLocal / anchors.Count;
            for (int i = 0; i < anchors.Count; ++i)
            {
                anchors[i].Position -= splineCenterLocal;
            }

            List <PSplineSegment> segments = spline.Segments;

            for (int i = 0; i < segments.Count; ++i)
            {
                segments[i].StartTangent -= splineCenterLocal;
                segments[i].EndTangent   -= splineCenterLocal;
            }
            Vector3 splineCenterWorld = water.transform.TransformPoint(splineCenterLocal);

            water.transform.position = splineCenterWorld;
        }
        public void Create(PWater water)
        {
            List <PSplineSegment> segments = water.Spline.Segments;

            for (int i = 0; i < segments.Count; ++i)
            {
                Create(water, i);
            }
        }
Example #5
0
        public void Create(PWater water)
        {
            if (water.AreaMeshAnchors.Count < 3)
            {
                return;
            }

            this.water = water;
            CalculateBoundaries();
            GenerateMask();
            GenerateGrid();
            UpdateMesh();
        }
Example #6
0
        private void OnEnable()
        {
            water = target as PWater;
            if (water.Profile != null)
            {
                water.ReCalculateBounds();
            }

            tileEditingGUIDrawer   = new PTilesEditingGUIDrawer(water);
            areaEditingGUIDrawer   = new PAreaEditingGUIDrawer(water);
            splineEditingGUIDrawer = new PSplineEditingGUIDrawer(water);

            SceneView.duringSceneGui += DuringSceneGUI;
        }
 public static Shader GetShader(PWater water)
 {
     if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Builtin)
     {
         return(GetBuiltinRPShader(water));
     }
     else if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Universal)
     {
         return(GetUniversalRPShader(water));
     }
     else
     {
         return(null);
     }
 }
 public static Shader GetUniversalRPShader(PWater water)
 {
     if (water.Profile == null)
     {
         return(null);
     }
     if (water.MeshType == PWaterMeshType.Spline)
     {
         return(RiverShaderURP);
     }
     else
     {
         if (water.Profile.EnableReflection || water.Profile.EnableRefraction)
         {
             return(WaterAdvancedShaderURP);
         }
         else
         {
             return(WaterBasicShaderURP);
         }
     }
 }
Example #9
0
        public static PWater CreateCalmWaterHQObject(MenuCommand cmd)
        {
            GameObject g = new GameObject("Calm Water HQ");

            if (cmd != null && cmd.context != null)
            {
                GameObject root = cmd.context as GameObject;
                GameObjectUtility.SetParentAndAlign(g, root);
            }

            PWater        waterComponent = g.AddComponent <PWater>();
            PWaterProfile profile        = PWaterProfile.CreateInstance <PWaterProfile>();
            string        fileName       = "WaterProfile_" + PCommon.GetUniqueID();
            string        filePath       = string.Format("Assets/{0}.asset", fileName);

            AssetDatabase.CreateAsset(profile, filePath);

            profile.CopyFrom(PPoseidonSettings.Instance.CalmWaterHQProfile);
            waterComponent.Profile  = profile;
            waterComponent.TileSize = new Vector2(100, 100);

            return(waterComponent);
        }
Example #10
0
 public PTilesEditingGUIDrawer(PWater water)
 {
     this.water = water;
 }
Example #11
0
 public PSplineEditingGUIDrawer(PWater water)
 {
     this.water = water;
 }
Example #12
0
 public void Create(PWater profile)
 {
     this.water = profile;
     Init();
     Bake();
 }
        public void Create(PWater water, int segmentIndex)
        {
            this.water = water;

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector4> uvs0      = new List <Vector4>();
            List <Vector4> uvs1      = new List <Vector4>();
            List <Color>   colors    = new List <Color>();
            List <int>     triangles = new List <int>();

            PSpline        spline = water.Spline;
            PSplineSegment s      = water.Spline.Segments[segmentIndex];

            Vector3    pos0, pos1;
            Quaternion rotation0, rotation1;
            Vector3    scale0, scale1;
            Matrix4x4  matrix0, matrix1;

            Vector4 bl, tl, tr, br;
            Vector4 v0, v1, v2, v3;
            Vector4 flow0, flow1;
            int     currentVertexCount;

            float halfWidth = water.SplineWidth * 0.5f;
            int   resY      = Mathf.RoundToInt(water.SplineResolutionY * s.ResolutionMultiplierY);

            resY = Mathf.Clamp(resY, 2, 100);
            if (resY % 2 == 1)
            {
                resY -= 1;
            }
            int   resX = water.SplineResolutionX;
            float xStep = 1.0f / resX;
            float yStep = 1.0f / resY;
            float x0, x1;
            float y0, y1;

            for (int yIndex = 0; yIndex < resY; ++yIndex)
            {
                y0        = yIndex * yStep;
                pos0      = spline.EvaluatePosition(segmentIndex, y0);
                rotation0 = spline.EvaluateRotation(segmentIndex, y0);
                scale0    = spline.EvaluateScale(segmentIndex, y0);
                matrix0   = Matrix4x4.TRS(pos0, rotation0, scale0);

                y1        = (yIndex + 1) * yStep;
                pos1      = spline.EvaluatePosition(segmentIndex, y1);
                rotation1 = spline.EvaluateRotation(segmentIndex, y1);
                scale1    = spline.EvaluateScale(segmentIndex, y1);
                matrix1   = Matrix4x4.TRS(pos1, rotation1, scale1);

                bl = matrix0.MultiplyPoint(new Vector3(-halfWidth, 0, 0));
                tl = matrix1.MultiplyPoint(new Vector3(-halfWidth, 0, 0));
                tr = matrix1.MultiplyPoint(new Vector3(halfWidth, 0, 0));
                br = matrix0.MultiplyPoint(new Vector3(halfWidth, 0, 0));

                for (int xIndex = 0; xIndex < resX; ++xIndex)
                {
                    x0 = xIndex * xStep;
                    x1 = (xIndex + 1) * xStep;

                    v0 = Vector4.Lerp(bl, br, x0);
                    v1 = Vector4.Lerp(tl, tr, x0);
                    v2 = Vector4.Lerp(tl, tr, x1);
                    v3 = Vector4.Lerp(bl, br, x1);

                    currentVertexCount = vertices.Count;
                    triangles.Add(currentVertexCount + 0);
                    triangles.Add(currentVertexCount + 1);
                    triangles.Add(currentVertexCount + 2);
                    triangles.Add(currentVertexCount + 3);
                    triangles.Add(currentVertexCount + 4);
                    triangles.Add(currentVertexCount + 5);

                    flow0 = matrix0.MultiplyVector(Vector3.forward * 2);
                    flow1 = matrix1.MultiplyVector(Vector3.forward * 2);

                    if ((xIndex + yIndex) % 2 == 0)
                    {
                        BakeData(vertices, uvs0, colors, uvs1, v0, v1, v2, flow0, flow1, flow1);
                        BakeData(vertices, uvs0, colors, uvs1, v1, v2, v0, flow1, flow1, flow0);
                        BakeData(vertices, uvs0, colors, uvs1, v2, v0, v1, flow1, flow0, flow1);

                        BakeData(vertices, uvs0, colors, uvs1, v2, v3, v0, flow1, flow0, flow0);
                        BakeData(vertices, uvs0, colors, uvs1, v3, v0, v2, flow0, flow0, flow1);
                        BakeData(vertices, uvs0, colors, uvs1, v0, v2, v3, flow0, flow1, flow0);
                    }
                    else
                    {
                        BakeData(vertices, uvs0, colors, uvs1, v0, v1, v3, flow0, flow1, flow0);
                        BakeData(vertices, uvs0, colors, uvs1, v1, v3, v0, flow1, flow0, flow0);
                        BakeData(vertices, uvs0, colors, uvs1, v3, v0, v1, flow0, flow0, flow1);

                        BakeData(vertices, uvs0, colors, uvs1, v2, v3, v1, flow1, flow0, flow1);
                        BakeData(vertices, uvs0, colors, uvs1, v3, v1, v2, flow0, flow1, flow1);
                        BakeData(vertices, uvs0, colors, uvs1, v1, v2, v3, flow1, flow1, flow0);
                    }
                }
            }

            Mesh m = s.Mesh;

            m.Clear();
            m.SetVertices(vertices);
            m.SetUVs(0, uvs0);
            m.SetUVs(1, uvs1);
            m.SetColors(colors);
            m.SetTriangles(triangles, 0);
            m.RecalculateBounds();
        }
 public PAreaEditingGUIDrawer(PWater water)
 {
     this.water          = water;
     selectedAnchorIndex = -1;
 }