/// <summary> /// Copy Constructor /// </summary> /// <param name="source"><see cref="AtmosphereOptions"/> to copy</param> public AtmosphereOptions(AtmosphereOptions source) { this.Time = source.Time; this.EastPosition = source.EastPosition; this.InnerRadius = source.InnerRadius; this.OuterRadius = source.OuterRadius; this.HeightPosition = source.HeightPosition; this.RayleighMultiplier = source.RayleighMultiplier; this.MieMultiplier = source.MieMultiplier; this.SunIntensity = source.SunIntensity; this.WaveLength = source.WaveLength; this.G = source.G; this.Exposure = source.Exposure; this.NumberOfSamples = source.NumberOfSamples; }
/// <summary> /// Constructor /// </summary> /// <param name="skyX"> parent skyX reference</param> public AtmosphereManager(SkyX skyX) { this.SkyX = skyX; _options = new AtmosphereOptions(); }
/// <summary> /// Update atmoshpere /// </summary> /// <param name="options">Update only the differences between actual parameters and new ones.</param> internal void Update(AtmosphereOptions options) { Update(options, false); }
/// <summary> /// Update atmoshpere /// </summary> /// <param name="options">Update only the differences between actual parameters and new ones.</param> /// <param name="forceUpdateToAll">Forces to upload all current parameters to skyx material.</param> public void Update(AtmosphereOptions newOptions, bool forceUpdateToAll) { GpuManager mGpuManager = this.SkyX.GpuManager; if (newOptions.Time != _options.Time || newOptions.EastPosition != _options.EastPosition || forceUpdateToAll) { _options.Time = newOptions.Time; _options.EastPosition = newOptions.EastPosition; if (SkyX.IsStarFieldEnabled) { mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Fragment, "uTime", SkyX.TimeOffset * 0.05f, false); } mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uLightDir", -this.SunDirection); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Fragment, "uLightDir", -this.SunDirection, false); this.SkyX.MoonManager.Update(); } if (newOptions.InnerRadius != this.Options.InnerRadius || newOptions.OuterRadius != this.Options.OuterRadius || forceUpdateToAll) { _options.InnerRadius = newOptions.InnerRadius; _options.OuterRadius = newOptions.OuterRadius; float scale = 1.0f / (_options.OuterRadius - _options.InnerRadius); float scaleDepth = (_options.OuterRadius - _options.InnerRadius) / 2.0f; float scaleOverScaleDepth = scale / scaleDepth; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uInnerRadius", _options.InnerRadius); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uCameraPos", new Vector3(0, _options.InnerRadius + (_options.OuterRadius - _options.InnerRadius) * _options.HeightPosition, 0)); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uScale", scale); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uScaleDepth", scaleDepth); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uScaleOverScaleDepth", scaleOverScaleDepth); } if (newOptions.HeightPosition != this.Options.HeightPosition || forceUpdateToAll) { _options.HeightPosition = newOptions.HeightPosition; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uCameraPos", new Vector3(0, _options.InnerRadius + (_options.OuterRadius - _options.InnerRadius) * _options.HeightPosition, 0)); } if (newOptions.RayleighMultiplier != this.Options.RayleighMultiplier || newOptions.SunIntensity != this.Options.SunIntensity || forceUpdateToAll) { _options.RayleighMultiplier = newOptions.RayleighMultiplier; float Kr4PI = _options.RayleighMultiplier * 4.0f * Math.Utility.PI; float KrESun = _options.RayleighMultiplier * _options.SunIntensity; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uKr4PI", Kr4PI); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uKrESun", KrESun); } if (newOptions.MieMultiplier != this.Options.MieMultiplier || newOptions.SunIntensity != this.Options.SunIntensity || forceUpdateToAll) { _options.MieMultiplier = newOptions.MieMultiplier; float Km4PI = _options.MieMultiplier * 4.0f * Math.Utility.PI; float KmESun = _options.MieMultiplier * _options.SunIntensity; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uKm4PI", Km4PI); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uKmESun", KmESun, false); } if (newOptions.NumberOfSamples != this.Options.NumberOfSamples || forceUpdateToAll) { _options.NumberOfSamples = newOptions.NumberOfSamples; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uNumberOfSamples", _options.NumberOfSamples); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uSamples", (float)_options.NumberOfSamples); } if (newOptions.WaveLength != this.Options.WaveLength || forceUpdateToAll) { _options.WaveLength = newOptions.WaveLength; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Vertex, "uInvWaveLength", new Vector3(1.0f / Math.Utility.Pow(_options.WaveLength.x, 4.0f), 1.0f / Math.Utility.Pow(_options.WaveLength.y, 4.0f), 1.0f / Math.Utility.Pow(_options.WaveLength.z, 4.0f))); } if (newOptions.G != this.Options.G || forceUpdateToAll) { _options.G = newOptions.G; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Fragment, "uG", _options.G, false); mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Fragment, "uG2", _options.G * _options.G, false); } if ((newOptions.Exposure != this.Options.Exposure || forceUpdateToAll) && (this.SkyX.LightingMode == LightingMode.Ldr)) { _options.Exposure = newOptions.Exposure; mGpuManager.SetGpuProgramParameter(GpuManager.GpuProgram.Fragment, "uExposure", _options.Exposure); } this.SkyX.CloudsManager.UpdateInternal(); }