166 lines
5.1 KiB
C#
166 lines
5.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class ScreenSpaceSnowSM : MonoBehaviour
|
|
{
|
|
public Texture2D SnowTexture;
|
|
|
|
public bool performanceMode;
|
|
|
|
public float downScale = 1f;
|
|
|
|
public bool recreateTexture;
|
|
|
|
public float shadowPower = 0.1f;
|
|
|
|
public float shadowPowerA = 1f;
|
|
|
|
public float screenRainPower = 1f;
|
|
|
|
public float screenBrightness = 1f;
|
|
|
|
public float objectRainPower;
|
|
|
|
public Color SnowColor = Color.white;
|
|
|
|
public float SnowTextureScale = 0.1f;
|
|
|
|
[Range(0f, 1f)]
|
|
public float BottomThreshold;
|
|
|
|
[Range(0f, 1f)]
|
|
public float TopThreshold = 1f;
|
|
|
|
private Material _material;
|
|
|
|
public Texture2D SnowBumpTex;
|
|
|
|
public Vector2 SnowBumpPowerScale = new Vector2(1f, 1f);
|
|
|
|
public float Shineness = 1f;
|
|
|
|
public float specularPower = 1f;
|
|
|
|
public float OutlineThickness;
|
|
|
|
public float DepthSensitivity;
|
|
|
|
public float NormalsSensitivity;
|
|
|
|
public float ColorSensitivity;
|
|
|
|
public Vector4 OutlineColor = new Vector4(0f, 0f, 0f, 1f);
|
|
|
|
public Vector4 OutlineControls = new Vector4(1f, 1f, 1f, 1f);
|
|
|
|
public Vector4 interactPointRadius = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Vector4 radialControls = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Vector4 directionControls = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Vector4 wipeControls = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Vector4 mainTexTilingOffset = new Vector4(1f, 1f, 0f, 0f);
|
|
|
|
public float maskPower;
|
|
|
|
public float _Size = 1f;
|
|
|
|
public float _Distortion;
|
|
|
|
public float _Blur;
|
|
|
|
public Vector4 _TimeOffset = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Vector4 _EraseCenterRadius = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public float erasePower;
|
|
|
|
public float _TileNumCausticRotMin;
|
|
|
|
public Vector4 _RainSmallDirection = new Vector4(0f, 0f, 0f, 0f);
|
|
|
|
public Texture2D RainRipples;
|
|
|
|
public float RainIntensity;
|
|
|
|
public float RippleAnimSpeed = 0.2f;
|
|
|
|
public float RippleTiling = 1f;
|
|
|
|
public float WaterBumpDistance = 1000f;
|
|
|
|
private RenderTexture middleA;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_material = new Material(Shader.Find("SkyMaster/ScreenSpaceSnowSM"));
|
|
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture src, RenderTexture dest)
|
|
{
|
|
_material.SetFloat("shadowPower", shadowPower);
|
|
_material.SetFloat("shadowPowerA", shadowPowerA);
|
|
_material.SetFloat("screenRainPower", screenRainPower);
|
|
_material.SetFloat("screenBrightness", screenBrightness);
|
|
_material.SetFloat("objectRainPower", objectRainPower);
|
|
_material.SetMatrix("_CamToWorld", GetComponent<Camera>().cameraToWorldMatrix);
|
|
_material.SetColor("_SnowColor", SnowColor);
|
|
_material.SetFloat("_BottomThreshold", BottomThreshold);
|
|
_material.SetFloat("_TopThreshold", TopThreshold);
|
|
_material.SetTexture("_SnowTex", SnowTexture);
|
|
_material.SetFloat("_SnowTexScale", SnowTextureScale);
|
|
_material.SetTexture("_SnowBumpTex", SnowBumpTex);
|
|
_material.SetFloat("Shineness", Shineness);
|
|
_material.SetVector("SnowBumpPowerScale", SnowBumpPowerScale);
|
|
_material.SetFloat("specularPower", specularPower);
|
|
_material.SetFloat("OutlineThickness", OutlineThickness);
|
|
_material.SetFloat("DepthSensitivity", DepthSensitivity);
|
|
_material.SetFloat("NormalsSensitivity", NormalsSensitivity);
|
|
_material.SetFloat("ColorSensitivity", ColorSensitivity);
|
|
_material.SetVector("OutlineColor", OutlineColor);
|
|
_material.SetVector("OutlineControls", OutlineControls);
|
|
_material.SetVector("_MainTex_TexelSize", new Vector4(1f / (float)src.width, 1f / (float)src.height, src.width, src.height));
|
|
_material.SetVector("interactPointRadius", interactPointRadius);
|
|
_material.SetVector("radialControls", radialControls);
|
|
_material.SetVector("directionControls", directionControls);
|
|
_material.SetVector("wipeControls", wipeControls);
|
|
_material.SetVector("mainTexTilingOffset", mainTexTilingOffset);
|
|
_material.SetFloat("maskPower", maskPower);
|
|
_material.SetFloat("_Size", _Size);
|
|
_material.SetFloat("_Distortion", _Distortion);
|
|
_material.SetFloat("_Blur", _Blur);
|
|
_material.SetVector("_TimeOffset", _TimeOffset);
|
|
_material.SetVector("_EraseCenterRadius", _EraseCenterRadius);
|
|
_material.SetFloat("erasePower", erasePower);
|
|
_material.SetFloat("_TileNumCausticRotMin", _TileNumCausticRotMin);
|
|
_material.SetVector("_RainSmallDirection", _RainSmallDirection);
|
|
_material.SetTexture("_Lux_RainRipples", RainRipples);
|
|
_material.SetFloat("_Lux_RainIntensity", RainIntensity);
|
|
_material.SetFloat("_Lux_RippleAnimSpeed", RippleAnimSpeed);
|
|
_material.SetFloat("_Lux_RippleTiling", RippleTiling);
|
|
_material.SetFloat("_Lux_WaterBumpDistance", WaterBumpDistance);
|
|
if (middleA == null || recreateTexture)
|
|
{
|
|
recreateTexture = false;
|
|
middleA = new RenderTexture((int)((float)src.width / downScale), (int)((float)src.height / downScale), 24, RenderTextureFormat.ARGB32);
|
|
}
|
|
_material.SetFloat("doOutline", 0f);
|
|
Graphics.Blit(src, middleA, _material);
|
|
_material.SetFloat("doOutline", 1f);
|
|
if (performanceMode)
|
|
{
|
|
Graphics.Blit(middleA, dest);
|
|
}
|
|
else
|
|
{
|
|
Graphics.Blit(middleA, dest, _material);
|
|
}
|
|
}
|
|
}
|
|
}
|