Nebula Lighting Everywhere + Perspective Distortion Fix

Applied nebula lit shader to "planets" and asteroids
Modified gas giant shader to accept nebula lighting and to be a bit less crappy in general
Fixed raymarching depth sampling perspective distortion
This commit is contained in:
Reinier Vens 2022-07-16 06:42:40 +01:00
commit 07bddc0a6a
67 changed files with 561 additions and 160 deletions

View file

@ -31,6 +31,10 @@ public class NebulaSettings
[JsonProperty("tintExponent"), Key(8)] public float TintExponent;
[JsonProperty("tintLodExponent"), Key(9)] public float TintLodExponent;
[JsonProperty("safetyDistance"), Key(10)] public float SafetyDistance;
[JsonProperty("dynamicSkyBoost"), Key(14)] public float DynamicSkyBoost;
[JsonProperty("dynamicLodRange"), Key(15)] public float DynamicLodRange;
[JsonProperty("dynamicLodBias"), Key(16)] public float DynamicLodBias;
[JsonProperty("dynamicIntensity"), Key(17)] public float DynamicIntensity;
}
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]

View file

@ -40,7 +40,7 @@ public enum Quality
/// <summary>
/// Cloud renderer post processing.
/// </summary>
[ImageEffectAllowedInSceneView]
//[ImageEffectAllowedInSceneView]
[ExecuteInEditMode,RequireComponent(typeof(Camera))]
[ImageEffectOpaque]
public class VolumeCloudRenderer : EffectBase

View file

@ -31,6 +31,7 @@ public class VolumeSampling : MonoBehaviour
public RenderTexture NebulaPatchHeight;
public RenderTexture NebulaPatch;
public RenderTexture NebulaTint;
private Camera _camera;
public bool EnableDepth { get; set; } = true;
@ -38,7 +39,7 @@ public class VolumeSampling : MonoBehaviour
private void Start()
{
//Debug.Log($"Supported MRT count: {SystemInfo.supportedRenderTargetCount}");
// _camera = GetComponent<Camera>();
_camera = GetComponent<Camera>();
// _mrt = new RenderBuffer[2];
//_blurMask = new RenderTexture(Screen.width, Screen.height, 0, GraphicsFormat.R8_UNorm);
_blurMask = Color.white.ToTexture();
@ -61,8 +62,8 @@ public class VolumeSampling : MonoBehaviour
Shader.SetGlobalVector("_GridTransform", new Vector4(GridTransform.position.x,GridTransform.position.z,GridTransform.localScale.x));
//
// Shader needs this matrix to generate world space rays
// Shader.SetGlobalMatrix("_CamProj", (Camera.current.projectionMatrix * Camera.current.worldToCameraMatrix).inverse);
// Shader.SetGlobalMatrix("_CamInvProj", (Camera.current.projectionMatrix * Camera.current.worldToCameraMatrix).inverse);
Shader.SetGlobalMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
Shader.SetGlobalMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
// _mrt[0] = destination.colorBuffer;
// _mrt[1] = _blurMask.colorBuffer;
//
@ -97,11 +98,15 @@ public class VolumeSampling : MonoBehaviour
Shader.SetGlobalFloat("_TintExponent", Settings.DefaultEnvironment.Nebula.TintExponent);
Shader.SetGlobalFloat("_TintLodExponent", Settings.DefaultEnvironment.Nebula.TintLodExponent);
Shader.SetGlobalFloat("_SafetyDistance", Settings.DefaultEnvironment.Nebula.SafetyDistance);
Shader.SetGlobalFloat("_DynamicSkyBoost", Settings.DefaultEnvironment.Nebula.DynamicSkyBoost);
Shader.SetGlobalFloat("_DynamicLodRange", Settings.DefaultEnvironment.Nebula.DynamicLodRange);
Shader.SetGlobalFloat("_DynamicLodBias", Settings.DefaultEnvironment.Nebula.DynamicLodBias);
Shader.SetGlobalFloat("_DynamicIntensity", Settings.DefaultEnvironment.Nebula.DynamicIntensity);
Shader.SetGlobalFloat("_NoiseScale", Settings.DefaultEnvironment.Noise.Scale);
Shader.SetGlobalFloat("_NoiseExponent", Settings.DefaultEnvironment.Noise.Exponent);
Shader.SetGlobalFloat("_NoiseAmplitude", Settings.DefaultEnvironment.Noise.Amplitude);
Shader.SetGlobalFloat("_NoiseSpeed", Settings.DefaultEnvironment.Noise.Speed);
Shader.SetGlobalFloat("_NebulaNoiseScale", Settings.DefaultEnvironment.Noise.Scale);
Shader.SetGlobalFloat("_NebulaNoiseExponent", Settings.DefaultEnvironment.Noise.Exponent);
Shader.SetGlobalFloat("_NebulaNoiseAmplitude", Settings.DefaultEnvironment.Noise.Amplitude);
Shader.SetGlobalFloat("_NebulaNoiseSpeed", Settings.DefaultEnvironment.Noise.Speed);
Shader.SetGlobalFloat("_FlowScale", Settings.DefaultEnvironment.Flow.Scale);
Shader.SetGlobalFloat("_FlowAmplitude", Settings.DefaultEnvironment.Flow.Amplitude);

View file

@ -362,11 +362,11 @@ public class ZoneRenderer : MonoBehaviour
var gas = (GasGiantObject) planet;
var gasGiant = Zone.PlanetInstances[planetData.ID] as GasGiant;
gasGiantData.Colors.Subscribe(c => gas.Body.material.SetTexture("_ColorRamp", c.ToGradient(!(planetData is SunData)).ToTexture()));
gasGiantData.AlbedoRotationSpeed.Subscribe(f => gas.SunMaterial.AlbedoRotationSpeed = f);
gasGiantData.FirstOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetRotationSpeed = f);
gasGiantData.SecondOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetRotationSpeed = f);
gasGiantData.FirstOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetDomainRotationSpeed = f);
gasGiantData.SecondOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetDomainRotationSpeed = f);
// gasGiantData.AlbedoRotationSpeed.Subscribe(f => gas.SunMaterial.AlbedoRotationSpeed = f);
// gasGiantData.FirstOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetRotationSpeed = f);
// gasGiantData.SecondOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetRotationSpeed = f);
// gasGiantData.FirstOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetDomainRotationSpeed = f);
// gasGiantData.SecondOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetDomainRotationSpeed = f);
gasGiant.GravityWavesRadius.Subscribe(f => gas.GravityWaves.transform.localScale = f * Vector3.one);
gasGiant.GravityWavesDepth.Subscribe(f => gas.GravityWaves.material.SetFloat("_Depth", f));
planetData.Mass.Subscribe(f => gas.GravityWaves.material.SetFloat("_Frequency", Settings.PlanetSettings.WaveFrequency.Evaluate(f)));