示例#1
0
        private static void DrawTextureOptions(SerializedProperty cloudLayerElement)
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.LabelField("Texture Settings", EditorStyles.boldLabel);

            EditorGUI.indentLevel += 1;

            SerializedProperty textureProperty = cloudLayerElement.FindPropertyRelative(CloudLayerData.PATH_TEXTURE);

            EditorGUILayout.PropertyField(textureProperty);

            if (textureProperty.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("No Texture assigned.", MessageType.Warning);
            }

            SerializedProperty tilingProperty = cloudLayerElement.FindPropertyRelative(CloudLayerData.PATH_TEXTURE_TILING);

            EditorGUILayout.PropertyField(tilingProperty);
            tilingProperty.vector2Value = CloudLayerData.LimitTextureTiling(tilingProperty.vector2Value);

            EditorGUILayout.PropertyField(cloudLayerElement.FindPropertyRelative(CloudLayerData.PATH_TEXTURE_OFFSET));

            EditorGUI.indentLevel -= 1;

            EditorGUILayout.EndVertical();
        }
示例#2
0
        /// <summary>
        /// Combines layer properties into a single Vector4 to be used as a shader property.
        /// </summary>
        private Vector4 ExtractCloudLayerParameters(CloudLayerData cloudLayerData)
        {
            float coverage = Mathf.Clamp01(cloudLayerData.Coverage + m_CoverageModifier);
            float softness = Mathf.Clamp01(cloudLayerData.Softness + m_SoftnessModifier);

            return(new Vector4(cloudLayerData.AnimationOffset.x, cloudLayerData.AnimationOffset.y, coverage, softness));
        }
示例#3
0
        /// <summary>
        /// Calculates the final opacity for the passed in layer.
        /// </summary>
        private float CalculateCloudLayerOpacity(CloudLayerData cloudLayerData, float angleToHorizon)
        {
            float opacity = 1;

            // In 3D Mode calculate the opacity based on the angle between the lights direction and horizon.
            if (m_ProjectMode == ProjectMode.Mode3D)
            {
                opacity = Mathf.Clamp01((angleToHorizon - m_HorizonAngleThreshold) / m_HorizonAngleFade);
            }

            opacity *= cloudLayerData.Opacity;
            opacity *= m_OpacityMultiplier;

            return(opacity);
        }
示例#4
0
        public CloudLayerData this[int index]
        {
            get
            {
                CloudLayerData cloudLayerData = null;

                if (index >= 0 && index < m_LayerData.Count)
                {
                    cloudLayerData = m_LayerData[index];
                }

                UnityEngine.Debug.Assert(cloudLayerData != null, "Failed to get CloudLayerData. Index out of bounds");

                return(cloudLayerData);
            }
        }
示例#5
0
        /// <summary>
        /// Updates cloud layer animation offsets
        /// </summary>
        private static void UpdateCloudLayerDataAnimationOffset(CloudLayerData cloudLayerData, float worldSize, float globalSpeedMultiplier, float globalDirectionModifier)
        {
            Vector2 cloudLayerDirection = CalculateLayerDirection(cloudLayerData.DirectionAngle, globalDirectionModifier);
            Vector2 translation         = cloudLayerDirection * cloudLayerData.Speed * globalSpeedMultiplier * Time.deltaTime;

            // Make sure cloud translation is independent from world size and texture tiling.
            translation   /= worldSize;
            translation.x *= cloudLayerData.TextureTiling.x;
            translation.y *= cloudLayerData.TextureTiling.y;

            Vector2 animationOffset = cloudLayerData.AnimationOffset;

            animationOffset += translation;

            // Repeat floats to avoid precision loss problems.
            animationOffset.x = Mathf.Repeat(animationOffset.x, worldSize);
            animationOffset.y = Mathf.Repeat(animationOffset.y, worldSize);

            cloudLayerData.AnimationOffset = animationOffset;
        }
示例#6
0
        /// <summary>
        /// Renders all of the layers to a single render texture and assigns it to the light.
        /// </summary>
        private void RenderCloudShadows()
        {
            // Clear alpha channel of first render texture to white.
            RenderTextureUtil.ClearRenderTexture(m_RenderTexture1, new Color(0, 0, 0, 1));

            // Don't render if Cloud Layers are not assigned or opacity is 0
            if (m_CloudLayers != null && m_OpacityMultiplier > 0.0f)
            {
                // Calculate the angle between the lights direction and the horizon.
                float angleToHorizon = Vector3.Angle(Vector3.up, transform.forward) - 90;

                // Render layers
                for (int i = 0; i < m_CloudLayers.LayerCount; ++i)
                {
                    CloudLayerData cloudLayerData = m_CloudLayers[i];

                    // Update cloud layer animation offsets.
                    UpdateCloudLayerDataAnimationOffset(cloudLayerData, m_WorldSize, m_SpeedMultiplier, m_DirectionModifier);

                    if (cloudLayerData.IsVisible)
                    {
                        // Set material texture properties.
                        m_CloudShadowMaterial.SetTexture(m_LayerTextureID, cloudLayerData.Texture);
                        m_CloudShadowMaterial.SetVector(m_LayerTextureTransformID, cloudLayerData.TextureTransform);

                        // Set remaining material properties.
                        m_CloudShadowMaterial.SetVector(m_LayerParamsID, ExtractCloudLayerParameters(cloudLayerData));
                        m_CloudShadowMaterial.SetFloat(m_LayerOpacityID, CalculateCloudLayerOpacity(cloudLayerData, angleToHorizon));

                        // Blit using material.
                        Graphics.Blit(m_RenderTexture1, m_RenderTexture2, m_CloudShadowMaterial, (int)cloudLayerData.BlendMode);

                        // Swap render texture references.
                        RenderTextureUtil.SwapRenderTextures(ref m_RenderTexture1, ref m_RenderTexture2);
                    }
                }
            }

            UpdateLightProperties();
        }