一些特效

This commit is contained in:
SoulliesOfficial
2025-06-28 03:01:03 -04:00
parent 16418804e4
commit 1a3d37d9b5
216 changed files with 41141 additions and 2728 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fd758a702a9040fcb8614b232817cff9
timeCreated: 1721290722

View File

@@ -0,0 +1,100 @@
using UnityEditor;
using UnityEngine;
using System;
// using Unity.Properties;
public class BinaryIntAttribute : PropertyAttribute
{
public int binaryBits;
public bool showInputFiled;
public int tabNums;
public BinaryIntAttribute(int Bits = 32,bool showInput = false,int tab = 0)
{
binaryBits = Bits;
showInputFiled = showInput;
tabNums = tab;
}
}
[CustomPropertyDrawer(typeof(BinaryIntAttribute))]
public class BinaryIntDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUIStyle richTextStyle = EditorStyles.label;
richTextStyle.richText = true;
BinaryIntAttribute binaryIntAttribute = (BinaryIntAttribute)attribute;
// int value = property.intValue;
// int largestBit = 0;
// for (int i = 0; i < 32; i++)
// {
// if ((~value & (1 << i)) == 0)
// {
// largestBit = i;
// }
// }
//
// int addZeroCount = 0;
// if (largestBit < binaryIntAttribute.binaryBits)
// {
// addZeroCount = binaryIntAttribute.binaryBits - largestBit - 1;
// }
//
// string addZeroString = "";
// for (int i = 0; i < addZeroCount; i++)
// {
// addZeroString += "0";
// }
// string binary = addZeroString+Convert.ToString(property.intValue, 2);
string binary = DrawBinaryInt(property.intValue, binaryIntAttribute.binaryBits);
string tabs = "";
for (int i = 0; i < binaryIntAttribute.tabNums; i++)
{
tabs += "\t";
}
if (binaryIntAttribute.showInputFiled)
{
string labelText = property.displayName + tabs + "<mspace=1em>" + binary + "</mspace>";
Rect intRect = EditorGUI.PrefixLabel(position,new GUIContent(labelText),richTextStyle);
property.intValue = EditorGUI.IntField( intRect,property.intValue);
}
else
{
EditorGUILayout.LabelField(property.displayName + tabs);
EditorGUILayout.LabelField(binary);
}
}
public static string DrawBinaryInt(int value ,int binaryBits)
{
int largestBit = 0;
for (int i = 0; i < 32; i++)
{
if ((~value & (1 << i)) == 0)
{
largestBit = i;
}
}
int addZeroCount = 0;
if (largestBit < binaryBits)
{
addZeroCount = binaryBits - largestBit - 1;
}
string addZeroString = "";
for (int i = 0; i < addZeroCount; i++)
{
addZeroString += "0";
}
string binary = addZeroString+Convert.ToString(value, 2);
return binary;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4517deaf5f31a5848b6a58304d1f516f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,236 @@
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.GraphView;
using System;
using System.Collections.Generic;
// #if UNITY_EDITOR
[CustomEditor(typeof(MaterialPropertyAgent))]
public class MaterialPropertyAgentInspector : UnityEditor.Editor
{
private MaterialPropertyAgent agent;
private void OnEnable()
{
agent = (MaterialPropertyAgent)target;
}
private GUIContent materialIndexContent = new GUIContent("材质序号:", "只有模型模式下需要使用,谨慎修改");
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
if (!agent.isGetByComponet)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("customRenderer"),new GUIContent("指定Renderer"));
}
if (agent.isRendererMode)
{
EditorGUILayout.BeginHorizontal();
int lastIndex = agent.materialIndex;
agent.materialIndex = EditorGUILayout.IntField(materialIndexContent ,agent.materialIndex);
if (lastIndex != agent.materialIndex)
{
agent.initMatAndShaderByMaterialIndexChange();
}
EditorGUILayout.LabelField("材质名:"+agent.mat.name+"\t"+"Shader名"+agent.shader.name);
EditorGUILayout.EndHorizontal();
}
DrawPropertyData(ref agent.data0, "Data0", serializedObject.FindProperty("data0"));
DrawPropertyData(ref agent.data1, "Data1", serializedObject.FindProperty("data1"));
DrawPropertyData(ref agent.data2, "Data2", serializedObject.FindProperty("data2"));
DrawPropertyData(ref agent.data3, "Data3", serializedObject.FindProperty("data3"));
DrawPropertyData(ref agent.data4, "Data4", serializedObject.FindProperty("data4"));
DrawPropertyData(ref agent.data5, "Data5", serializedObject.FindProperty("data5"));
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("添加"))
{
agent.addProperteData();
}
if (GUILayout.Button("全部删除"))
{
agent.removeAllProperty();
}
EditorGUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
PrefabUtility.RecordPrefabInstancePropertyModifications(agent);
if (!agent.isGetByComponet && agent.mat)
{
if(matEditor) DestroyImmediate(matEditor);
matEditor = (MaterialEditor)CreateEditor(agent.mat);
}
}
if (!agent.isGetByComponet && agent.mat)
{
DrawMaterialInspector(matEditor,agent.mat);
}
}
void DrawPropertyData(ref MaterialPropertyAgent.PropertyData data, string dataLabel, SerializedProperty property)
{
EditorGUI.BeginProperty(EditorGUILayout.GetControlRect(false, 0f), GUIContent.none, property);
if (data.isActive)
{
EditorGUILayout.LabelField(dataLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
float originLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropNameArr);
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropDescripArr);
// string dataDesript = data.descripName;
if (GUILayout.Button(data.descripName, EditorStyles.popup))
{
int dataIndexInAgent = data.dataIndexInAgent;
StringListSerchProvider provider = ScriptableObject.CreateInstance<StringListSerchProvider>();
provider.Initialize(agent.shaderPropDescripsForSerch, (x) =>
{
if (x != null)
{
AfterShaderPropSerch(dataIndexInAgent,x);
}
});
SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)), provider);
// SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)),
// new StringListSerchProvider(agent.shaderPropDescripsForSerch, (x) =>
// {
// if (x != null)
// {
// AfterShaderPropSerch(dataIndexInAgent,x);
// }
// }));
}
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
EditorGUILayout.EndHorizontal();
EditorGUIUtility.labelWidth = originLabelWidth;
switch (data.type)
{
case MaterialPropertyAgent.shaderPropertyType.Color:
SerializedProperty colorProp = property.FindPropertyRelative("colorValue");
if (data.descripName.ToLower().Contains("hdr"))
{
colorProp.colorValue = EditorGUILayout.ColorField(new GUIContent(data.propName + " :") , colorProp.colorValue,true,true,true);
}
else
{
colorProp.colorValue = EditorGUILayout.ColorField(data.propName + " :", colorProp.colorValue);
}
break;
case MaterialPropertyAgent.shaderPropertyType.Vector:
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
SerializedProperty vecProp = property.FindPropertyRelative("vecValue");
if (data.type == MaterialPropertyAgent.shaderPropertyType.Vector)
{
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + " :", vecProp.vector4Value);
}
else if (data.type == MaterialPropertyAgent.shaderPropertyType.TexEnv)
{
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + ":", vecProp.vector4Value);
}
break;
case MaterialPropertyAgent.shaderPropertyType.Float:
case MaterialPropertyAgent.shaderPropertyType.Range:
SerializedProperty floatProp = property.FindPropertyRelative("floatValue");
if (data.type == MaterialPropertyAgent.shaderPropertyType.Float)
{
floatProp.floatValue = EditorGUILayout.FloatField(data.propName + ":", floatProp.floatValue);
}
else if (data.type == MaterialPropertyAgent.shaderPropertyType.Range)
{
floatProp.floatValue = EditorGUILayout.Slider(data.propName + ":", floatProp.floatValue, data.rangMin, data.rangMax);
}
break;
}
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
{
data.isActive = false;
}
EditorGUI.indentLevel--;
// EditorGUILayout.Space();
}
EditorGUI.EndProperty();
}
//因为Action不能有Ref。所以有了这个丑陋的HardCode
public void AfterShaderPropSerch(int dataIndexInAgent, string propertyDesrpt)
{
switch (dataIndexInAgent)
{
case 0:
AfterShaderPropSerch(ref agent.data0,propertyDesrpt);
break;
case 1:
AfterShaderPropSerch(ref agent.data1,propertyDesrpt);
break;
case 2:
AfterShaderPropSerch(ref agent.data2,propertyDesrpt);
break;
case 3:
AfterShaderPropSerch(ref agent.data3,propertyDesrpt);
break;
case 4:
AfterShaderPropSerch(ref agent.data4,propertyDesrpt);
break;
case 5:
AfterShaderPropSerch(ref agent.data5,propertyDesrpt);
break;
}
}
public void AfterShaderPropSerch(ref MaterialPropertyAgent.PropertyData data, string propertyDesrpt)
{
int preservedIndex = data.index;
// string propname = data.propName;
data.index = Array.FindIndex(agent.shaderPropDescripArr, x=> x.Equals(propertyDesrpt) );
// Debug.Log();
if (preservedIndex != data.index)//证明用户进行了更改
{
if (!agent.isCanUsedIndex(data.index))
{
//TODO给一个报错提示
Debug.LogError("材质属性已经存在:" + ShaderUtil.GetPropertyDescription(agent.shader, data.index));
data.index = agent.getCanUsedIndex();
}
//此处进行内容刷新
data.setValueByPropChange();
}
}
private MaterialEditor matEditor;
void DrawMaterialInspector(MaterialEditor editor,Material mat)
{
if (editor != null && mat != null)
{
// Draw the material's foldout and the material shader field
// Required to call _materialEditor.OnInspectorGUI ();
editor.DrawHeader();
// We need to prevent the user to edit Unity default materials
bool isDefaultMaterial = !AssetDatabase.GetAssetPath (mat).StartsWith ("Assets");
using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) {
// Draw the material properties
// Works only if the foldout of _materialEditor.DrawHeader () is open
editor.OnInspectorGUI ();
}
}
}
}
// #endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9544bec10c84ecca289bece4a630d65
timeCreated: 1702126025

