Unified Volumetric Flow

Fixed towing system
Tweaked Nebula Flow (a lot)
Extracted environment appearance settings into ZoneEnvironment data structure
Stardust particles now follow global flow field
This commit is contained in:
Reinier Vens 2021-06-18 12:32:03 +01:00
commit 00f752edf7
39 changed files with 812 additions and 341 deletions

View file

@ -6,6 +6,7 @@ using System;
using UnityEngine;
using Unity.Mathematics;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Serialization;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
@ -16,15 +17,23 @@ using static Unity.Mathematics.noise;
[RequireComponent( typeof( Camera ) ), ImageEffectAllowedInSceneView]
public class VolumeSampling : MonoBehaviour
{
public Material _volMaterial;
[FormerlySerializedAs("_volMaterial")] public Material VolMaterial;
public Transform GridTransform;
public GameSettings Settings;
//public int DownsampleBlurMask = 2;
private Camera _camera;
private RenderBuffer[] _mrt;
private RenderTexture _blurMask;
private Texture2D _disabledBlurMask;
private float _flowScroll;
public RenderTexture NebulaSurfaceHeight;
public RenderTexture NebulaPatchHeight;
public RenderTexture NebulaPatch;
public RenderTexture NebulaTint;
public bool EnableDepth { get; set; } = true;
private void Start()
{
@ -39,19 +48,19 @@ public class VolumeSampling : MonoBehaviour
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
// check for no shader / shader compile error
if( _volMaterial == null )
if( VolMaterial == null )
{
Graphics.Blit(source, destination);
return;
}
// Shader needs this matrix to generate world space rays
_volMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
_volMaterial.SetMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
VolMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
VolMaterial.SetMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
// Shader needs to know the position and scale of cameras used to render input textures
if(GridTransform != null)
_volMaterial.SetVector("_GridTransform", new Vector4(GridTransform.position.x,GridTransform.position.z,GridTransform.localScale.x));
VolMaterial.SetVector("_GridTransform", new Vector4(GridTransform.position.x,GridTransform.position.z,GridTransform.localScale.x));
_mrt[0] = destination.colorBuffer;
_mrt[1] = _blurMask.colorBuffer;
@ -59,7 +68,7 @@ public class VolumeSampling : MonoBehaviour
// Blit with a MRT.
Graphics.SetRenderTarget(_mrt, source.depthBuffer);
Graphics.Blit( source, _volMaterial, 0 );
Graphics.Blit( source, VolMaterial, 0 );
//Graphics.Blit(rt1, destination);
@ -67,5 +76,29 @@ public class VolumeSampling : MonoBehaviour
Shader.SetGlobalTexture("_DoFBlurTex", _blurMask);
else
Shader.SetGlobalTexture("_DoFBlurTex", _disabledBlurMask);
Shader.SetGlobalTexture("_NebulaSurfaceHeight", NebulaSurfaceHeight);
Shader.SetGlobalTexture("_NebulaPatchHeight", NebulaPatchHeight);
Shader.SetGlobalTexture("_NebulaPatch", NebulaPatch);
Shader.SetGlobalTexture("_NebulaTint", NebulaTint);
Shader.SetGlobalFloat("_NebulaFillDensity", Settings.DefaultEnvironment.Nebula.FillDensity);
Shader.SetGlobalFloat("_SafetyDistance", Settings.DefaultEnvironment.Nebula.FillDistance);
Shader.SetGlobalFloat("_NebulaFloorDensity", Settings.DefaultEnvironment.Nebula.FloorDensity);
Shader.SetGlobalFloat("_NebulaPatchDensity", Settings.DefaultEnvironment.Nebula.PatchDensity);
Shader.SetGlobalFloat("_NebulaFloorOffset", Settings.DefaultEnvironment.Nebula.FloorOffset);
Shader.SetGlobalFloat("_NebulaFloorBlend", Settings.DefaultEnvironment.Nebula.FloorBlend);
Shader.SetGlobalFloat("_NebulaPatchBlend", Settings.DefaultEnvironment.Nebula.PatchBlend);
// Shader.SetGlobalFloat("_TintExponent", Settings.DefaultEnvironment.);
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("_FlowScale", Settings.DefaultEnvironment.Flow.Scale);
Shader.SetGlobalFloat("_FlowAmplitude", Settings.DefaultEnvironment.Flow.Amplitude);
_flowScroll += Settings.DefaultEnvironment.Flow.ScrollSpeed * Time.deltaTime;
Shader.SetGlobalFloat("_FlowScroll", _flowScroll);
Shader.SetGlobalFloat("_FlowSpeed", Settings.DefaultEnvironment.Flow.Speed);
// Shader.SetGlobalFloat("_SafetyDistance", Settings.DefaultEnvironment.);
}
}