예제 #1
0
    public void BakeVertexColors()
    {
        var colors = new Color[mesh.vertexCount];
        var l      = Mathf.FloorToInt(blendAmount) % 7;
        var h      = Mathf.CeilToInt(blendAmount) % 7;
        var blend  = blendAmount - l;

        try
        {
            texture1.SetPixels(SkyGradients.GetPixels(l * frameWidth, 0, frameWidth, SkyGradients.height));
            texture1.Apply();
            texture2.SetPixels(SkyGradients.GetPixels(h * frameWidth, 0, frameWidth, SkyGradients.height));
            texture2.Apply();

            if (texture3 == null)
            {
                texture3 = new Texture2D(frameWidth, SkyGradients.height, TextureFormat.RGB24, false);
                texture3.SetPixels(SkyGradients.GetPixels(7 * frameWidth, 0, frameWidth, SkyGradients.height));
                texture3.Apply();
                SkyMaterial.SetTexture("_NoiseTex", texture3);
            }
        }
        catch
        {
            Debug.LogError("Make sure your sky gradient texture is readable.");
            return;
        }

        for (var i = 0; i < colors.Length; i++)
        {
            var uv = mesh.uv[i];
            var x  = Mathf.FloorToInt(uv.x * (frameWidth - 1));
            var y  = Mathf.FloorToInt(uv.y * (texture1.height - 1));

            var c1 = texture1.GetPixel(x, y);
            var c2 = texture2.GetPixel(x + frameWidth, y);

            colors[i] = Color.Lerp(c1, c2, blend);
        }

        mesh.colors = colors;
        lastBlend   = blendAmount;
    }
예제 #2
0
    private void SkyUpdate()
    {
        PositionAndScale();

        CloudOffset += Time.fixedDeltaTime * (WindSpeed * 0.001f);

        SkyMaterial.SetColor("_CloudColor", CurrentCloudColor);
        SkyMaterial.SetFloat("_CloudCover", CloudCover);
        SkyMaterial.SetFloat("_SkyIntensity", SkyIntensity);
        SkyMaterial.SetFloat("_CloudOffset", CloudOffset);
        SkyMaterial.SetFloat("_VerticalMotion", VerticalMotion);

        var time = Mathf.Clamp(TimeOfDayRemapCurve.Evaluate(TimeOfDay), 0, 24);

        blendAmount = time / 24f * 7;
        if (Mathf.Abs(lastBlend - blendAmount) > ChangeSensitivity)
        {
            BakeVertexColors();
        }
    }
예제 #3
0
    private void Awake()
    {
        mesh        = GetComponent <MeshFilter>().mesh ?? new Mesh();
        SkyMaterial = !UseSimpleShader
                          ? new Material(Resources.Load("Shaders/CG_Sky") as Shader)
                          : new Material(Resources.Load("Shaders/CG_SimpleSky") as Shader);

        SkyMaterial.SetTexture("_CloudTex", SkyGradients);
        GetComponent <Renderer>().sharedMaterial = SkyMaterial;

        frameWidth = SkyGradients.width / 8;
        texture1   = new Texture2D(frameWidth, SkyGradients.height, TextureFormat.RGB24, false);
        texture2   = new Texture2D(frameWidth, SkyGradients.height, TextureFormat.RGB24, false);

        CurrentCloudColor = CloudColor;

        if (TimeOfDayRemapCurve == null)
        {
            TimeOfDayRemapCurve = AnimationCurve.Linear(0, 0, 24, 24);
        }
    }
