add shader remap lerp
This commit is contained in:
parent
e0f03b3e7f
commit
7acb946c4e
149
Assets/Scenes/Terminal/ShadowRemap.asset
Normal file
149
Assets/Scenes/Terminal/ShadowRemap.asset
Normal file
@ -0,0 +1,149 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!28 &-3624966030674371785
|
||||
Texture2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: ShadowRemap
|
||||
m_ImageContentsHash:
|
||||
serializedVersion: 2
|
||||
Hash: 00000000000000000000000000000000
|
||||
m_ForcedFallbackFormat: 4
|
||||
m_DownscaleFallback: 0
|
||||
m_IsAlphaChannelOptional: 0
|
||||
serializedVersion: 2
|
||||
m_Width: 256
|
||||
m_Height: 1
|
||||
m_CompleteImageSize: 1024
|
||||
m_MipsStripped: 0
|
||||
m_TextureFormat: 4
|
||||
m_MipCount: 1
|
||||
m_IsReadable: 1
|
||||
m_IsPreProcessed: 0
|
||||
m_IgnoreMipmapLimit: 0
|
||||
m_MipmapLimitGroupName:
|
||||
m_StreamingMipmaps: 0
|
||||
m_StreamingMipmapsPriority: 0
|
||||
m_VTOnly: 0
|
||||
m_AlphaIsTransparency: 1
|
||||
m_ImageCount: 1
|
||||
m_TextureDimension: 2
|
||||
m_TextureSettings:
|
||||
serializedVersion: 2
|
||||
m_FilterMode: 1
|
||||
m_Aniso: 1
|
||||
m_MipBias: 0
|
||||
m_WrapU: 0
|
||||
m_WrapV: 0
|
||||
m_WrapW: 0
|
||||
m_LightmapFormat: 0
|
||||
m_ColorSpace: 1
|
||||
m_PlatformBlob:
|
||||
image data: 1024
|
||||
_typelessdata: fff4f4fffff4f4fffff4f5fffff5f5fffff5f5fffff6f6fffff6f6fffff6f7fffff7f7fffff7f7fffff8f8fffff8f8fffff8f9fffff9f9fffff9f9fffffafafffffafafffffafafffffbfbfffffbfbfffffcfcfffffcfcfffffcfcfffffdfdfffffdfdfffffefefffffefefffffefefffffffffffffefefffffafafffff7f7fffff3f4fffff0f0ffffededffffe9eaffffe6e6ffffe2e3ffffdfe0ffffdbddffffd8d9ffffd5d6ffffd1d3ffffcecfffffcaccffffc7c9ffffc3c5ffffc0c2ffffbdbfffffb9bbffffb6b8ffffb2b5ffffafb1ffffabaeffffa8abffffa5a7ffffa1a4ffff9ea1ffff9a9dffff979affff9397ffff9093ffff8d90ffff898dffff8689ffff8286ffff7f83ffff7c80ffff787cffff7579ffff7176ffff6e72ffff6a6fffff676cffff6468ffff6065ffff5d62ffff595effff565bffff5258ffff4f54ffff4c51ffff484effff454affff4147ffff3e44ffff3a40ffff373dffff343affff3036ffff2d33ffff2930fffe282dfffb342bfff7402afff34c29fff05827ffec6426ffe87024ffe57c23ffe18822ffdd9420ffd9a01fffd6ac1effd2b81cffcec41bffcbd019ffc7dc18ffc3e817ffc0f415ffbcff14ffc1f813ffc6f111ffcaea10ffcfe40effd4dd0dffd9d60cffddd00affe2c909ffe7c207ffebbb06fff0b505fff5ae03fff9a702fffea100ffffa106ffffa40fffffa817ffffab1fffffae27ffffb130ffffb438ffffb740ffffba48ffffbd51ffffc059ffffc461ffffc769ffffca72ffffcd7affffd082ffffd38affffd693ffffd99bffffdca3ffffe0acffffe3b4ffffe6bcffffe9c4ffffeccdffffefd5fffff2ddfffff5e5fffff8eefffffcf6fffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||
m_StreamData:
|
||||
serializedVersion: 2
|
||||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f8eadfa0c9544f341adc4b64cfa80e06, type: 3}
|
||||
m_Name: ShadowRemap
|
||||
m_EditorClassIdentifier:
|
||||
_resolution: {x: 256, y: 1}
|
||||
_sRGB: 0
|
||||
_verticalLerp:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 1
|
||||
outSlope: 1
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 1
|
||||
outSlope: 1
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
_horizontalTop:
|
||||
serializedVersion: 2
|
||||
key0: {r: 1, g: 1, b: 1, a: 1}
|
||||
key1: {r: 1, g: 1, b: 1, a: 1}
|
||||
key2: {r: 1, g: 1, b: 1, a: 0}
|
||||
key3: {r: 1, g: 1, b: 1, a: 0}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 65535
|
||||
ctime2: 65535
|
||||
ctime3: 65535
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_ColorSpace: 0
|
||||
m_NumColorKeys: 2
|
||||
m_NumAlphaKeys: 2
|
||||
_horizontalBottom:
|
||||
serializedVersion: 2
|
||||
key0: {r: 1, g: 0.95495445, b: 0.9563196, a: 1}
|
||||
key1: {r: 1, g: 1, b: 1, a: 1}
|
||||
key2: {r: 1, g: 0.15043616, b: 0.17618251, a: 1}
|
||||
key3: {r: 0.73782194, g: 1, b: 0.07843137, a: 1}
|
||||
key4: {r: 1, g: 0.62319684, b: 0, a: 0}
|
||||
key5: {r: 1, g: 1, b: 1, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 7325
|
||||
ctime2: 23516
|
||||
ctime3: 28142
|
||||
ctime4: 31804
|
||||
ctime5: 39707
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 65535
|
||||
atime3: 65535
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_ColorSpace: 0
|
||||
m_NumColorKeys: 6
|
||||
m_NumAlphaKeys: 2
|
||||
_texture: {fileID: -3624966030674371785}
|
||||
8
Assets/Scenes/Terminal/ShadowRemap.asset.meta
Normal file
8
Assets/Scenes/Terminal/ShadowRemap.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14fe883388dd915438a4832c5ce4bbf3
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts.meta
Normal file
8
Assets/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0fdd4e378d929441bca26de6e2d4890
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
480
Assets/Scripts/GradientTexture.cs
Normal file
480
Assets/Scripts/GradientTexture.cs
Normal file
@ -0,0 +1,480 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using Object = UnityEngine.Object;
|
||||
using UnityEditor.Callbacks;
|
||||
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public interface IGradientTextureForEditor
|
||||
{
|
||||
void CreateTexture();
|
||||
|
||||
Texture2D GetTexture();
|
||||
|
||||
void LoadExisitingTexture();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main Asset, holds settings, create, hold and change Texture2D's pixels, name
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "NewGradientName", menuName = "Texture/Gradient")]
|
||||
public class GradientTexture : ScriptableObject, IEquatable<Texture2D>, ISerializationCallbackReceiver,
|
||||
IGradientTextureForEditor
|
||||
{
|
||||
[SerializeField] Vector2Int _resolution = new Vector2Int(256, 256);
|
||||
[SerializeField] bool _sRGB = true;
|
||||
[SerializeField] AnimationCurve _verticalLerp = AnimationCurve.Linear(0, 0, 1, 1);
|
||||
[SerializeField, GradientUsage(true)] Gradient _horizontalTop = GetDefaultGradient();
|
||||
[SerializeField, GradientUsage(true)] Gradient _horizontalBottom = GetDefaultGradient();
|
||||
[SerializeField, HideInInspector] Texture2D _texture = default;
|
||||
|
||||
public Texture2D GetTexture() => _texture;
|
||||
|
||||
public bool GetSRGB() => _sRGB;
|
||||
|
||||
public void SetSRGB(bool value)
|
||||
{
|
||||
_sRGB = value;
|
||||
OnValidate();
|
||||
}
|
||||
|
||||
int _width => _resolution.x;
|
||||
int _height => _resolution.y;
|
||||
|
||||
public static implicit operator Texture2D(GradientTexture asset) => asset.GetTexture();
|
||||
|
||||
static Gradient GetDefaultGradient() => new Gradient
|
||||
{
|
||||
alphaKeys = new[] { new GradientAlphaKey(1, 1) },
|
||||
colorKeys = new[]
|
||||
{
|
||||
new GradientColorKey(Color.black, 0),
|
||||
new GradientColorKey(Color.white, 1)
|
||||
}
|
||||
};
|
||||
|
||||
public void FillColors(bool useRGB)
|
||||
{
|
||||
bool isLinear = QualitySettings.activeColorSpace == ColorSpace.Linear;
|
||||
|
||||
float tVertical = 0;
|
||||
|
||||
for (int y = 0; y < _height; y++)
|
||||
{
|
||||
tVertical = _verticalLerp.Evaluate((float)y / _height);
|
||||
|
||||
for (int x = 0; x < _width; x++)
|
||||
{
|
||||
float tHorizontal = (float)x / _width;
|
||||
|
||||
Color color = Color.Lerp(_horizontalBottom.Evaluate(tHorizontal),
|
||||
_horizontalTop.Evaluate(tHorizontal),
|
||||
tVertical);
|
||||
|
||||
color = useRGB && isLinear ? color.linear : color;
|
||||
_texture.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
_texture.Apply();
|
||||
}
|
||||
|
||||
public bool Equals(Texture2D other)
|
||||
{
|
||||
return _texture.Equals(other);
|
||||
}
|
||||
|
||||
void OnValidate() => ValidateTextureValues();
|
||||
|
||||
void IGradientTextureForEditor.LoadExisitingTexture()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_texture)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(this);
|
||||
_texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void IGradientTextureForEditor.CreateTexture()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
//if (EditorApplication.isUpdating) return;
|
||||
|
||||
string assetPath = AssetDatabase.GetAssetPath(this);
|
||||
if (string.IsNullOrEmpty(assetPath)) return;
|
||||
|
||||
if (!_texture && this != null && !EditorApplication.isUpdating)
|
||||
{
|
||||
AssetDatabase.ImportAsset(assetPath);
|
||||
_texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
||||
}
|
||||
|
||||
if (!_texture)
|
||||
{
|
||||
#if UNITY_2018
|
||||
_texture = new Texture2D(_resolution.x, _resolution.y);
|
||||
#else
|
||||
_texture = new Texture2D(_resolution.x, _resolution.y, DefaultFormat.LDR, TextureCreationFlags.None);
|
||||
#endif
|
||||
if (_texture.name != name) _texture.name = name;
|
||||
}
|
||||
|
||||
if (!_texture) return;
|
||||
|
||||
ValidateTextureValues();
|
||||
|
||||
if (!EditorUtility.IsPersistent(this)) return;
|
||||
if (AssetDatabase.IsSubAsset(_texture)) return;
|
||||
if (AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath)) return;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if (AssetDatabase.IsAssetImportWorkerProcess()) return;
|
||||
#endif
|
||||
AssetDatabase.AddObjectToAsset(_texture, this);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ValidateTextureValues()
|
||||
{
|
||||
if (!_texture) return;
|
||||
if (_texture.name != name)
|
||||
{
|
||||
_texture.name = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_texture.width != _resolution.x ||
|
||||
_texture.height != _resolution.y)
|
||||
{
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
_texture.Reinitialize(_resolution.x, _resolution.y);
|
||||
#else
|
||||
_texture.Resize(_resolution.x, _resolution.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
_texture.alphaIsTransparency = true;
|
||||
#endif
|
||||
FillColors(_sRGB);
|
||||
|
||||
SetDirtyTexture();
|
||||
}
|
||||
}
|
||||
|
||||
#region Editor
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
void SetDirtyTexture()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_texture) return;
|
||||
|
||||
EditorUtility.SetDirty(_texture);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_texture || _texture.name == name) return;
|
||||
|
||||
_texture.name = name;
|
||||
|
||||
//AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(GradientTexture), true), CanEditMultipleObjects]
|
||||
public class GradientTextureEditor : UnityEditor.Editor
|
||||
{
|
||||
GradientTexture _gradientTexture;
|
||||
UnityEditor.Editor _editor;
|
||||
|
||||
public override bool HasPreviewGUI() => true;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_gradientTexture = target as GradientTexture;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_gradientTexture.GetTexture() == null)
|
||||
{
|
||||
(_gradientTexture as IGradientTextureForEditor).CreateTexture();
|
||||
}
|
||||
|
||||
base.OnInspectorGUI();
|
||||
|
||||
string buttonText = "Encode to PNG" + (targets.Length > 1 ? $" ({targets.Length})" : "");
|
||||
|
||||
if (GUILayout.Button(buttonText))
|
||||
{
|
||||
foreach (Object target in targets)
|
||||
{
|
||||
GradientTexture targetTexture = target as GradientTexture;
|
||||
|
||||
string path = EditorUtility.SaveFilePanelInProject("Save file",
|
||||
$"{targetTexture.name}_baked",
|
||||
"png",
|
||||
"Choose path to save file");
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
Debug.LogError("[ GradientTextureEditor ] EncodeToPNG() save path is empty! canceled",
|
||||
targetTexture);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool wasSRGB = targetTexture.GetSRGB();
|
||||
if (wasSRGB) targetTexture.SetSRGB(false);
|
||||
byte[] bytes = ImageConversion.EncodeToPNG(targetTexture.GetTexture());
|
||||
targetTexture.SetSRGB(wasSRGB);
|
||||
|
||||
int length = "Assets".Length;
|
||||
string dataPath = Application.dataPath;
|
||||
dataPath = dataPath.Remove(dataPath.Length - length, length);
|
||||
dataPath += path;
|
||||
File.WriteAllBytes(dataPath, bytes);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.ImportAsset(path);
|
||||
Texture2D image = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
||||
|
||||
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(path);
|
||||
importer.sRGBTexture = targetTexture.GetSRGB();
|
||||
importer.SaveAndReimport();
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"[ GradientTextureEditor ] EncodeToPNG() Success! png-gradient saved at '{path}'",
|
||||
image);
|
||||
|
||||
EditorGUIUtility.PingObject(image);
|
||||
Selection.activeObject = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawPreview(Rect previewArea)
|
||||
{
|
||||
Texture2D texture = _gradientTexture.GetTexture();
|
||||
bool check = !_editor || _editor.target != texture;
|
||||
|
||||
if (check && texture && (_editor == null || _editor.target != texture))
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor = CreateEditor(targets.Select(t => (t as GradientTexture)?.GetTexture()).ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
_editor = null;
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (_editor && _editor.target)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor.DrawPreview(previewArea);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPreviewSettings()
|
||||
{
|
||||
if (_editor && _editor.target)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor.OnPreviewSettings();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReloadPreviewInstances()
|
||||
{
|
||||
if (_editor && _editor.target)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor.ReloadPreviewInstances();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
|
||||
{
|
||||
if (_editor && _editor.target)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor.OnInteractivePreviewGUI(r, background);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
||||
{
|
||||
if (_editor && _editor.target)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editor.OnPreviewGUI(r, background);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Debug.LogException(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
|
||||
{
|
||||
if (_gradientTexture == null) return null;
|
||||
if (_gradientTexture.GetTexture() == null) return null;
|
||||
Texture2D tex = new Texture2D(width, height);
|
||||
EditorUtility.CopySerialized(_gradientTexture.GetTexture(), tex);
|
||||
return tex;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (_editor)
|
||||
{
|
||||
_editor.GetType().GetMethod("OnDisable", BindingFlags.NonPublic)?.Invoke(_editor, null);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_editor)
|
||||
{
|
||||
DestroyImmediate(_editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DragAndDropUtility
|
||||
{
|
||||
static DragAndDrop.ProjectBrowserDropHandler _handlerProject;
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
public static void Init()
|
||||
{
|
||||
_handlerProject = ProjectDropHandler;
|
||||
DragAndDrop.RemoveDropHandler(_handlerProject);
|
||||
DragAndDrop.AddDropHandler(_handlerProject);
|
||||
}
|
||||
|
||||
private static DragAndDropVisualMode ProjectDropHandler(int dragInstanceId, string dropUponPath, bool perform)
|
||||
{
|
||||
if (!perform)
|
||||
{
|
||||
var dragged = DragAndDrop.objectReferences;
|
||||
bool found = false;
|
||||
for (var i = 0; i < dragged.Length; i++)
|
||||
{
|
||||
if (dragged[i] is GradientTexture gradient)
|
||||
{
|
||||
dragged[i] = gradient.GetTexture();
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
DragAndDrop.objectReferences = dragged;
|
||||
GUI.changed = true;
|
||||
return default;
|
||||
}
|
||||
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProjectIconsUtility
|
||||
{
|
||||
[DidReloadScripts]
|
||||
static ProjectIconsUtility()
|
||||
{
|
||||
EditorApplication.projectWindowItemOnGUI -= ItemOnGUI;
|
||||
EditorApplication.projectWindowItemOnGUI += ItemOnGUI;
|
||||
}
|
||||
|
||||
static void ItemOnGUI(string guid, Rect rect)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var asset = AssetDatabase.LoadAssetAtPath<GradientTexture>(assetPath);
|
||||
|
||||
if (asset == null) return;
|
||||
if (!asset.GetTexture()) return;
|
||||
|
||||
|
||||
if (rect.height > 30)
|
||||
{
|
||||
// rect.position = new Vector2(rect.position.x + rect.height * .1f + rect.width - rect.height, rect.position.y);
|
||||
// rect.height *= .87f;
|
||||
// rect.width = rect.height - 5;
|
||||
// rect.height *= .95f;
|
||||
}
|
||||
else
|
||||
{
|
||||
//rect.position = new Vector2(rect.position.x-2 + rect.width - rect.height, rect.position.y);
|
||||
rect.width = rect.height *= .9f;
|
||||
GUI.DrawTexture(rect, asset.GetTexture());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Scripts/GradientTexture.cs.meta
Normal file
11
Assets/Scripts/GradientTexture.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8eadfa0c9544f341adc4b64cfa80e06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/Scripts/SceneEffect.cs
Normal file
70
Assets/Scripts/SceneEffect.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
public class SceneEffect : MonoBehaviour
|
||||
{
|
||||
public RenderPassEvent injectionPoint = RenderPassEvent.BeforeRendering;
|
||||
|
||||
[Serializable]
|
||||
class Settings
|
||||
{
|
||||
public GradientTexture ShadowRemapTex;
|
||||
}
|
||||
[SerializeField]
|
||||
private Settings settings;
|
||||
SetupPass pass;
|
||||
private void OnEnable()
|
||||
{
|
||||
pass = new(settings);
|
||||
pass.renderPassEvent = injectionPoint;
|
||||
RenderPipelineManager.beginCameraRendering += OnBeginCamera;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
RenderPipelineManager.beginCameraRendering -= OnBeginCamera;
|
||||
}
|
||||
|
||||
|
||||
private void OnBeginCamera(ScriptableRenderContext context, Camera cam)
|
||||
{
|
||||
if (pass == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cam.cameraType != CameraType.Game && cam.cameraType != CameraType.SceneView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cam.GetUniversalAdditionalCameraData().scriptableRenderer.EnqueuePass(pass);
|
||||
}
|
||||
|
||||
private class SetupPass : ScriptableRenderPass
|
||||
{
|
||||
const string ShadowRemap = "_ShadowRemapON";
|
||||
private Settings settings;
|
||||
|
||||
public SetupPass(Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public override void FrameCleanup(CommandBuffer cmd)
|
||||
{
|
||||
cmd.DisableShaderKeyword(ShadowRemap);
|
||||
}
|
||||
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
var cmd = CommandBufferPool.Get("DissolveEffect");
|
||||
cmd.EnableShaderKeyword(ShadowRemap);
|
||||
cmd.SetGlobalTexture("_ShadowRemap", settings.ShadowRemapTex.GetTexture());
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
cmd.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SceneEffect.cs.meta
Normal file
11
Assets/Scripts/SceneEffect.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 763668dd69af1b243b7b0bebcc85b814
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -139,7 +139,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 1eadf15e5222b6546b5c84a97197f414, type: 3}
|
||||
m_Name: CapsuleAO
|
||||
m_EditorClassIdentifier:
|
||||
m_Active: 1
|
||||
m_Active: 0
|
||||
settings:
|
||||
RenderPassEvent: 450
|
||||
AmbientIntensity: 1.44
|
||||
|
||||
@ -112,7 +112,7 @@ Shader "Universal Render Pipeline/Lit"
|
||||
// -------------------------------------
|
||||
// Shader Stages
|
||||
#pragma vertex LitPassVertex
|
||||
#pragma fragment LitPassFragment
|
||||
#pragma fragment _LitPassFragment
|
||||
|
||||
// -------------------------------------
|
||||
// Material Keywords
|
||||
@ -170,9 +170,184 @@ Shader "Universal Render Pipeline/Lit"
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
||||
|
||||
#pragma multi_compile_vertex _ ENABLE_VS_SKINNING
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
|
||||
|
||||
sampler2D _ShadowRemap;
|
||||
#pragma multi_compile_fragment _ _ShadowRemapON
|
||||
|
||||
half4 _UniversalFragmentPBR(InputData inputData, SurfaceData surfaceData)
|
||||
{
|
||||
#if defined(_SPECULARHIGHLIGHTS_OFF)
|
||||
bool specularHighlightsOff = true;
|
||||
#else
|
||||
bool specularHighlightsOff = false;
|
||||
#endif
|
||||
BRDFData brdfData;
|
||||
|
||||
// NOTE: can modify "surfaceData"...
|
||||
InitializeBRDFData(surfaceData, brdfData);
|
||||
|
||||
#if defined(DEBUG_DISPLAY)
|
||||
half4 debugColor;
|
||||
|
||||
if (CanDebugOverrideOutputColor(inputData, surfaceData, brdfData, debugColor))
|
||||
{
|
||||
return debugColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Clear-coat calculation...
|
||||
BRDFData brdfDataClearCoat = CreateClearCoatBRDFData(surfaceData, brdfData);
|
||||
half4 shadowMask = CalculateShadowMask(inputData);
|
||||
AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData, surfaceData);
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
Light mainLight = GetMainLight(inputData, shadowMask, aoFactor);
|
||||
|
||||
// NOTE: We don't apply AO to the GI here because it's done in the lighting calculation below...
|
||||
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI);
|
||||
|
||||
LightingData lightingData = CreateLightingData(inputData, surfaceData);
|
||||
|
||||
lightingData.giColor = GlobalIllumination(brdfData, brdfDataClearCoat, surfaceData.clearCoatMask,
|
||||
inputData.bakedGI,
|
||||
aoFactor.indirectAmbientOcclusion,
|
||||
inputData.positionWS,
|
||||
inputData.normalWS, inputData.viewDirectionWS,
|
||||
inputData.normalizedScreenSpaceUV);
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.mainLightColor = LightingPhysicallyBased(brdfData, brdfDataClearCoat,
|
||||
mainLight,
|
||||
inputData.normalWS, inputData.viewDirectionWS,
|
||||
surfaceData.clearCoatMask, specularHighlightsOff);
|
||||
// * (step(0.01, 1 - mainLight.shadowAttenuation) /* * step( 1 - mainLight.shadowAttenuation, 0.3) */?
|
||||
// lerp(0, half3(0.5, 0, 0) * (1 - mainLight.shadowAttenuation), mainLight.shadowAttenuation) * 0 : 1);
|
||||
#ifdef _ShadowRemapON
|
||||
half4 remapValue = tex2D(_ShadowRemap, float3(mainLight.shadowAttenuation, 0, 0));
|
||||
lightingData.mainLightColor *= remapValue.rgb * remapValue.a;
|
||||
#endif
|
||||
|
||||
}
|
||||
#if defined(PLANAR_SHADOW)
|
||||
lightingData.mainLightColor *= GetPlanarScreenShadowAttenuation(inputData.normalizedScreenSpaceUV);
|
||||
#endif
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.additionalLightsColor += LightingPhysicallyBased(brdfData, brdfDataClearCoat, light,
|
||||
inputData.normalWS, inputData.viewDirectionWS,
|
||||
surfaceData.clearCoatMask, specularHighlightsOff);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.additionalLightsColor += LightingPhysicallyBased(brdfData, brdfDataClearCoat, light,
|
||||
inputData.normalWS, inputData.viewDirectionWS,
|
||||
surfaceData.clearCoatMask, specularHighlightsOff);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
#endif
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS_VERTEX)
|
||||
lightingData.vertexLightingColor += inputData.vertexLighting * brdfData.diffuse;
|
||||
#endif
|
||||
|
||||
// #if defined(_SCREEN_SPACE_SHADOW_LOW_RESOLUTION_PCF)
|
||||
// half realtimeShadow = half(SAMPLE_TEXTURE2D(_ScreenSpaceShadowmapTexture, sampler_PointClamp, inputData.normalizedScreenSpaceUV.xy).x);
|
||||
// UNITY_BRANCH
|
||||
// if(abs(realtimeShadow - 0.5) < 0.499)
|
||||
// {
|
||||
// return float4(1, 0, 0, 1);
|
||||
// }
|
||||
// #endif
|
||||
// #if defined(_SOFTSHADOW_MASK)
|
||||
// half realtimeShadow = half(SAMPLE_TEXTURE2D(_SoftShadowMaskTexture, sampler_PointClamp, inputData.normalizedScreenSpaceUV.xy).x);
|
||||
// UNITY_BRANCH
|
||||
// if(abs(realtimeShadow - 0.5) < 0.499)
|
||||
// {
|
||||
// return float4(1, 0, 0, 1);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
#if REAL_IS_HALF
|
||||
// Clamp any half.inf+ to HALF_MAX
|
||||
return min(CalculateFinalColor(lightingData, surfaceData.alpha), HALF_MAX);
|
||||
#else
|
||||
return CalculateFinalColor(lightingData, surfaceData.alpha);
|
||||
#endif
|
||||
}
|
||||
|
||||
void _LitPassFragment(
|
||||
Varyings input
|
||||
, out half4 outColor : SV_Target0
|
||||
#ifdef _WRITE_RENDERING_LAYERS
|
||||
, out float4 outRenderingLayers : SV_Target1
|
||||
#endif
|
||||
)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
#if defined(_PARALLAXMAP)
|
||||
#if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
|
||||
half3 viewDirTS = input.viewDirTS;
|
||||
#else
|
||||
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
||||
half3 viewDirTS = GetViewDirectionTangentSpace(input.tangentWS, input.normalWS, viewDirWS);
|
||||
#endif
|
||||
ApplyPerPixelDisplacement(viewDirTS, input.uv);
|
||||
#endif
|
||||
|
||||
SurfaceData surfaceData;
|
||||
InitializeStandardLitSurfaceData(input.uv, surfaceData);
|
||||
|
||||
#ifdef LOD_FADE_CROSSFADE
|
||||
LODFadeCrossFade(input.positionCS);
|
||||
#endif
|
||||
|
||||
InputData inputData;
|
||||
InitializeInputData(input, surfaceData.normalTS, inputData);
|
||||
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);
|
||||
|
||||
#ifdef _DBUFFER
|
||||
ApplyDecalToSurfaceData(input.positionCS, surfaceData, inputData);
|
||||
#endif
|
||||
|
||||
half4 color = _UniversalFragmentPBR(inputData, surfaceData);
|
||||
|
||||
color.rgb = MixFog(color.rgb, inputData.fogCoord);
|
||||
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
|
||||
|
||||
outColor = color;
|
||||
|
||||
#ifdef _WRITE_RENDERING_LAYERS
|
||||
uint renderingLayers = GetMeshRenderingLayer();
|
||||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
@ -441,7 +616,6 @@ Shader "Universal Render Pipeline/Lit"
|
||||
// Includes
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user