Пример #1
0
        protected void UpdateParams()
        {
            this.position = base.transform.position.y;
            this.scaleSum = VectorHelpers.Sum(this.waveScales);
            Vector4 vector = (Vector4.one * this.windAngle + this.waveAngles) * 0.0174532924f;

            this.waveDirection01         = VectorHelpers.GetV4(Mathf.Cos(vector.x), Mathf.Sin(vector.x), Mathf.Cos(vector.y), Mathf.Sin(vector.y));
            this.waveDirection23         = VectorHelpers.GetV4(Mathf.Cos(vector.z), Mathf.Sin(vector.z), Mathf.Cos(vector.w), Mathf.Sin(vector.w));
            this.waveOffsets            += this.waveSpeeds * Time.deltaTime;
            this.waveConstants           = VectorHelpers.Div(Vector4.one * 6.28318548f, this.waveLengths);
            this.waveDerivativeConstants = 0.5f * VectorHelpers.Mul(VectorHelpers.Mul(this.waveScales, this.waveConstants), this.waveExponents);
            float f  = (this.windAngle + this.normalMapAngle0) * 0.0174532924f;
            float f2 = (this.windAngle + this.normalMapAngle1) * 0.0174532924f;

            this.normalMapOffset0 += VectorHelpers.GetV2(Mathf.Cos(f), Mathf.Sin(f)) * this.normalMapSpeed0 * Time.deltaTime;
            this.normalMapOffset1 += VectorHelpers.GetV2(Mathf.Cos(f2), Mathf.Sin(f2)) * this.normalMapSpeed1 * Time.deltaTime;
        }
Пример #2
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]);
     }
 }