Exemple #1
0
        private Vector4 GetMeshInfo(MeshRenderer r)
        {
            Bounds meshBounds = r.bounds;

            //Mesh size has to be uniform
            if (StylizedWaterUtilities.IsApproximatelyEqual(r.bounds.extents.x, r.bounds.extents.z))
            {
                if (debug)
                {
                    Debug.LogErrorFormat("[Stylized Water] Size of \"{0}\" is not uniform at {1}! Width and Length must be equal!", r.name, r.bounds.extents.x + "x" + r.bounds.extents.z);
                }
            }

            targetSize           = meshBounds.extents * 2;
            targetCenterPosition = meshBounds.center;

            if (debug)
            {
                Debug.Log(r.name + " : Size = " + targetSize + " Center = " + targetCenterPosition);
            }

            Vector4 meshScaleOffset = new Vector4(targetSize.x, targetSize.z, targetCenterPosition.x - (targetSize.x / 2), targetCenterPosition.z - (targetSize.z / 2));

            Shader.SetGlobalVector("_SWS_RENDERTEX_POS", meshScaleOffset);

            return(meshScaleOffset);
        }
Exemple #2
0
        //Called through inspector OnEnable, editor-only
        public void Init()
        {
#if UNITY_EDITOR
            #region Dropdowns
            //Avoids a null ref on start up, instance will be created some frames later(?)
            if (StylizedWaterResources.Instance != null)
            {
                intersectionStyleNames = StylizedWaterUtilities.ComposeDropdown(StylizedWaterResources.Instance.intersectionStyles, "SWS_Intersection_");

                waveStyleNames = StylizedWaterUtilities.ComposeDropdown(StylizedWaterResources.Instance.waveStyles, "SWS_Waves_");

                waveHeightmapNames = StylizedWaterUtilities.ComposeDropdown(StylizedWaterResources.Instance.heightmapStyles, "SWS_Heightmap_");
            }

            tilingMethodNames       = new string[] { "Mesh UV", "World-aligned (planar)" };
            intersectionSolverNames = new string[] { "Depth-based", "Vertex color (red)" };
            foamSolverNames         = new string[] { "Normal map", "Intersection texture" };
            lightingMethodNames     = new string[] { "Unlit", "Basic", "Advanced" };
            refractionSolverNames   = new string[] { "Performance", "Appearance" };
            resolutionNames         = new string[] { "Low", "Medium", "High" };
            #endregion

            //Create initial gradient
            if (colorGradient == null)
            {
                colorGradient = new Gradient();
            }
            if (colorGradient.Evaluate(0f) == Color.clear && colorGradient.Evaluate(1f) == Color.clear)
            {
                //Debug.Log("Creating initial gradient");

                colorGradient = new Gradient();
                GradientColorKey[] colorKeys = new GradientColorKey[2];
                colorKeys[0].time  = 0f;
                colorKeys[0].color = waterShallowColor;
                colorKeys[1].time  = 1f;
                colorKeys[0].color = waterColor;

                GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2];
                alphaKeys[0].time  = 0f;
                alphaKeys[0].alpha = waterShallowColor.a;
                alphaKeys[1].time  = 1f;
                alphaKeys[1].alpha = waterColor.a;

                colorGradient.SetKeys(colorKeys, alphaKeys);
            }
#endif
        }