Example #1
0
        protected void IntersectFrustumEdgeWaterPlane(Vector3 start, Vector3 end, List <Vector3> points)
        {
            if (!this.init_top_bottom_Plane)
            {
                this.topPlane              = new Plane(Vector3.up, Vector3.up * (this.position + this.scaleSum));
                this.bottomPlane           = new Plane(Vector3.up, Vector3.up * this.position);
                this.init_top_bottom_Plane = true;
            }
            else
            {
                this.topPlane.SetNormalAndPosition(Vector3.up, Vector3.up * (this.position + this.scaleSum));
                this.bottomPlane.SetNormalAndPosition(Vector3.up, Vector3.up * this.position);
            }
            Vector3 vector     = end - start;
            Vector3 normalized = vector.normalized;
            float   magnitude  = vector.magnitude;

            this.topPlaneRay.origin    = start;
            this.topPlaneRay.direction = normalized;
            float num;

            if (this.topPlane.Raycast(this.topPlaneRay, out num) && num <= magnitude)
            {
                Vector3 vector2 = start + normalized * num;
                points.Add(VectorHelpers.GetV3(vector2.x, this.position, vector2.z));
            }
            this.bottomPlaneRay.origin    = start;
            this.bottomPlaneRay.direction = normalized;
            if (this.bottomPlane.Raycast(this.bottomPlaneRay, out num) && num <= magnitude)
            {
                Vector3 vector3 = start + normalized * num;
                points.Add(VectorHelpers.GetV3(vector3.x, this.position, vector3.z));
            }
        }
Example #2
0
 protected void IntersectFrustumWaterPlane(Camera cam)
 {
     this.corners[0] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(0f, 0f, cam.nearClipPlane));
     this.corners[1] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(0f, 1f, cam.nearClipPlane));
     this.corners[2] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(1f, 1f, cam.nearClipPlane));
     this.corners[3] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(1f, 0f, cam.nearClipPlane));
     this.corners[4] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(0f, 0f, cam.farClipPlane));
     this.corners[5] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(0f, 1f, cam.farClipPlane));
     this.corners[6] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(1f, 1f, cam.farClipPlane));
     this.corners[7] = cam.ViewportToWorldPoint(VectorHelpers.GetV3(1f, 0f, cam.farClipPlane));
     if (this.points != null)
     {
         this.points.Clear();
     }
     this.IntersectFrustumEdgeWaterPlane(this.corners[0], this.corners[1], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[1], this.corners[2], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[2], this.corners[3], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[3], this.corners[0], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[4], this.corners[5], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[5], this.corners[6], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[6], this.corners[7], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[7], this.corners[4], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[0], this.corners[4], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[1], this.corners[5], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[2], this.corners[6], this.points);
     this.IntersectFrustumEdgeWaterPlane(this.corners[3], this.corners[7], this.points);
 }
Example #3
0
        protected void CreateQuadMesh()
        {
            int num  = this.meshResolutionX;
            int num2 = this.meshResolutionY;

            Vector3[] array  = new Vector3[num * num2];
            int[]     array2 = new int[(num - 1) * (num2 - 1) * 2 * 3];
            for (int i = 0; i < num; i++)
            {
                for (int j = 0; j < num2; j++)
                {
                    array[i * num2 + j] = VectorHelpers.GetV3((float)i / (float)(num - 1), (float)j / (float)(num2 - 1), 0f);
                }
            }
            int num3 = 0;

            for (int k = 0; k < num - 1; k++)
            {
                for (int l = 0; l < num2 - 1; l++)
                {
                    array2[num3++] = k * num2 + l;
                    array2[num3++] = k * num2 + (l + 1);
                    array2[num3++] = (k + 1) * num2 + (l + 1);
                    array2[num3++] = k * num2 + l;
                    array2[num3++] = (k + 1) * num2 + (l + 1);
                    array2[num3++] = (k + 1) * num2 + l;
                }
            }
            Mesh mesh = new Mesh();

            mesh.name                  = "Ocean Mesh";
            mesh.vertices              = array;
            mesh.triangles             = array2;
            mesh.bounds                = new Bounds(Vector3.zero, Vector3.one * this.meshBoundsSize);
            this.meshFilter.sharedMesh = mesh;
        }
