Ejemplo n.º 1
0
 /// <summary>
 /// Recreates render textures if their resolution differs from the set resolution.
 /// </summary>
 private void UpdateRenderTextureResolution()
 {
     if (m_RenderTexture1 != null && m_RenderTexture1.width != m_RenderTextureResolution)
     {
         RenderTextureUtil.RecreateRenderTexture(ref m_RenderTexture1, m_RenderTextureResolution);
         RenderTextureUtil.RecreateRenderTexture(ref m_RenderTexture2, m_RenderTextureResolution);
     }
 }
Ejemplo n.º 2
0
        private void Start()
        {
            // Create Shader IDs.
            m_LayerTextureID          = Shader.PropertyToID("_LayerTex");
            m_LayerTextureTransformID = Shader.PropertyToID("_LayerTex_ST");
            m_LayerParamsID           = Shader.PropertyToID("_LayerParams");
            m_LayerOpacityID          = Shader.PropertyToID("_LayerOpacity");

            // Create render texture.
            m_RenderTexture1 = RenderTextureUtil.CreateRenderTexture(m_RenderTextureResolution);
            m_RenderTexture2 = RenderTextureUtil.CreateRenderTexture(m_RenderTextureResolution);

            // Create materials.
            m_CloudShadowMaterial = ResourceUtil.CreateMaterial(SHADER_PATH_CLOUD_SHADOWS);

            // Initial Update
            UpdateLightProperties();
        }
Ejemplo n.º 3
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();
        }