Exemple #1
0
        private void CameraPreRender(Camera camera)
        {
            if (model != null)
            {
                model.Restore(camera);
            }

            // Write camera-dependant shader values
            if (innerMaterial != null && outerMaterial != null)
            {
                var cameraPosition       = camera.transform.position;
                var localCameraPosition  = transform.InverseTransformPoint(cameraPosition);
                var localDistance        = localCameraPosition.magnitude;
                var clampedSky           = Mathf.InverseLerp(OuterRadius, InnerMeshRadius, localDistance);
                var innerAtmosphereDepth = default(float);
                var outerAtmosphereDepth = default(float);
                var radiusRatio          = SgtHelper.Divide(InnerMeshRadius, OuterRadius);
                var scaleDistance        = SgtHelper.Divide(localDistance, OuterRadius);
                var innerDensity         = 1.0f - InnerFog;
                var outerDensity         = 1.0f - OuterFog;

                SgtHelper.CalculateAtmosphereThicknessAtHorizon(radiusRatio, 1.0f, scaleDistance, out innerAtmosphereDepth, out outerAtmosphereDepth);

                SgtHelper.SetTempMaterial(innerMaterial, outerMaterial);

                if (scaleDistance > 1.0f)
                {
                    SgtHelper.EnableKeyword("SGT_A");                     // Outside
                }
                else
                {
                    SgtHelper.DisableKeyword("SGT_A");                     // Outside
                }

                innerMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(innerAtmosphereDepth * innerDensity));
                outerMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(outerAtmosphereDepth * outerDensity));

                if (OuterDepthTex != null)
                {
#if UNITY_EDITOR
                    SgtHelper.MakeTextureReadable(OuterDepthTex);
#endif
                    outerMaterial.SetFloat("_Sky", GetSky(camera) * OuterDepthTex.GetPixelBilinear(clampedSky / outerDensity, 0.0f).a);
                }

                UpdateMaterialNonSerialized();
            }
        }