Example #4
0
 protected void PreRender(Camera cam)
 {
     if (this.mainCameraOnly && cam != Camera.main && cam.name != "Fight Camera" && !cam.CompareTag("MainCamera"))
     {
         return;
     }
     this.IntersectFrustumWaterPlane(cam);
     if (this.points.Count > 0)
     {
         if (!this.init_waterPlane)
         {
             this.waterPlane      = new Plane(Vector3.up, Vector3.up * this.position);
             this.init_waterPlane = true;
         }
         else
         {
             this.waterPlane.SetNormalAndPosition(Vector3.up, Vector3.up * this.position);
         }
         Vector3 b = cam.transform.position;
         float   a = this.position + this.scaleSum + 10f;
         b.y = Mathf.Max(a, b.y);
         Vector3 a2          = cam.transform.position + cam.transform.forward * 5f;
         Vector3 vector      = Vector3.Normalize(a2 - b);
         Vector3 normalized  = Vector3.Cross(Vector3.up, vector).normalized;
         Vector3 normalized2 = Vector3.Cross(vector, normalized).normalized;
         this.viewFrame.SetColumn(0, normalized);
         this.viewFrame.SetColumn(1, normalized2);
         this.viewFrame.SetColumn(2, -vector);
         this.viewFrame.SetColumn(3, VectorHelpers.GetV4(b.x, b.y, b.z, 1f));
         Matrix4x4 inverse          = this.viewFrame.inverse;
         Matrix4x4 projectionMatrix = cam.projectionMatrix;
         Matrix4x4 matrix4x         = projectionMatrix * inverse;
         Shader.SetGlobalMatrix("ot_Proj", projectionMatrix);
         Shader.SetGlobalMatrix("ot_InvView", inverse.inverse);
         Vector3[] array    = this.ProjectPointsToNdc(matrix4x, this.points);
         Matrix4x4 lhs      = this.MapNdcBoundingBoxToFullscreen(array);
         Matrix4x4 inverse2 = (lhs * matrix4x).inverse;
         Vector2[] array2   = new Vector2[]
         {
             VectorHelpers.GetV2(0f, 0f),
             VectorHelpers.GetV2(1f, 0f),
             VectorHelpers.GetV2(1f, 1f),
             VectorHelpers.GetV2(0f, 1f)
         };
         for (int i = 0; i < array2.Length; i++)
         {
             Vector2 vector2     = array2[i];
             Vector3 v           = VectorHelpers.GetV3(vector2.x, vector2.y, -1f);
             Vector3 v2          = VectorHelpers.GetV3(vector2.x, vector2.y, 1f);
             Vector3 vector3     = inverse2.MultiplyPoint(v);
             Vector3 a3          = inverse2.MultiplyPoint(v2);
             Vector3 normalized3 = (a3 - vector3).normalized;
             this.waterPlaneRay.origin    = vector3;
             this.waterPlaneRay.direction = normalized3;
             float d;
             this.waterPlane.Raycast(this.waterPlaneRay, out d);
             Vector3 v3 = vector3 + normalized3 * d;
             this.viewCorners[i] = inverse.MultiplyPoint(v3);
         }
         Shader.SetGlobalVector("ot_ViewCorner0", this.viewCorners[0]);
         Shader.SetGlobalVector("ot_ViewCorner1", this.viewCorners[1]);
         Shader.SetGlobalVector("ot_ViewCorner2", this.viewCorners[2]);
         Shader.SetGlobalVector("ot_ViewCorner3", this.viewCorners[3]);
     }
 }