예제 #4
0
        void Update()
        {
            if (Main.settings.cloudShadowsEnabled)
            {
                SunLight.cookie = WeatherSource.SunShadowRenderImage;
            }
            else
            {
                SunLight.cookie = null;
            }

#if !CYBEX_TIME
            // fauxnik time algo
            ProceduralSkyTimeSource.Instance.CalculateTimeProgress(Time.deltaTime);
            var currentTime = TimeSourceAdapter.GetCurrentTime();
#if DEBUG
            DevGUI devGui = GetComponent <DevGUI>();
            if (devGui != null && devGui.dateTimeOverride)
            {
                currentTime = devGui.CurrentTime;
            }
#endif

            DateToSkyMapper.ApplyDate(currentTime);

            // daily & yearly rotation of skybox night
            SkyboxNight.localRotation = DateToSkyMapper.SkyboxNightRotation;

            // daily & seasonal rotation of the sun
            SunPathCenter.parent.localRotation = DateToSkyMapper.SunPivotRotation;
            SunPathCenter.localPosition        = DateToSkyMapper.SunOffsetFromPath;

            // daily & seasonal rotation of the moon
            MoonPathCenter.parent.localRotation = DateToSkyMapper.MoonPivotRotation;
            MoonPathCenter.localPosition        = DateToSkyMapper.MoonOffsetFromPath;
#else
            // cybex time algo
            CybexTime.CalculateTimeProgress(Main.settings.latitude, 0);

            // rotations
            SkyboxNight.localRotation           = Quaternion.Euler(CybexTime.SkyboxNightRotation);
            SunPathCenter.parent.localRotation  = Quaternion.Euler(CybexTime.SunPivotRotation);
            MoonPathCenter.parent.localRotation = Quaternion.Euler(CybexTime.MoonRotation);

#if DEBUG
            // TODO: update this
            DevGUI devGui = GetComponent <DevGUI>();
            if (devGui != null && devGui.posOverride)
            {
                devGui.CalculateRotationOverride();
                SkyboxNight.localRotation    = devGui.skyRot;
                SunPathCenter.localRotation  = devGui.sunRot;
                MoonPathCenter.localRotation = devGui.moonRot;
            }
#endif
#endif

            // movement
            worldPos           = PlayerManager.PlayerTransform.position - WorldMover.currentMove;
            transform.position = new Vector3(worldPos.x * .001f, 0, worldPos.z * .001f);

            Vector3 highLatitudeCorrection = SunPathCenter.parent.TransformVector(SunPathCenter.localPosition) - SunPathCenter.parent.position / DateToSkyMapper.maxProjectedSunOffset;
            Vector3 sunPos            = SunLight.transform.position - SunPathCenter.position + highLatitudeCorrection;
            float   sunOverHorizonFac = Mathf.Clamp01(sunPos.y);
            SunLight.intensity = sunOverHorizonFac * 1.5f;
            SunLight.color     = Color.Lerp(new Color(1f, 0.5f, 0), Color.white, sunOverHorizonFac);

            StarMaterial.SetFloat("_Visibility", (-sunOverHorizonFac + 1) * .01f);

            MoonMaterial.SetFloat("_MoonDayNight", Mathf.Lerp(2.19f, 1.5f, sunOverHorizonFac));
            // gives aproximate moon phase
            MoonMaterial.SetFloat("_MoonPhase", Vector3.SignedAngle(SunPathCenter.right, MoonPathCenter.right, SunPathCenter.forward) / 180);
            MoonMaterial.SetFloat("_Exposure", Mathf.Lerp(2f, 4f, sunOverHorizonFac));

            SkyMaterial.SetFloat("_Exposure", Mathf.Lerp(.01f, 1f, sunOverHorizonFac));
            SkyMaterial.SetFloat("_AtmosphereThickness", Mathf.Lerp(0.1f, 1f, Mathf.Clamp01(sunOverHorizonFac * 10)));

            CloudMaterial.SetFloat("_NScale", WeatherSource.CloudNoiseScaleBlend);
            CloudMaterial.SetFloat("_ClearSky", WeatherSource.CloudClearSkyBlend);
            float facC = Mathf.Lerp(.002f, 1f, sunOverHorizonFac);
            CloudMaterial.SetFloat("_CloudBright", WeatherSource.CloudBrightnessBlend * facC);
            float facG = Mathf.Lerp(.25f, 0.0f, sunOverHorizonFac);
            CloudMaterial.SetFloat("_CloudGradient", WeatherSource.CloudGradientBlend + facG);
            CloudMaterial.SetFloat("_CloudSpeed", WeatherSource.CloudSpeedBlend);
            CloudMaterial.SetFloat("_CloudChange", WeatherSource.CloudChangeBlend);
#if DEBUG
            if (devGui != null && devGui.cloudOverride)
            {
                CloudMaterial.SetFloat("_NScale", devGui.loadedWeatherState.cloudNoiseScale);
                CloudMaterial.SetFloat("_ClearSky", devGui.loadedWeatherState.cloudClearSky);
                CloudMaterial.SetFloat("_CloudBright", devGui.loadedWeatherState.cloudBrightness * facC);
                CloudMaterial.SetFloat("_CloudGradient", devGui.loadedWeatherState.cloudGradient + facG);
                CloudMaterial.SetFloat("_CloudSpeed", devGui.loadedWeatherState.cloudSpeed);
                CloudMaterial.SetFloat("_CloudChange", devGui.loadedWeatherState.cloudChange);
            }
#endif

            RenderSettings.fogColor        = Color.Lerp(nightFog, defaultFog, sunOverHorizonFac);
            RenderSettings.ambientSkyColor = Color.Lerp(ambientNight, ambientDay, sunOverHorizonFac);

#if DEBUG
            if (devGui != null && devGui.rainOverride)
            {
                RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, devGui.loadedWeatherState.rainParticleStrength);
                RainController.SetRainStrength(devGui.loadedWeatherState.rainParticleStrength);
            }
            else
            {
                RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, WeatherSource.RainStrengthBlend);
                RainController.SetRainStrength(WeatherSource.RainStrengthBlend);
            }
#else
            RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, WeatherSource.RainStrengthBlend);
            RainController.SetRainStrength(WeatherSource.RainStrengthBlend);
#endif

            RainController.SetRainColor(new Color(RenderSettings.fogColor.r + 0.5f, RenderSettings.fogColor.g + 0.5f, RenderSettings.fogColor.b + 0.5f, 1));
        }