View File

@@ -0,0 +1,732 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.AnimatedValues;
// using UnityEditor.Rendering.Universal.ShaderGUI;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor
{
public class ShaderGUIHelper
{
public class ShaderPropertyPack
{
public MaterialProperty property;
public string name;
}
private List<Material> mats;
private MaterialEditor matEditor;
public List<ShaderPropertyPack> ShaderPropertyPacks = new List<ShaderPropertyPack>();
public ShaderFlagsBase[] shaderFlags = null;
public void Init(MaterialEditor materialEditor, MaterialProperty[] properties,
ShaderFlagsBase[] shaderFlags_in = null, List<Material> mats_in = null)
{
shaderFlags = shaderFlags_in;
ShaderPropertyPacks.Clear();
mats = mats_in;
Shader shader = mats[0].shader;
matEditor = materialEditor;
for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
{
ShaderPropertyPack pack = new ShaderPropertyPack();
pack.name = ShaderUtil.GetPropertyName(shader, i);
for (int index = 0; index < properties.Length; ++index)
{
if (properties[index] != null && properties[index].name == pack.name)
{
pack.property = properties[index];
break;
}
else
{
if (index == properties.Length - 1)
{
Debug.LogError(pack.name + "找不到Properties");
}
}
}
ShaderPropertyPacks.Add(pack);
}
}
AnimBool trueAnimBool = new AnimBool(true);
public void DrawBigBlock(String label, Action drawBlock)
{
EditorGUILayout.Space();
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;
EditorGUILayout.LabelField(label);
EditorStyles.label.fontStyle = origFontStyle;
drawBlock();
GuiLine();
}
public void DrawBigBlockFoldOut(ref AnimBool foldOutAnimBool, String label, Action drawBlock)
{
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
// EditorGUI.DrawRect(foldoutRect,Color.red);
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
// EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
FontStyle origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;
EditorGUI.LabelField(labelRect, label);
EditorStyles.label.fontStyle = origFontStyle;
EditorGUILayout.EndHorizontal();
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f;
EditorGUILayout.BeginFadeGroup(faded);
EditorGUI.indentLevel++;
drawBlock();
EditorGUI.indentLevel--;
EditorGUILayout.EndFadeGroup();
GuiLine();
}
public void DrawBigBlockWithToggle(String label, string propertyName, int flagBitsName = 0, int flagIndex = 0,
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
Action<bool> drawBlock = null)
{
DrawToggle(label, propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, shaderPassName2,
isIndentBlock: true, FontStyle.Bold, drawBlock: drawBlock);
GuiLine();
}
public void DrawToggleFoldOut(ref AnimBool foldOutAnimBool, String label, string propertyName = null,
int flagBitsName = 0,
int flagIndex = 0, string shaderKeyword = null, string shaderPassName = null, bool isIndentBlock = true,
FontStyle fontStyle = FontStyle.Normal,
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
{
if (fontStyle == FontStyle.Bold)
{
EditorGUILayout.Space();
}
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var toggleRect = GetRectAfterLabelWidth(rect);
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
foldoutRect.width = toggleRect.x - foldoutRect.x;
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
bool isToggle = false;
// 必须先画Toggle不然按钮会被FoldOut和Label覆盖。
DrawToggle("", propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, isIndentBlock: false,
fontStyle: FontStyle.Normal, rect: toggleRect, drawBlock:
toggle => { isToggle = toggle; }, drawEndChangeCheck: isEndChangeToggle =>
{
if (drawEndChangeCheck != null)
{
drawEndChangeCheck(isEndChangeToggle);
}
});
// EditorGUI.DrawRect(foldoutRect,Color.red);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = fontStyle;
// EditorGUI.DrawRect(labelRect,Color.blue);
EditorGUI.LabelField(labelRect, label);
EditorStyles.label.fontStyle = origFontStyle;
EditorGUILayout.EndHorizontal();
if (isIndentBlock) EditorGUI.indentLevel++;
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f; //用于欺骗FadeGroup不要让他真的关闭了。这样会藏不住相关的GUI。我们的目的是GUI藏住但是逻辑还是在跑。drawBlock要执行。
EditorGUILayout.BeginFadeGroup(faded);
{
EditorGUI.BeginDisabledGroup(!isToggle);
drawBlock?.Invoke(isToggle);
EditorGUI.EndDisabledGroup();
}
EditorGUILayout.EndFadeGroup();
if (isIndentBlock) EditorGUI.indentLevel--;
}
public void DrawToggle(String label, string propertyName = null, int flagBitsName = 0, int flagIndex = 0,
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
bool isIndentBlock = true, FontStyle fontStyle = FontStyle.Normal, Rect rect = new Rect(),
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
{
if (propertyName != null && GetProperty(propertyName) == null)
return;
if (fontStyle == FontStyle.Bold)
{
EditorGUILayout.Space();
}
bool isToggle = false;
if (propertyName != null)
{
isToggle = GetProperty(propertyName).floatValue > 0.5f ? true : false;
}
else if (flagBitsName != 0 && shaderFlags[0] != null)
{
isToggle = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex);
}
else if (shaderKeyword != null)
{
isToggle = mats[0].IsKeywordEnabled(shaderKeyword);
}
else if (shaderPassName != null)
{
isToggle = mats[0].GetShaderPassEnabled(shaderPassName);
}
else if (shaderPassName2 != null)
{
isToggle = mats[0].GetShaderPassEnabled(shaderPassName2);
}
if (propertyName != null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
}
for (int i = 0; i < mats.Count; i++)
{
if (isToggle)
{
if (shaderKeyword != null)
{
mats[i].EnableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, true);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, true);
}
}
else
{
if (shaderKeyword != null)
{
mats[i].DisableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, false);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, false);
}
}
}
EditorGUI.BeginChangeCheck();
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = fontStyle;
if (rect.width > 0) //给FoldOut功能使用。
{
isToggle = EditorGUI.Toggle(rect, isToggle, EditorStyles.toggle);
}
else
{
isToggle = EditorGUILayout.Toggle(label, isToggle);
}
EditorStyles.label.fontStyle = origFontStyle;
if (EditorGUI.EndChangeCheck())
{
for (int i = 0; i < mats.Count; i++)
{
if (isToggle)
{
if (propertyName != null)
{
GetProperty(propertyName).floatValue = 1;
}
if (flagBitsName != 0 && shaderFlags[i] != null)
{
shaderFlags[i].SetFlagBits(flagBitsName, index: flagIndex);
}
if (shaderKeyword != null)
{
mats[i].EnableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, true);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, true);
}
}
else
{
if (propertyName != null)
{
GetProperty(propertyName).floatValue = 0;
}
if (flagBitsName != 0 && shaderFlags[i] != null)
{
shaderFlags[i].ClearFlagBits(flagBitsName, index: flagIndex);
}
if (shaderKeyword != null)
{
mats[i].DisableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, false);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, false);
}
}
}
drawEndChangeCheck?.Invoke(isToggle);
}
if (isIndentBlock) EditorGUI.indentLevel++;
drawBlock?.Invoke(isToggle);
if (isIndentBlock) EditorGUI.indentLevel--;
EditorGUI.showMixedValue = false;
}
public void DrawSlider(string label, string propertyName, float minValue, float maxValue,
Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
float f = GetProperty(propertyName).floatValue;
EditorGUI.BeginChangeCheck();
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).floatValue = f;
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawFloat(string label, string propertyName, bool isReciprocal = false,
Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
float f = GetProperty(propertyName).floatValue;
if (isReciprocal) f = 1 / f;
EditorGUI.BeginChangeCheck();
f = EditorGUILayout.FloatField(label, f);
if (isReciprocal) f = 1 / f;
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).floatValue = f;
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawVector4In2Line(string propertyName, string firstLineLabel = null, string secondLineLabel = null,
Action drawBlock = null)
{
MaterialProperty property = GetProperty(propertyName);
EditorGUI.showMixedValue = property.hasMixedValue;
Vector2 xy = new Vector2(property.vectorValue.x, property.vectorValue.y);
Vector2 zw = new Vector2(property.vectorValue.z, property.vectorValue.w);
EditorGUI.BeginChangeCheck();
if (firstLineLabel != null)
{
xy = EditorGUILayout.Vector2Field(firstLineLabel, xy);
}
if (secondLineLabel != null)
{
zw = EditorGUILayout.Vector2Field(secondLineLabel, zw);
}
if (EditorGUI.EndChangeCheck())
{
property.vectorValue = new Vector4(xy.x, xy.y, zw.x, zw.y);
}
drawBlock?.Invoke();
EditorGUI.showMixedValue = false;
}
float GetCompInVec4(Vector4 vec, string comp)
{
float f = 0;
switch (comp)
{
case "x":
f = vec.x;
break;
case "y":
f = vec.y;
break;
case "z":
f = vec.z;
break;
case "w":
f = vec.w;
break;
}
return f;
}
Vector4 SetCompInVec4(Vector4 vec, string comp, float value)
{
switch (comp)
{
case "x":
vec.x = value;
break;
case "y":
vec.y = value;
break;
case "z":
vec.z = value;
break;
case "w":
vec.w = value;
break;
}
return vec;
}
public void DrawVector4MinMaxSlider(string propertyName, string Lable, string minChannel, string maxChanel,
float minValue = 0f, float maxValue = 1f, Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 vec = GetProperty(propertyName).vectorValue;
float minChannelVal = GetCompInVec4(vec, minChannel);
float maxChanelVal = GetCompInVec4(vec, maxChanel);
EditorGUI.BeginChangeCheck();
using (EditorGUILayout.HorizontalScope scope = new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PrefixLabel(Lable);
minChannelVal =
EditorGUILayout.FloatField(minChannelVal, new GUILayoutOption[] { GUILayout.Width(80) });
EditorGUILayout.MinMaxSlider(ref minChannelVal, ref maxChanelVal, minValue, maxValue);
maxChanelVal = EditorGUILayout.FloatField(maxChanelVal, new GUILayoutOption[] { GUILayout.Width(80) });
}
if (EditorGUI.EndChangeCheck())
{
vec = SetCompInVec4(vec, minChannel, minChannelVal);
vec = SetCompInVec4(vec, maxChanel, maxChanelVal);
GetProperty(propertyName).vectorValue = vec;
}
EditorGUI.showMixedValue = false;
}
public void DrawVector4Componet(string label, string propertyName, string channel, bool isSlider,
float minValue = 0, float maxValue = 1, float powerSlider = 1, float multiplier = 1,
bool isReciprocal = false, Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 vec = GetProperty(propertyName).vectorValue;
float f = GetCompInVec4(vec, channel);
f *= multiplier;
if (isReciprocal) f = 1 / f;
EditorGUI.BeginChangeCheck();
if (isSlider)
{
if (powerSlider > 1)
{
f = PowerSlider(EditorGUILayout.GetControlRect(new GUILayoutOption[] { GUILayout.Height(18) }),
new GUIContent(label), f, minValue, maxValue, powerSlider);
}
else
{
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
}
}
else
{
f = EditorGUILayout.FloatField(label, f);
}
if (isReciprocal) f = 1 / f;
f /= multiplier;
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).vectorValue = SetCompInVec4(vec, channel, f);
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawVector4XYZComponet(string label, string propertyName, Action<Vector3> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 originVec = GetProperty(propertyName).vectorValue;
Vector3 vec = originVec;
EditorGUI.BeginChangeCheck();
vec = EditorGUILayout.Vector3Field(label, vec);
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).vectorValue = new Vector4(vec.x, vec.y, vec.z, originVec.w);
}
drawBlock?.Invoke(vec);
EditorGUI.showMixedValue = false;
}
public enum SamplerWarpMode
{
Repeat,
Clamp,
RepeatX_ClampY,
ClampX_RepeatY
}
public Rect GetRectAfterLabelWidth(Rect rect, bool ignoreIndent = false)
{
Rect rectAfterLabelWidth = MaterialEditor.GetRectAfterLabelWidth(rect); //右边缘是准的。
Rect leftAlignedFieldRect = MaterialEditor.GetLeftAlignedFieldRect(rect); //左边缘是准的实际有2f空隙。
float x = leftAlignedFieldRect.x + 2f;
float width = rectAfterLabelWidth.x + rectAfterLabelWidth.width - x;
var newRec = new Rect(x, rectAfterLabelWidth.y, width, rectAfterLabelWidth.height);
if (ignoreIndent)
{
float indent = (float)EditorGUI.indentLevel * 15f;
newRec.x -= indent;
newRec.width += indent;
}
// // EditorGUI.DrawRect(leftRect,Color.red);
// float biasWidth = EditorGUI.indentLevel * 15f - 2f;
// leftRect.x -= biasWidth;
// leftRect.width += biasWidth;
// EditorGUI.DrawRect(leftRect,Color.green);
return newRec;
}
public void DrawTextureFoldOut(ref AnimBool foldOutAnimBool, string label, string texturePropertyName,
string colorPropertyName = null, bool drawScaleOffset = true, bool drawWrapMode = false,
int flagBitsName = 0, int flagIndex = 2, Action<Texture> drawBlock = null)
{
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var foldoutRect = new Rect(rect.x, rect.y, rect.width - MaterialEditor.GetRectAfterLabelWidth(rect).width,
rect.height);
var textureThumbnialRect = new Rect(rect.x + 2f, rect.y, 14f, rect.height);
var labelRect = new Rect(rect.x + 35f, rect.y, rect.width - 18f, rect.height);
Texture texture =
matEditor.TexturePropertyMiniThumbnail(textureThumbnialRect, GetProperty(texturePropertyName), "", "");
EditorGUI.LabelField(labelRect, label);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
if (colorPropertyName != null)
{
Rect colorPropRect = GetRectAfterLabelWidth(rect, true);
// colorPropRect.x -= EditorGUI.indentLevel
Color color = matEditor.ColorProperty(colorPropRect, GetProperty(colorPropertyName), "");
}
EditorGUILayout.EndHorizontal();
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f;
EditorGUILayout.BeginFadeGroup(faded);
EditorGUI.BeginDisabledGroup(texture == null);
DrawAfterTexture(true, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName, flagIndex,
drawBlock);
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndFadeGroup();
}
public void DrawTexture(string label, string texturePropertyName, string colorPropertyName = null,
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
Action<Texture> drawBlock = null)
{
bool hasTexture = mats[0].GetTexture(texturePropertyName) != null;
matEditor.TexturePropertySingleLine(new GUIContent(label), GetProperty(texturePropertyName),
GetProperty(colorPropertyName));
DrawAfterTexture(hasTexture, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName,
flagIndex, drawBlock);
}
public void DrawAfterTexture(bool hasTexture, string label, string texturePropertyName,
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
Action<Texture> drawBlock = null)
{
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(!hasTexture);
if (drawWrapMode)
{
//这个多选材质就不出现了,不好处理
if (mats.Count == 1)
{
int tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex) ? 1 : 0;
tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName << 16, index: flagIndex)
? tmpWrapMode + 2
: tmpWrapMode;
tmpWrapMode = EditorGUILayout.Popup(new GUIContent(label + "循环模式"), tmpWrapMode,
Enum.GetNames(typeof(SamplerWarpMode)));
switch (tmpWrapMode)
{
case 0:
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 1:
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 2:
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 3:
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
break;
}
}
}
if (drawScaleOffset)
{
matEditor.TextureScaleOffsetProperty(GetProperty(texturePropertyName));
}
drawBlock?.Invoke(GetProperty(texturePropertyName).textureValue);
EditorGUI.indentLevel--;
EditorGUI.EndDisabledGroup();
}
public void DrawPopUp(string label, string propertyName, string[] options, string[] toolTips = null,
Action<float> drawBlock = null)
{
MaterialProperty property = GetProperty(propertyName);
if (property == null) return;
EditorGUI.showMixedValue = property.hasMixedValue;
float mode = property.floatValue;
EditorGUI.BeginChangeCheck();
GUIContent[] optionGUIContents = new GUIContent[options.Length];
for (int i = 0; i < optionGUIContents.Length; i++)
{
if (toolTips != null && toolTips.Length == options.Length)
{
optionGUIContents[i] = new GUIContent(options[i], toolTips[i]);
}
else
{
optionGUIContents[i] = new GUIContent(options[i]);
}
}
mode = EditorGUILayout.Popup(new GUIContent(label), (int)mode, optionGUIContents);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = mode;
}
drawBlock?.Invoke(mode);
EditorGUI.showMixedValue = false;
}
public MaterialProperty GetProperty(string propertyName)
{
foreach (ShaderPropertyPack pack in ShaderPropertyPacks)
{
if (pack.name == propertyName)
{
return pack.property;
}
}
// Debug.LogError("材质球" + mat.name + "找不到属性" + propertyName, mat);
return null;
}
public void DrawRenderQueue(MaterialProperty queueBiasProp)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Queue" + mats[0].renderQueue);
int QueueBias = (int)queueBiasProp.floatValue;
QueueBias = EditorGUILayout.IntField("QueueBias:", QueueBias);
queueBiasProp.floatValue = QueueBias;
EditorGUILayout.EndHorizontal();
}
void GuiLine(int i_height = 1)
{
Rect rect = EditorGUILayout.GetControlRect(false, i_height);
rect.height = i_height;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.5f));
}
public static float PowerSlider(Rect position, GUIContent label, float value, float leftValue, float rightValue,
float power)
{
var editorGuiType = typeof(EditorGUI);
var methodInfo = editorGuiType.GetMethod(
"PowerSlider",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static,
null,
new[] { typeof(Rect), typeof(GUIContent), typeof(float), typeof(float), typeof(float), typeof(float) },
null);
if (methodInfo != null)
{
return (float)methodInfo.Invoke(null,
new object[] { position, label, value, leftValue, rightValue, power });
}
return leftValue;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9279ba81938dc1548b9e9d8297bdcd57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
// using Sirenix.OdinInspector;
// using Sirenix.OdinInspector.Editor;
using UnityEditor;
namespace stencilTestHelper
{
[Serializable]
public class StencilValues
{
public int DefaultQueue = 2000;
[BinaryInt(8,true,2)]
public int Ref = 0;
public CompareFunction Comp = CompareFunction.Always;
public StencilOp Pass = StencilOp.Keep;
public StencilOp Fail = StencilOp.Keep;
public StencilOp ZFail = StencilOp.Keep;
[BinaryInt(8,true,1)]
public int ReadMask = 255;
[BinaryInt(8,true,1)]
public int WriteMask = 255;
}
public static class StencilTestHelper
{
// private static StencilValuesConfig stencilValuesConfig;
public class StencilPropertyNames
{
public string stencil = "_Stencil";
public string stencilComp = "_StencilComp";
public string stencilOp = "_StencilOp";
public string stencilWriteMask = "_StencilWriteMask";
public string stencilReadMask = "_StencilReadMask";
public string stencilZFail = "_StencilZFail";
public string stencilFail = "_StencilFail";
public StencilPropertyNames()
{
}
public StencilPropertyNames(string stencilName, string stencilCompName, string stencilOpName,
string stencilWriteMaskName, string stencilReadMaskName, string stencilZFailName,
string stencilFailName)
{
if (!string.IsNullOrEmpty(stencilName))
{
stencil = stencilName;
}
if (!string.IsNullOrEmpty(stencilCompName))
{
stencilComp = stencilCompName;
}
if (!string.IsNullOrEmpty(stencilOpName))
{
stencilOp = stencilOpName;
}
if (!string.IsNullOrEmpty(stencilWriteMaskName))
{
stencilWriteMask = stencilWriteMaskName;
}
if (!string.IsNullOrEmpty(stencilReadMaskName))
{
stencilReadMask = stencilReadMaskName;
}
if (!string.IsNullOrEmpty(stencilZFailName))
{
stencilZFail = stencilZFailName;
}
if (!string.IsNullOrEmpty(stencilFailName))
{
stencilFail = stencilFailName;
}
}
}
private static StencilPropertyNames defaultStencilPropertyNames = new StencilPropertyNames();
// public static void SetMaterialStencil(Material mat,StencilValues stencilValues,out int defaultQueue)
public static void SetMaterialStencil(Material mat, string stencilConfigKey,StencilValuesConfig stencilValuesConfig, out int defaultQueue,StencilPropertyNames stencilPropertyNames = null)
{
if (stencilValuesConfig == null)
{
Debug.LogError(mat.name+": 缺少模板预设,设置Stencil失败");
// stencilValuesConfig =
// AssetDatabase.LoadAssetAtPath<StencilValuesConfig>(
// "Assets/AddressableAssets/Shader/StencilConfig.asset");
}
if (stencilPropertyNames == null)
{
stencilPropertyNames = defaultStencilPropertyNames;
}
StencilValues stencilValues;
if (stencilValuesConfig.ContainsKey(stencilConfigKey))
{
stencilValues = stencilValuesConfig[stencilConfigKey];
if (!string.IsNullOrEmpty(stencilPropertyNames.stencil))
{
mat.SetFloat(stencilPropertyNames.stencil, stencilValues.Ref);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilComp) )
{
mat.SetFloat(stencilPropertyNames.stencilComp, (float)stencilValues.Comp);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilOp))
{
mat.SetFloat(stencilPropertyNames.stencilOp, (float)stencilValues.Pass);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilWriteMask))
{
mat.SetFloat(stencilPropertyNames.stencilWriteMask, stencilValues.WriteMask);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilReadMask))
{
mat.SetFloat(stencilPropertyNames.stencilReadMask, stencilValues.ReadMask);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilZFail))
{
mat.SetFloat(stencilPropertyNames.stencilZFail, (float)stencilValues.ZFail);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilFail))
{
mat.SetFloat(stencilPropertyNames.stencilFail, (float)stencilValues.Fail);
}
defaultQueue = stencilValues.DefaultQueue;
}
else
{
Debug.LogError("无法设置材质模板参数,因为没有配置模板值", mat);
defaultQueue = mat.renderQueue;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7d6268a1ca7d824d8da2adf4cb8f74a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace stencilTestHelper
{
public class StencilValuesConfig : ScriptableObject
{
// public Dictionary<string, StencilValues> Config = new Dictionary<string, StencilValues>();
// public StencilValuesConfigDictionary Config = new StencilValuesConfigDictionary();
[Serializable]
public class KeyStencilValues
{
public string key;
public StencilValues Values;
}
[SerializeField]
public List<KeyStencilValues> Config = new List<KeyStencilValues>();
public bool ContainsKey(string key)
{
if (GetStencilValues(key) != null)
{
return true;
}
else
{
return false;
}
}
public StencilValues GetStencilValues(string key)
{
foreach (var item in Config)
{
if (item.key == key)
{
return item.Values;
}
}
Debug.LogError("StencilValuesConfig: 不存在Key"+key);
return null;
}
public StencilValues this[string key]
{
get
{
return GetStencilValues(key);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9177edf81a5b2354490ec4d66c4c069d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,101 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEditor;
public class StringListSerchProvider : ScriptableObject , ISearchWindowProvider
// public class StringListSerchProvider
{
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
{
List<SearchTreeEntry> serchList = new List<SearchTreeEntry>();
serchList.Add(new SearchTreeGroupEntry(new GUIContent("List"),0));
List<string> listItemAfterSort = listItems.ToList();
sortListItems(ref listItemAfterSort);
List<string> groups = new List<string>();
foreach (var item in listItemAfterSort)
{
string[] entryTitle = item.Split("/");
string groupName = "";
for (int i = 0; i < entryTitle.Length - 1; i++)
{
groupName += entryTitle[i];
if (!groups.Contains(groupName))
{
serchList.Add(new SearchTreeGroupEntry(new GUIContent(entryTitle[i]),i+1));
}
groupName += "/";
}
SearchTreeEntry entry = new SearchTreeEntry(new GUIContent(entryTitle.Last()));
entry.level = entryTitle.Length;
entry.userData = item;//这里是serch操作点击最后的返回值是什么都可以的。
// Debug.Log(entry.userData);
serchList.Add(entry);
}
return serchList;
}
public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
{
string data = (string)searchTreeEntry.userData;
onSetIndexCallback?.Invoke(data);
return true;
}
private string[] listItems;
private Action<string> onSetIndexCallback;
public StringListSerchProvider(string[] items, Action<string> callBack)
{
listItems = items;
onSetIndexCallback = callBack;
}
public void Initialize(string[] items, Action<string> callBack)
{
listItems = items;
onSetIndexCallback = callBack;
}
// private List<string> sortListItems;
void sortListItems(ref List<string> list)
{
// sortListItems = listItems.ToList();
list.Sort((a, b) =>
{
string[] splits1 = a.Split('/');
string[] splits2 = b.Split('/');
for (int i = 0; i < splits1.Length; i++)
{
if (i >= splits2.Length)
{
return 1;
}
int value = splits1[i].CompareTo(splits2[i]);
if (value != 0)
{
if (splits1.Length != splits2.Length && (i == splits1.Length - 1 || i == splits2.Length - 1))
{
return splits1.Length < splits2.Length ? 1 : -1;
}
return value;
}
}
return 0;
});
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aec459410f5254c4bb4d42e7ec8b4b5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
{
"name": "com.xuanxuan.render.utility.Editor",
"rootNamespace": "",
"references": [
"GUID:8f9e4d586616f13449cfeb86c5f704c2",
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8495541fcd41b0c40b5b6e6e7a7639d1
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
public class RefreshMaterialInspectorWindow : EditorWindow
{
[MenuItem("ArtTools/刷新选中材质球面板")]
static void refershSelectMaterialInspector()
{
EditorWindow.GetWindow<RefreshMaterialInspectorWindow>("材质球刷新");
}
public static bool isRefreshing = false;
List<Material> materials = new List<Material>();
int i = 0;
private void OnGUI()
{
if (GUILayout.Button("开始刷新材质面板"))
{
materials.Clear();
foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
{
string path = AssetDatabase.GetAssetPath(o);
string fileExtension = Path.GetExtension(path);
if (fileExtension == ".mat")
{
materials.Add((Material)o);
}
}
i = 0;
}
}
private void OnEnable()
{
Debug.Log("刷新材质打开");
isRefreshing = true;
}
private void Update()
{
if(materials.Count <= 0) return;
if (i < materials.Count)
{
// isRefreshing = true;
// SetNormalToUV1(materials[i]);
Selection.activeObject = materials[i];
Debug.Log(materials[i].name,materials[i]);
EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Count}", (i + 1) / (float)materials.Count);
i++;
// isRefreshing = false;
}
if (i >= materials.Count)
{
EditorUtility.ClearProgressBar();
materials.Clear();
Debug.Log("材质刷新结束isRefreshing布尔值 = "+isRefreshing);
}
}
void OnDisable()
{
Debug.Log("刷新材质关闭");
isRefreshing = false;
}
// void SetNormalToUV1(Material mat)
// {
// if (mat.HasProperty("_NormalFrom"))
// {
// mat.SetInteger("_NormalFrom",1);
// }
// }
//
// // [MenuItem("Assets/测试刷新材质", priority = 1)]
// public static void TestRefeshMaterial()
// {
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags();
// int id = Shader.PropertyToID("_Mask2_Toggle");
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
// {
// Material mat = o as Material;
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// bool isToggle = mat.GetFloat(id) > 0.5f;
// if (isToggle)
// {
// mat.DisableKeyword("_MASKMAP2");
// flags.SetMaterial(mat);
// flags.SetFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_MASK_MAP2,index:1);
// }
// // flags.SetMaterial(mat);
// }
// }
// AssetDatabase.SaveAssets();
// }
//
// [MenuItem("Assets/Effect Tool/刷新选中文件夹内材质Wrap模式", priority = 1)]
// public static void SetSelectParticleMaterialWrapMode()
// {
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
// {
// Material mat = (Material)o;
// // Debug.Log(mat.shader.name);
// SetParticleMaterialWrapMode((Material)o);
// }
// AssetDatabase.SaveAssets();
// }
//
// public static void SetParticleMaterialWrapMode(Material mat)
// {
//
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags(mat);
// SetWrapModeFlag(flags,mat,"_BaseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_BASEMAP);
// SetWrapModeFlag(flags,mat,"_MaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP);
// SetWrapModeFlag(flags,mat,"_MaskMap2",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP2);
// SetWrapModeFlag(flags,mat,"_NoiseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_NOISEMAP);
// SetWrapModeFlag(flags,mat,"_EmissionMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_EMISSIONMAP);
// SetWrapModeFlag(flags,mat,"_DissolveMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MAP);
// SetWrapModeFlag(flags,mat,"_DissolveMaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP);
// SetWrapModeFlag(flags,mat,"_DissolveRampMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP);
// SetWrapModeFlag(flags,mat,"_ColorBlendMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_COLORBLENDMAP);
// SetWrapModeFlag(flags,mat,"_VertexOffset_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP);
// SetWrapModeFlag(flags,mat,"_ParallaxMapping_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP);
// }
// }
//
// public static void SetParticleMaterialMaskStrenth(Material mat)
// {
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// Vector4 vec = mat.GetVector("_MaskMap3OffsetAnition");
// if (vec.z < 1)
// {
// Vector4 newVec = new Vector4(vec.x, vec.y, 1, vec.w);
// mat.SetVector("_MaskMap3OffsetAnition",newVec);
// }
// }
// }
//
// static void SetWrapModeFlag(W9ParticleShaderFlags flags, Material mat, string matTexPropertyName, int flagBit)
// {
// if (mat.GetTexture(matTexPropertyName) != null)
// {
// Texture tex = mat.GetTexture(matTexPropertyName);
// Debug.Log(tex.name);
// if (tex.wrapMode == TextureWrapMode.Clamp)
// {
// Debug.Log("This is Clamp");
// flags.SetFlagBits(flagBit,index:2);
// }
// else if (tex.wrapMode == TextureWrapMode.Repeat)
// {
// Debug.Log("This is Repeat");
// flags.ClearFlagBits(flagBit,index:2);
// }
// }
// }
// static IEnumerator refreshMaterialInspector(Material[] materials)
// {
// for (int i = 0; i < materials.Length; i++)
// {
// EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Length}", (i + 1) / (float)materials.Length);
// Debug.Log(i);
// // Selection.activeObject = materials[i];
// yield return null;
// }
// EditorUtility.ClearProgressBar();
// // yield break;
// }
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 317bb692129be184ebd7249bba265210
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 72e9a7523c1a5994c8fb317e7a9514e0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
using System.Reflection;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class InspectorButtonAttribute:PropertyAttribute
{
public string Label;
public string MethodName;
public InspectorButtonAttribute(string label,string methodName)
{
this.Label = label;
this.MethodName = methodName;
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(InspectorButtonAttribute))]
public class InspectorButtonPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
InspectorButtonAttribute buttonAttribute = (InspectorButtonAttribute)attribute;
// 绘制按钮
if (GUI.Button(position, buttonAttribute.Label))
{
// 获取包含该方法的对象
var targetObject = property.serializedObject.targetObject;
// 获取方法信息
var methodInfo = targetObject.GetType().GetMethod(buttonAttribute.MethodName,BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo != null)
{
// 调用方法
methodInfo.Invoke(targetObject, null);
}
else
{
Debug.LogError($"Method '{buttonAttribute.MethodName}' not found in {targetObject.name}.");
}
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight; // 返回按钮的高度
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 45f557806bb54c4dbeaec7a2ded5be83
timeCreated: 1737792133

View File

@@ -0,0 +1,562 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//TODO增加一键去重功能。测试排查BUG
[ExecuteInEditMode]
public class MaterialPropertyAgent : MonoBehaviour,IMaterialModifier
{
[System.Serializable]
public struct PropertyData
{
[HideInInspector] public int dataIndexInAgent;
[HideInInspector] public MaterialPropertyAgent agent;
[HideInInspector] public int id;
public int index;
[HideInInspector] public string propName;
public shaderPropertyType type;
public string descripName;
public Color colorValue;
public Vector4 vecValue;
public float floatValue;
[SerializeField] public IEnumerable propNameList;
[HideInInspector] public bool isActive;
[HideInInspector] public Shader shader;
[HideInInspector] public Material mat;
#if UNITY_EDITOR
public float rangMin { get; set; }
public float rangMax { get; set; }
public void setValueByPropChange()
{
agent.refreshShderPropNameList();
if (!agent.isCanUsedIndex(index))
{
index = agent.getCanUsedIndex();
}
string propertyName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
id = Shader.PropertyToID(propertyName);
descripName = UnityEditor.ShaderUtil.GetPropertyDescription(shader, index);
type = (shaderPropertyType) UnityEditor.ShaderUtil.GetPropertyType(shader, index);
if (type == shaderPropertyType.TexEnv)
{
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
}
else
{
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
}
switch (type)
{
case shaderPropertyType.Color:
colorValue = mat.GetColor(id);
break;
case shaderPropertyType.Float:
floatValue = mat.GetFloat(id);
break;
case shaderPropertyType.Range:
rangMin = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 1);
rangMax = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 2);
floatValue = mat.GetFloat(id);
break;
case shaderPropertyType.Vector:
vecValue = mat.GetVector(id);
break;
case shaderPropertyType.TexEnv:
string stName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
vecValue = mat.GetVector(stName);
break;
}
}
public void inActivateThis()
{
isActive = false;
}
#endif
}
//因为ShaderUtil只是用于Editor所以复制一个枚举对属性类型进行识别。
public enum shaderPropertyType
{
//
// 摘要:
// Color Property.
Color = 0,
//
// 摘要:
// Vector Property.
Vector = 1,
//
// 摘要:
// Float Property.
Float = 2,
//
// 摘要:
// Range Property.
Range = 3,
//
// 摘要:
// Texture Property.
TexEnv = 4
}
public PropertyData data0 = new PropertyData();
public PropertyData data1 = new PropertyData();
public PropertyData data2 = new PropertyData();
public PropertyData data3 = new PropertyData();
public PropertyData data4 = new PropertyData();
public PropertyData data5 = new PropertyData();
public Shader shader;
public Material mat;
public int materialIndex = 0;
public Renderer customRenderer;
void initMatAndShader(bool initMat = false)
{
if (!initMat)
{
if (mat != null) return;
}
if (customRenderer || GetComponent<Renderer>())
{
Material[] materials;
Renderer r;
if (customRenderer)
{
r = customRenderer;
}
else
{
r = GetComponent<Renderer>();
}
if (Application.isPlaying)
{
materials = r.materials;
}
else
{
materials = r.sharedMaterials;
}
mat = materials[materialIndex];
shader = mat.shader;
}
else if (this.GetComponent<Graphic>())
{
Graphic graphic = this.GetComponent<Graphic>();
//测试要不要用IMaterialModifier来处理
// if (Application.isPlaying)
// {
// graphic.material = Material.Instantiate(graphic.material);
// }
mat = graphic.material;
shader = mat.shader;
}
else
{
Debug.LogError("MaterialPropertyAgent未找到材质", this.gameObject);
}
}
private void Start()
{
if (Application.isPlaying)
{
initMatAndShader(true);
}
else
{
initMatAndShader(false);
}
}
private void Update()
{
if (mat == null)
{
// initMatAndShader();
return;
}
updateData(data0);
updateData(data1);
updateData(data2);
updateData(data3);
updateData(data4);
updateData(data5);
}
void updateData(PropertyData data)
{
if (!data.isActive) return;
if (mat == null) return;
switch (data.type)
{
case shaderPropertyType.Color:
mat.SetColor(data.propName, data.colorValue);
break;
case shaderPropertyType.Vector:
case shaderPropertyType.TexEnv:
mat.SetVector(data.propName, data.vecValue);
break;
case shaderPropertyType.Float:
case shaderPropertyType.Range:
mat.SetFloat(data.propName, data.floatValue);
break;
}
}
//实际上是修改了graphic.materialForRendering
public Material GetModifiedMaterial(Material baseMaterial)
{
if (mat)
{
return mat;
}
else
{
return baseMaterial;
}
}
#if UNITY_EDITOR
private void OnRenderObject()
{
if (!UnityEditor.EditorApplication.isPlaying)
{
Update();
}
}
public void addProperteData()
{
refreshShderPropNameList();
if (!data0.isActive)
{
initData(ref data0, 0);
}
else if (!data1.isActive)
{
initData(ref data1, 1);
}
else if (!data2.isActive)
{
initData(ref data2, 2);
}
else if (!data3.isActive)
{
initData(ref data3, 3);
}
else if (!data4.isActive)
{
initData(ref data4, 4);
}
else if (!data5.isActive)
{
initData(ref data5, 5);
}
else
{
Debug.Log("已用掉可用的6个属性");
}
}
public void removeAllProperty()
{
data0.isActive = false;
data1.isActive = false;
data2.isActive = false;
data3.isActive = false;
data4.isActive = false;
data5.isActive = false;
}
public void initData(ref PropertyData data, int dataIndexInAgent)
{
data.dataIndexInAgent = dataIndexInAgent;
data.agent = this;
data.shader = shader;
data.mat = mat;
data.isActive = true;
data.index = getCanUsedIndex();
data.setValueByPropChange();
}
#region TODO自动排除已用Property
List<string> usedPropertyName = new List<string>();
void collectUsedPropName()
{
usedPropertyName.Clear();
if (data0.isActive)
{
usedPropertyName.Add(data0.propName);
}
if (data1.isActive)
{
usedPropertyName.Add(data1.propName);
}
if (data2.isActive)
{
usedPropertyName.Add(data2.propName);
}
if (data3.isActive)
{
usedPropertyName.Add(data3.propName);
}
if (data4.isActive)
{
usedPropertyName.Add(data4.propName);
}
if (data5.isActive)
{
usedPropertyName.Add(data5.propName);
}
}
public int getCanUsedIndex()
{
int index = -1;
collectUsedPropName();
for (int i = 0; i < shaderPropNameArr.Length; i++)
{
string propertyName;
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
{
propertyName = shaderPropNameArr[i] + "_ST";
}
else
{
propertyName = shaderPropNameArr[i];
}
if (usedPropertyName.Contains(propertyName)) continue;
index = i;
break;
}
return index;
}
public bool isCanUsedIndex(int i)
{
string propertyName;
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
{
propertyName = shaderPropNameArr[i] + "_ST";
}
else
{
propertyName = shaderPropNameArr[i];
}
collectUsedPropName();
if (usedPropertyName.Contains(propertyName))
{
return false;
}
else
{
return true;
}
}
#endregion
public string[] shaderPropNameArr;
public string[] shaderPropDescripArr;
public string[] shaderPropDescripsForSerch;
private void OnValidate()
{
// if (XLuaManager.Instance != null)
// {
// if (XLuaManager.Instance.HasGameStart)//判断是游戏运行状态才进行实例化
// {
// return;//游戏进行中不允许编辑
// }
// }
// Debug.Log("MaterialPropertyAgent : " + "OnValidate");
refreshShderPropNameList();
if (TryGetComponent<Renderer>(out Renderer r)||customRenderer)
{
isRendererMode = true;
}
else
{
isRendererMode = false;
}
if (TryGetComponent<Renderer>(out Renderer r2) || TryGetComponent<Graphic>(out Graphic g))
{
isGetByComponet = true;
}
else
{
isGetByComponet = false;
}
}
public bool isRendererMode = false;
public bool isGetByComponet = false;
public void initMatAndShaderByMaterialIndexChange()
{
initMatAndShader(true);
refreshShderPropNameList();
if (data0.isActive && data0.shader != mat.shader) {data0.shader = mat.shader;data0.mat = mat;}
if (data1.isActive && data1.shader != mat.shader) {data1.shader = mat.shader;data1.mat = mat;}
if (data2.isActive && data2.shader != mat.shader) {data2.shader = mat.shader;data2.mat = mat;}
if (data3.isActive && data3.shader != mat.shader) {data3.shader = mat.shader;data3.mat = mat;}
if (data4.isActive && data4.shader != mat.shader) {data4.shader = mat.shader;data4.mat = mat;}
if (data5.isActive && data5.shader != mat.shader) {data5.shader = mat.shader;data5.mat = mat;}
}
List<string> shaderPropNameList = new List<string>();
private List<string> shaderPropDescripList = new List<string>();
private List<string> shaderPropDescripListForSerch = new List<string>();
public void refreshShderPropNameList()
{
initMatAndShader();
if (shader == null) return;
shaderPropNameList.Clear();
shaderPropDescripList.Clear();
shaderPropDescripListForSerch.Clear();
for (int i = 0; i < UnityEditor.ShaderUtil.GetPropertyCount(shader); i++)
{
shaderPropNameList.Add(UnityEditor.ShaderUtil.GetPropertyName(shader, i));
string descript = UnityEditor.ShaderUtil.GetPropertyDescription(shader, i);
shaderPropDescripList.Add(descript);
string lowerDesc = descript.ToLower();
if (!(lowerDesc.Contains("ignore") || lowerDesc.Contains("mode") || lowerDesc.Contains("toggle") ||
lowerDesc.Contains("enable") || lowerDesc.Contains("flag")))
{
shaderPropDescripListForSerch.Add(descript);
}
}
shaderPropNameArr = shaderPropNameList.ToArray();
shaderPropDescripArr = shaderPropDescripList.ToArray();
shaderPropDescripsForSerch = shaderPropDescripListForSerch.ToArray();
}
#endif
}
/*
[CustomPropertyDrawer(typeof(MaterialPropertyAgent.PropertyData))]
public class PropertyAgentPropertyDataDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var isActive = property.FindPropertyRelative("isActive");
if (isActive.boolValue)
{
EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
var index = property.FindPropertyRelative("index");
MaterialPropertyAgent agent = property.FindPropertyRelative("agent").objectReferenceValue as MaterialPropertyAgent;
int preservedIndex = index.intValue;
float originLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
index.intValue = EditorGUILayout.Popup("属性名:", index.intValue, agent.shaderPropNameArr);
if (preservedIndex != index.intValue)//证明用户进行了更改
{
if (!agent.isCanUsedIndex(index.intValue))
{
//TODO给一个报错提示
Debug.Log(ShaderUtil.GetPropertyDescription(agent.shader, index.intValue));
index.intValue = agent.getCanUsedIndex();
}
//此处进行内容刷新
data.setValueByPropChange();
}
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
EditorGUILayout.EndHorizontal();
EditorGUIUtility.labelWidth = originLabelWidth;
switch (data.type)
{
case MaterialPropertyAgent.shaderPropertyType.Color:
data.colorValue = EditorGUILayout.ColorField(data.descripName + " :", data.colorValue);
break;
case MaterialPropertyAgent.shaderPropertyType.Vector:
data.vecValue = EditorGUILayout.Vector4Field(data.descripName + " :", data.vecValue);
break;
case MaterialPropertyAgent.shaderPropertyType.Float:
data.floatValue = EditorGUILayout.FloatField(data.descripName + ":", data.floatValue);
break;
case MaterialPropertyAgent.shaderPropertyType.Range:
data.floatValue = EditorGUILayout.Slider(data.descripName + ":", data.floatValue, data.rangMin, data.rangMax);
break;
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
data.vecValue = EditorGUILayout.Vector4Field(data.propName + "_ST:", data.vecValue);
break;
}
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
{
data.isActive = false;
}
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
}
EditorGUI.EndProperty();
}
}
*/

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 781e80efab11a1d438f7c4d37603bdff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
using System;
using UnityEngine;
public abstract class ShaderFlagsBase
{
private Material _material;
public Material material
{
get
{
return _material;
}
}
protected ShaderFlagsBase(Material material)
{
_material = material;
}
public void SetMaterial(Material material)
{
_material = material;
}
public Material GetMaterial()
{
return _material;
}
protected abstract int GetShaderFlagsId(int index = 0);
protected abstract string GetShaderFlagsName(int index = 0);
private void SetIntValue(Material material, int flagBits,int index = 0)
{
#if UNITY_EDITOR
// SerializedObject serializedObject = new SerializedObject(_material);
// SerializedProperty serializedProperty = serializedObject.FindProperty("m_SavedProperties");
// serializedProperty = serializedProperty.FindPropertyRelative("m_Floats");
// for (int index = serializedProperty.arraySize - 1; index >= 0; index--)
// {
// var property = serializedProperty.GetArrayElementAtIndex(index);
// string propertyName = property.displayName;
// if (propertyName == "_W9PBRStandardShaderFlags")
// {
// var propertyType = property.propertyType;
// Debug.Log("xxx: "+propertyType);
//
//
// property.floatValue = (float) (flags | flagBits);
// }
// }
// material.SetInt(GetShaderFlagsName(), flagBits);
material.SetInteger(GetShaderFlagsId(index), flagBits);
#else
material.SetInteger(GetShaderFlagsId(index), flagBits);
#endif
}
public void SetFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
{
if (propertyBlock is null)
{
if (_material is null) return;
int flags = _material.GetInteger(GetShaderFlagsId(index));
SetIntValue(_material, flags | flagBits,index);
}
else
{
int flags = propertyBlock.GetInt(GetShaderFlagsId(index));
propertyBlock.SetInt(GetShaderFlagsId(index), flags|flagBits);
}
}
public void ClearFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
{
if (propertyBlock is null)
{
if (_material is null) return;
int flags = _material.GetInteger(GetShaderFlagsId(index));
SetIntValue(_material, flags&~flagBits,index);
}
else
{
int flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
propertyBlock.SetInteger(GetShaderFlagsId(index), flags&~flagBits);
}
}
public bool CheckFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
{
int flags = 0;
if (propertyBlock is null)
{
if (_material is null) throw new NullReferenceException("material");
flags = _material.GetInteger(GetShaderFlagsId(index));
}
else
{
flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
}
return (flags & flagBits) != 0;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3bcf591e67bd470e9375d72c63838643
timeCreated: 1655437380

View File

@@ -0,0 +1,16 @@
{
"name": "com.xuanxuan.render.utility",
"rootNamespace": "",
"references": [
"GUID:15fc0a57446b3144c949da3e2b9737a9"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8f9e4d586616f13449cfeb86c5f704c2
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 97647516635f92f43a6cd4807c3899d8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fa89a0fdb680e154f89c18f1a7fea2c6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,351 @@
#ifndef XUANXUAN_UTILITY
#define XUANXUAN_UTILITY
//引入自UnityCG.cginc
#define UNITY_PI 3.14159265359f
#define UNITY_TWO_PI 6.28318530718f
#define UNITY_FOUR_PI 12.56637061436f
#define UNITY_INV_PI 0.31830988618f
#define UNITY_INV_TWO_PI 0.15915494309f
#define UNITY_INV_FOUR_PI 0.07957747155f
#define UNITY_HALF_PI 1.57079632679f
#define UNITY_INV_HALF_PI 0.636619772367f
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
inline half NB_Remap(half x, half inMin, half inMax, half outMin, half outMax)
{
// x= clamp(x,inMin,inMax);
return saturate((x - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;
}
inline half NB_RemapNoClamp(half x, half inMin, half inMax, half outMin, half outMax)
{
// x= clamp(x,inMin,inMax);
return ((x - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;
}
//原生SmoothStep开销很大https://zhuanlan.zhihu.com/p/34629262
//在很多时候可以用简单线性映射代替。
half SimpleSmoothstep(half min,half max,half interp)
{
return saturate((interp - min)/(max-min));
}
half4 TryLinearize(half4 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half4 TryLinearizeWithoutAlpha(half4 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return half4(pow(color.rgb, 2.2f), color.a);
#else
return color;
#endif
}
half3 TryLinearize(half3 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half2 TryLinearize(half2 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half TryLinearize(half color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half4 tex2D_TryLinearizeWithoutAlpha(sampler2D tex, float2 uv)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return TryLinearizeWithoutAlpha(tex2D(tex, uv));
#else
return tex2D(tex, uv);
#endif
}
inline float LinearToGammaSpaceExact (float value)
{
if (value <= 0.0F)
return 0.0F;
else if (value <= 0.0031308F)
return 12.92F * value;
else if (value < 1.0F)
return 1.055F * pow(value, 0.4166667F) - 0.055F;
else
return pow(value, 0.45454545F);
}
// real FastSRGBToLinear(real c)
// {
// return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);
// }
float2 Rotate_Radians_float(float2 UV, float2 Center, float Rotation)
{
if(Rotation == 0)
{
return UV;
}
// Rotation = Rotation / 180 * 3.14; //从角度转为弧度。
Rotation *= 0.01745329222; //从角度转为弧度。
UV -= Center;
float s = sin(Rotation);
float c = cos(Rotation);
float2x2 rMatrix = float2x2(c, -s, s, c);
rMatrix *= 0.5;
rMatrix += 0.5;
rMatrix = rMatrix * 2 - 1;
UV.xy = mul(UV.xy, rMatrix);
UV += Center;
return UV;
}
inline half luminance(half3 color)
{
return dot(color, float3(0.2126f, 0.7152f, 0.0722f));
}
inline half DepthFactor(float Z, float near, float far)
{
Z = saturate((Z-near)/(far - near));
return Z;
}
//抽自Unity.cginc
inline half3 LinearToGammaSpace (half3 linRGB)
{
linRGB = max(linRGB, half3(0.h, 0.h, 0.h));
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
// Exact version, useful for debugging.
//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
}
//ASE
float2 voronoihash1( float2 p )
{
p = float2( dot( p, float2( 127.1, 311.7 ) ), dot( p, float2( 269.5, 183.3 ) ) );
return frac( sin( p ) *43758.5453);
}
//ASE
float voronoi1( float2 v, float time, inout float2 id, inout float2 mr, float smoothness )
{
float2 n = floor( v );
float2 f = frac( v );
float F1 = 8.0;
float F2 = 8.0; float2 mg = 0;
for ( int j = -1; j <= 1; j++ )
{
for ( int i = -1; i <= 1; i++ )
{
float2 g = float2( i, j );
float2 o = voronoihash1( n + g );
o = ( sin( time + o * 6.2831 ) * 0.5 + 0.5 ); float2 r = f - g - o;
float d = 0.5 * dot( r, r );
if( d<F1 ) {
F2 = F1;
F1 = d; mg = g; mr = r; id = o;
} else if( d<F2 ) {
F2 = d;
}
}
}
return F2 - F1;
}
void voroniForgraphfunc_half(half2 uv,half angle,half scale,out float outVoroni1 )
{
uv = uv*scale;
float2 id1 = 0;
float2 uv1 = 0;
outVoroni1 = voronoi1( uv, angle, id1, uv1, 0 );
}
inline float2 unity_voronoi_noise_randomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
void Unity_Voronoi_float(float2 UV, float AngleOffset, float CellDensity, out float Out, out float Cells)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = unity_voronoi_noise_randomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
Out = res.x;
Cells = res.y;
}
}
}
}
void Unity_Blend_Overlay_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
float4 result2 = 2.0 * Base * Blend;
float4 zeroOrOne = step(Base, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
void Unity_Blend_HardLight_half(half Base, half Blend, half Opacity, out half Out)
{
half result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
half result2 = 2.0 * Base * Blend;
half zeroOrOne = step(Blend, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
float2 randomGradient(float2 p) {
p = p + 0.02;
float x = dot(p, float2(123.4, 234.5));
float y = dot(p, float2(234.5, 345.6));
float2 gradient = float2(x, y);
gradient = sin(gradient);
gradient = gradient * 43758.5453;
// part 4.5 - update noise function with time
// gradient = sin(gradient + u_time);
return gradient;
// gradient = sin(gradient);
// return gradient;
}
#include "./jp.keijiro.noiseshader/Shader/SimplexNoise3D.hlsl"
half SimplexNoise(float2 uv,float time)
{
return SimplexNoise(float3(uv,time))*0.5+0.5;
}
#include "./jp.keijiro.noiseshader/Shader/ClassicNoise3D.hlsl"
half PerlinNoise(float2 uv,float time)
{
return ClassicNoise(float3(uv,time))*0.5+0.5;
}
float2 PolarCoordinates(float2 UV, float2 _PCCenter)
{
// float2 uvsource = float2(0, 0);
float2 delta = UV - _PCCenter.xy;//校准UV到中心
float radius = length(delta) * 2;
float angle = atan2(delta.x, delta.y) * UNITY_INV_TWO_PI ;
return float2(angle, radius);//翻转可以调整横向和纵向。
}
float2 PolarCoordinatesStrengthAndST(float2 UVBeforPollarCoord,float2 UVAfterPolarCoord,float polarStrenth ,float4 tex_ST)
{
UVAfterPolarCoord = UVAfterPolarCoord*tex_ST.xy + tex_ST.zw;//利用相应功能贴图的坐标对ST进行修改。
UVAfterPolarCoord = lerp(UVBeforPollarCoord, UVAfterPolarCoord, polarStrenth);
return UVAfterPolarCoord;
}
//极坐标//transformation为极坐标强度
float2 PolarCoordinates(float2 UV, float3 _PCCenter, float4 tex_ST)
{
// float2 uvsource = float2(0, 0);
//
// float2 delta = UV - _PCCenter.xy;//校准UV到中心
// float radius = length(delta) * 2;
// float angle = atan2(delta.x, delta.y) * UNITY_INV_TWO_PI ;
// uvsource = float2(angle, radius);//翻转可以调整横向和纵向。
// uvsource = uvsource*tex_ST.xy + tex_ST.zw;//利用相应功能贴图的坐标对ST进行修改。
// uvsource = lerp(UV, uvsource, _PCCenter.z);
// return uvsource;
//拆分成两步第一步求极坐标太耗atan一般源UV都是一样的只是ST不同。
float2 uvsource = PolarCoordinates(UV,_PCCenter.xy);
uvsource = PolarCoordinatesStrengthAndST(UV,uvsource,_PCCenter.z,tex_ST);
return uvsource;
}
float2 CylinderCoordinate(float3 positionOS)
{
float angle = atan2(positionOS.x,positionOS.z)* UNITY_INV_TWO_PI ;
return float2(angle,positionOS.y);
}
float2 UVOffsetAnimaiton(float2 UV,half2 OffsetSpeed,float time)
{
float2 newUV = float2(OffsetSpeed.x*time+UV.x,OffsetSpeed.y*time+UV.y);
return newUV;
}
half3 rgb2hsv(half3 c)
{
half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g));
half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
half3 hsv2rgb(half3 c)
{
half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
half3 ColorSaturate(half3 color, half colorSaturation)
{
half3 lum = luminance(color);
return max(0, lerp(lum, color, colorSaturation));
}
half2 Rotate(half2 v, half cos0, half sin0)
{
return half2(v.x * cos0 - v.y * sin0,
v.x * sin0 + v.y * cos0);
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f34986983f558c40a7e30a353dc3c34
timeCreated: 1684725413

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e95a8f1b5d23f4141b5121f98f90f10a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
Noise Shader Library for Unity
==============================
**NoiseShader** is a Unity package that provides 2D/3D gradient noise
functions written in the shader language. These functions are ported from the
[webgl-noise] library that is originally written by Stefan Gustavson and Ahima
Arts.
[webgl-noise]: https://github.com/ashima/webgl-noise
At the moment, it contains the following functions:
- Classic Perlin noise (2D/3D)
- Periodic Perlin noise (2D/3D)
- Simplex noise (2D/3D)
- Analytical derivatives of simplex noise (2D/3D)
How To Install
--------------
This package uses the [scoped registry] feature to resolve package dependencies.
Please add the following sections to the manifest file (Packages/manifest.json).
[scoped registry]: https://docs.unity3d.com/Manual/upm-scoped.html
To the `scopedRegistries` section:
```
{
"name": "Keijiro",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.keijiro" ]
}
```
To the `dependencies` section:
```
"jp.keijiro.noiseshader": "2.0.0"
```
After changes, the manifest file should look like below:
```
{
"scopedRegistries": [
{
"name": "Keijiro",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.keijiro" ]
}
],
"dependencies": {
"jp.keijiro.noiseshader": "2.0.0",
...
```

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b92baefe22663afa5ad0ab303b3dcc20
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 77b21af505211947eb730e678820eb8b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
//
// GLSL textureless classic 2D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-08-22
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_2D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_2D_HLSL_
#include "Common.hlsl"
float ClassicNoise_impl(float2 pi0, float2 pf0, float2 pi1, float2 pf1)
{
pi0 = wglnoise_mod289(pi0); // To avoid truncation effects in permutation
pi1 = wglnoise_mod289(pi1);
float4 ix = float2(pi0.x, pi1.x).xyxy;
float4 iy = float2(pi0.y, pi1.y).xxyy;
float4 fx = float2(pf0.x, pf1.x).xyxy;
float4 fy = float2(pf0.y, pf1.y).xxyy;
float4 i = wglnoise_permute(wglnoise_permute(ix) + iy);
float4 phi = i / 41 * 3.14159265359 * 2;
float2 g00 = float2(cos(phi.x), sin(phi.x));
float2 g10 = float2(cos(phi.y), sin(phi.y));
float2 g01 = float2(cos(phi.z), sin(phi.z));
float2 g11 = float2(cos(phi.w), sin(phi.w));
float n00 = dot(g00, float2(fx.x, fy.x));
float n10 = dot(g10, float2(fx.y, fy.y));
float n01 = dot(g01, float2(fx.z, fy.z));
float n11 = dot(g11, float2(fx.w, fy.w));
float2 fade_xy = wglnoise_fade(pf0);
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
return 1.44 * n_xy;
}
// Classic Perlin noise
float ClassicNoise(float2 p)
{
float2 i = floor(p);
float2 f = frac(p);
return ClassicNoise_impl(i, f, i + 1, f - 1);
}
// Classic Perlin noise, periodic variant
float PeriodicNoise(float2 p, float2 rep)
{
float2 i0 = wglnoise_mod(floor(p), rep);
float2 i1 = wglnoise_mod(i0 + 1, rep);
float2 f = frac(p);
return ClassicNoise_impl(i0, f, i1, f - 1);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8ec48974b9689234f9a4a7c1927e2a7b
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
//
// GLSL textureless classic 3D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-10-11
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_3D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_3D_HLSL_
#include "Common.hlsl"
float ClassicNoise_impl(float3 pi0, float3 pf0, float3 pi1, float3 pf1)
{
pi0 = wglnoise_mod289(pi0);
pi1 = wglnoise_mod289(pi1);
float4 ix = float4(pi0.x, pi1.x, pi0.x, pi1.x);
float4 iy = float4(pi0.y, pi0.y, pi1.y, pi1.y);
float4 iz0 = pi0.z;
float4 iz1 = pi1.z;
float4 ixy = wglnoise_permute(wglnoise_permute(ix) + iy);
float4 ixy0 = wglnoise_permute(ixy + iz0);
float4 ixy1 = wglnoise_permute(ixy + iz1);
float4 gx0 = lerp(-1, 1, frac(floor(ixy0 / 7) / 7));
float4 gy0 = lerp(-1, 1, frac(floor(ixy0 % 7) / 7));
float4 gz0 = 1 - abs(gx0) - abs(gy0);
bool4 zn0 = gz0 < -0.01;
gx0 += zn0 * (gx0 < -0.01 ? 1 : -1);
gy0 += zn0 * (gy0 < -0.01 ? 1 : -1);
float4 gx1 = lerp(-1, 1, frac(floor(ixy1 / 7) / 7));
float4 gy1 = lerp(-1, 1, frac(floor(ixy1 % 7) / 7));
float4 gz1 = 1 - abs(gx1) - abs(gy1);
bool4 zn1 = gz1 < -0.01;
gx1 += zn1 * (gx1 < -0.01 ? 1 : -1);
gy1 += zn1 * (gy1 < -0.01 ? 1 : -1);
float3 g000 = normalize(float3(gx0.x, gy0.x, gz0.x));
float3 g100 = normalize(float3(gx0.y, gy0.y, gz0.y));
float3 g010 = normalize(float3(gx0.z, gy0.z, gz0.z));
float3 g110 = normalize(float3(gx0.w, gy0.w, gz0.w));
float3 g001 = normalize(float3(gx1.x, gy1.x, gz1.x));
float3 g101 = normalize(float3(gx1.y, gy1.y, gz1.y));
float3 g011 = normalize(float3(gx1.z, gy1.z, gz1.z));
float3 g111 = normalize(float3(gx1.w, gy1.w, gz1.w));
float n000 = dot(g000, pf0);
float n100 = dot(g100, float3(pf1.x, pf0.y, pf0.z));
float n010 = dot(g010, float3(pf0.x, pf1.y, pf0.z));
float n110 = dot(g110, float3(pf1.x, pf1.y, pf0.z));
float n001 = dot(g001, float3(pf0.x, pf0.y, pf1.z));
float n101 = dot(g101, float3(pf1.x, pf0.y, pf1.z));
float n011 = dot(g011, float3(pf0.x, pf1.y, pf1.z));
float n111 = dot(g111, pf1);
float3 fade_xyz = wglnoise_fade(pf0);
float4 n_z = lerp(float4(n000, n100, n010, n110),
float4(n001, n101, n011, n111), fade_xyz.z);
float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x);
return 1.46 * n_xyz;
}
// Classic Perlin noise
float ClassicNoise(float3 p)
{
float3 i = floor(p);
float3 f = frac(p);
return ClassicNoise_impl(i, f, i + 1, f - 1);
}
// Classic Perlin noise, periodic variant
float PeriodicNoise(float3 p, float3 rep)
{
float3 i0 = wglnoise_mod(floor(p), rep);
float3 i1 = wglnoise_mod(i0 + 1, rep);
float3 f = frac(p);
return ClassicNoise_impl(i0, f, i1, f - 1);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2688615dc3cd4ed4cbca4cd0135d8e8a
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_COMMON_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_COMMON_HLSL_
float wglnoise_mod(float x, float y)
{
return x - y * floor(x / y);
}
float2 wglnoise_mod(float2 x, float2 y)
{
return x - y * floor(x / y);
}
float3 wglnoise_mod(float3 x, float3 y)
{
return x - y * floor(x / y);
}
float4 wglnoise_mod(float4 x, float4 y)
{
return x - y * floor(x / y);
}
float2 wglnoise_fade(float2 t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
float3 wglnoise_fade(float3 t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
float wglnoise_mod289(float x)
{
return x - floor(x / 289) * 289;
}
float2 wglnoise_mod289(float2 x)
{
return x - floor(x / 289) * 289;
}
float3 wglnoise_mod289(float3 x)
{
return x - floor(x / 289) * 289;
}
float4 wglnoise_mod289(float4 x)
{
return x - floor(x / 289) * 289;
}
float3 wglnoise_permute(float3 x)
{
return wglnoise_mod289((x * 34 + 1) * x);
}
float4 wglnoise_permute(float4 x)
{
return wglnoise_mod289((x * 34 + 1) * x);
}
#endif

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 443fb5ca2e0ec42bc8a96eb43c8470fe
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_2D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_2D_HLSL_
#include "Common.hlsl"
float3 SimplexNoiseGrad(float2 v)
{
const float C1 = (3 - sqrt(3)) / 6;
const float C2 = (sqrt(3) - 1) / 2;
// First corner
float2 i = floor(v + dot(v, C2));
float2 x0 = v - i + dot(i, C1);
// Other corners
float2 i1 = x0.x > x0.y ? float2(1, 0) : float2(0, 1);
float2 x1 = x0 + C1 - i1;
float2 x2 = x0 + C1 * 2 - 1;
// Permutations
i = wglnoise_mod289(i); // Avoid truncation effects in permutation
float3 p = wglnoise_permute( i.y + float3(0, i1.y, 1));
p = wglnoise_permute(p + i.x + float3(0, i1.x, 1));
// Gradients: 41 points uniformly over a unit circle.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
float3 phi = p / 41 * 3.14159265359 * 2;
float2 g0 = float2(cos(phi.x), sin(phi.x));
float2 g1 = float2(cos(phi.y), sin(phi.y));
float2 g2 = float2(cos(phi.z), sin(phi.z));
// Compute noise and gradient at P
float3 m = float3(dot(x0, x0), dot(x1, x1), dot(x2, x2));
float3 px = float3(dot(g0, x0), dot(g1, x1), dot(g2, x2));
m = max(0.5 - m, 0);
float3 m3 = m * m * m;
float3 m4 = m * m3;
float3 temp = -8 * m3 * px;
float2 grad = m4.x * g0 + temp.x * x0 +
m4.y * g1 + temp.y * x1 +
m4.z * g2 + temp.z * x2;
return 99.2 * float3(grad, dot(m4, px));
}
float SimplexNoise(float2 v)
{
return SimplexNoiseGrad(v).z;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 66b8605d5d2f14d408b0f4aee5f9d25a
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
//
// Description : Array and textureless GLSL 2D/3D/4D simplex
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_3D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_3D_HLSL_
#include "Common.hlsl"
float4 SimplexNoiseGrad(float3 v)
{
// First corner
float3 i = floor(v + dot(v, 1.0 / 3));
float3 x0 = v - i + dot(i, 1.0 / 6);
// Other corners
float3 g = x0.yzx <= x0.xyz;
float3 l = 1 - g;
float3 i1 = min(g.xyz, l.zxy);
float3 i2 = max(g.xyz, l.zxy);
float3 x1 = x0 - i1 + 1.0 / 6;
float3 x2 = x0 - i2 + 1.0 / 3;
float3 x3 = x0 - 0.5;
// Permutations
i = wglnoise_mod289(i); // Avoid truncation effects in permutation
float4 p = wglnoise_permute( i.z + float4(0, i1.z, i2.z, 1));
p = wglnoise_permute(p + i.y + float4(0, i1.y, i2.y, 1));
p = wglnoise_permute(p + i.x + float4(0, i1.x, i2.x, 1));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float4 gx = lerp(-1, 1, frac(floor(p / 7) / 7));
float4 gy = lerp(-1, 1, frac(floor(p % 7) / 7));
float4 gz = 1 - abs(gx) - abs(gy);
bool4 zn = gz < -0.01;
gx += zn * (gx < -0.01 ? 1 : -1);
gy += zn * (gy < -0.01 ? 1 : -1);
float3 g0 = normalize(float3(gx.x, gy.x, gz.x));
float3 g1 = normalize(float3(gx.y, gy.y, gz.y));
float3 g2 = normalize(float3(gx.z, gy.z, gz.z));
float3 g3 = normalize(float3(gx.w, gy.w, gz.w));
// Compute noise and gradient at P
float4 m = float4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3));
float4 px = float4(dot(g0, x0), dot(g1, x1), dot(g2, x2), dot(g3, x3));
m = max(0.5 - m, 0);
float4 m3 = m * m * m;
float4 m4 = m * m3;
float4 temp = -8 * m3 * px;
float3 grad = m4.x * g0 + temp.x * x0 +
m4.y * g1 + temp.y * x1 +
m4.z * g2 + temp.z * x2 +
m4.w * g3 + temp.w * x3;
return 107 * float4(grad, dot(m4, px));
}
float SimplexNoise(float3 v)
{
return SimplexNoiseGrad(v).w;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2b1bb9b67aabb824998a7d2e026d2606
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
{
"author": "Keijiro Takahashi",
"description": "Noise Shader provides lightweight 2D/3D gradient noise functions for shader use.",
"displayName": "Noise Shader",
"keywords": [ "unity" ],
"license": "MIT",
"name": "jp.keijiro.noiseshader",
"repository": "github:keijiro/NoiseShader",
"unity": "2019.3",
"unityRelease": "0f1",
"version": "2.0.0"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 39ccfaa9af9f4dc84a876b1b1c3ae8bb
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
{
"name": "com.xuanxuan.render.utility",
"version": "0.0.1",
"displayName": "XuanXuanRenderUtility",
"description": "XuanXuanRenderUtility",
"unity": "2019.1"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 45aa6b78bfd3f814b8fbc72aeba1affd
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: