新增unity的牛逼shader和熊猫超级shader
This commit is contained in:
1 parent
6001f6d87a
commit
1a4cd29e7c
216 files changed
+41947
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af9e4a2cbc9cee94485138c3bc876c62
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="91023a6b-e90c-4b7e-ad29-2c758b62337b" name="更改" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 1
|
||||
}]]></component>
|
||||
<component name="ProjectId" id="2woZni0kkDvAva6vMvSRxXle59k" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="默认任务">
|
||||
<changelist id="91023a6b-e90c-4b7e-ad29-2c758b62337b" name="更改" comment="" />
|
||||
<created>1746710058620</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1746710058620</updated>
|
||||
<workItem from="1746710064595" duration="3599000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,146 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(AnimationSheetHelper))]
|
||||
public class AnimationSheetHelperEditor : Editor
|
||||
{
|
||||
SerializedProperty isParticleBaseShader;
|
||||
SerializedProperty isPostProcessShader;
|
||||
SerializedProperty postProcessingController;
|
||||
SerializedProperty propertyName;
|
||||
|
||||
SerializedProperty xSize;
|
||||
SerializedProperty ySize;
|
||||
|
||||
SerializedProperty manualPlay;
|
||||
SerializedProperty manualPlayePos;
|
||||
SerializedProperty speed;
|
||||
|
||||
SerializedProperty scaleOffset;
|
||||
SerializedProperty mat;
|
||||
SerializedProperty frameIndex;
|
||||
SerializedProperty frameCount;
|
||||
|
||||
private AnimationSheetHelper _target;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_target = (AnimationSheetHelper)target;
|
||||
|
||||
isParticleBaseShader = serializedObject.FindProperty("isParticleBaseShader");
|
||||
// isPostProcessShader = serializedObject.FindProperty("isPostProcessShader");
|
||||
// postProcessingController = serializedObject.FindProperty("postProcessingController");
|
||||
propertyName = serializedObject.FindProperty("propertyName");
|
||||
|
||||
xSize = serializedObject.FindProperty("xSize");
|
||||
ySize = serializedObject.FindProperty("ySize");
|
||||
|
||||
manualPlay = serializedObject.FindProperty("manualPlay");
|
||||
manualPlayePos = serializedObject.FindProperty("manualPlayePos");
|
||||
speed = serializedObject.FindProperty("speed");
|
||||
|
||||
scaleOffset = serializedObject.FindProperty("scaleOffset");
|
||||
mat = serializedObject.FindProperty("mat");
|
||||
frameIndex = serializedObject.FindProperty("frameIndex");
|
||||
frameCount = serializedObject.FindProperty("frameCount");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawShaderSection();
|
||||
EditorGUILayout.Space(5);
|
||||
DrawAnimationSection();
|
||||
EditorGUILayout.Space(5);
|
||||
DrawRuntimeInfo();
|
||||
EditorGUILayout.Space(8);
|
||||
DrawInitButton();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
#region Sections
|
||||
|
||||
void DrawShaderSection()
|
||||
{
|
||||
EditorGUILayout.LabelField("Shader 设置", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(isParticleBaseShader, new GUIContent("使用 NB Shader"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
_target.InitParticleBaseShaderToggle();
|
||||
EditorUtility.SetDirty(_target);
|
||||
}
|
||||
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// EditorGUILayout.PropertyField(isPostProcessShader, new GUIContent("使用 后处理扭曲"));
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// {
|
||||
// serializedObject.ApplyModifiedProperties();
|
||||
// // _target.InitPostProcessToggle();
|
||||
// EditorUtility.SetDirty(_target);
|
||||
// }
|
||||
|
||||
// if (isPostProcessShader.boolValue)
|
||||
// {
|
||||
// GUI.enabled = false;
|
||||
// EditorGUILayout.PropertyField(postProcessingController);
|
||||
// GUI.enabled = true;
|
||||
// }
|
||||
|
||||
EditorGUILayout.PropertyField(propertyName, new GUIContent("Shader 属性名"));
|
||||
}
|
||||
|
||||
void DrawAnimationSection()
|
||||
{
|
||||
EditorGUILayout.LabelField("序列帧设置", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(xSize, new GUIContent("横向帧数量"));
|
||||
EditorGUILayout.PropertyField(ySize, new GUIContent("纵向帧数量"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
_target.Init();
|
||||
EditorUtility.SetDirty(_target);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(4);
|
||||
EditorGUILayout.PropertyField(manualPlay, new GUIContent("手动控制播放"));
|
||||
|
||||
if (manualPlay.boolValue)
|
||||
{
|
||||
EditorGUILayout.PropertyField(manualPlayePos, new GUIContent("手动播放位置"));
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(speed, new GUIContent("播放速度 fps"));
|
||||
}
|
||||
}
|
||||
|
||||
void DrawRuntimeInfo()
|
||||
{
|
||||
EditorGUILayout.LabelField("运行时信息", EditorStyles.boldLabel);
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(scaleOffset, new GUIContent("Tiling Offset"));
|
||||
EditorGUILayout.PropertyField(mat, new GUIContent("Material"));
|
||||
EditorGUILayout.PropertyField(frameIndex);
|
||||
EditorGUILayout.PropertyField(frameCount);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
void DrawInitButton()
|
||||
{
|
||||
if (GUILayout.Button("初始化", GUILayout.Height(28)))
|
||||
{
|
||||
_target.Init();
|
||||
EditorUtility.SetDirty(_target);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e1a5d6748bd4515869cb9c6ebd2b548
|
||||
timeCreated: 1769260616
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01d5272ee28d1384d9f555c579592a6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.shaders.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:0e3b0e6ce60c7a34094f8f9822c0b7f2",
|
||||
"GUID:8495541fcd41b0c40b5b6e6e7a7639d1",
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e03fab8dc9c256468083d9bc82a73c3
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4684518ac782305428f8c0434c85d1c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,328 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
// using Sirenix.OdinInspector;
|
||||
// using Unity.Mathematics;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using NBShader;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class AnimationSheetHelper : MonoBehaviour,IMaterialModifier
|
||||
{
|
||||
|
||||
public bool isParticleBaseShader = true;
|
||||
|
||||
public string propertyName = "_BaseMap_ST";
|
||||
|
||||
private int _propertyID;
|
||||
private int _particleBaseAniBlendStPropertyID = Shader.PropertyToID("_BaseMap_AnimationSheetBlend_ST");
|
||||
private int _particleBaseAniBlendIntensityPropertyID = Shader.PropertyToID("_AnimationSheetHelperBlendIntensity");
|
||||
private W9ParticleShaderFlags _flags = new W9ParticleShaderFlags();
|
||||
|
||||
|
||||
|
||||
// [LabelText("序列帧图横向帧数量")]
|
||||
// [OnValueChanged("Init")]
|
||||
public int xSize = 4;
|
||||
|
||||
// [LabelText("序列帧图纵向帧数量")]
|
||||
// [OnValueChanged("Init")]
|
||||
public int ySize = 4;
|
||||
|
||||
// [LabelText("手动控制播放")]
|
||||
public bool manualPlay = false;
|
||||
|
||||
// [ShowIf("manualPlay")]
|
||||
// [LabelText("手动播放位置")] [Range(0, 1)]
|
||||
public float manualPlayePos = 0;
|
||||
|
||||
// [LabelText("播放速度fps")]
|
||||
// [HideIf("manualPlay")]
|
||||
public float speed = 16;
|
||||
|
||||
// [ReadOnly]
|
||||
// [LabelText("TillingOffset")]
|
||||
public Vector4 scaleOffset;
|
||||
// [ReadOnly]
|
||||
public Material mat;
|
||||
|
||||
// [ReadOnly]
|
||||
public int frameIndex;
|
||||
// [ReadOnly]
|
||||
public int frameCount;
|
||||
|
||||
private float _time;
|
||||
|
||||
private float _xScale;
|
||||
private float _yScale;
|
||||
|
||||
private static List<Material> usedMaterialList = new List<Material>();
|
||||
|
||||
|
||||
// // Start is called before the first frame update
|
||||
// void Start()
|
||||
// {
|
||||
// Debug.Log( "ASUpadate_Start");
|
||||
// Init();
|
||||
// }
|
||||
private void OnEnable()
|
||||
{
|
||||
// Debug.Log( "ASUpadate_OnEnable");
|
||||
Init();
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.update += EditorUpdate;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Init();
|
||||
|
||||
//清掉,避免参数保留。
|
||||
if (isParticleBaseShader)
|
||||
{
|
||||
if (mat)
|
||||
{
|
||||
_flags.SetMaterial(mat);
|
||||
_flags.ClearFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER,index:1);
|
||||
}
|
||||
}
|
||||
|
||||
if (usedMaterialList.Contains(mat))
|
||||
{
|
||||
usedMaterialList.Remove(mat);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
#endif
|
||||
}
|
||||
|
||||
// [Button("初始化")]
|
||||
public void Init()
|
||||
{
|
||||
_time = 0;
|
||||
if (xSize <= 0)
|
||||
{
|
||||
xSize = 1;
|
||||
}
|
||||
|
||||
if (ySize <= 0)
|
||||
{
|
||||
ySize = 1;
|
||||
}
|
||||
frameCount = xSize * ySize;
|
||||
|
||||
_xScale = 1 / (float)xSize;
|
||||
_yScale = 1 / (float)ySize;
|
||||
// if (frameCount <= 0)
|
||||
// {
|
||||
// frameCount = 1;
|
||||
// }
|
||||
// scaleOffset = new Vector4(1f/(float)xSize,1f/ (float)ySize, 0, 0);
|
||||
|
||||
if (gameObject.TryGetComponent(out Graphic g))
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
mat = g.materialForRendering;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = g.material;
|
||||
}
|
||||
}
|
||||
else if (gameObject.TryGetComponent(out Renderer r))
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
mat = r.material;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = r.sharedMaterial;
|
||||
}
|
||||
// Debug.Log("AS_GetRenderer:Mat--"+mat.name);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = null;
|
||||
}
|
||||
|
||||
InitParticleBaseShaderToggle();
|
||||
// InitPostProcessToggle();
|
||||
|
||||
|
||||
_propertyID = Shader.PropertyToID(propertyName);
|
||||
if (mat != null)
|
||||
{
|
||||
mat.SetVector(_propertyID,CalSt(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void InitParticleBaseShaderToggle()
|
||||
{
|
||||
if (isParticleBaseShader)
|
||||
{
|
||||
_flags.SetMaterial(mat);
|
||||
// Debug.Log(_flags.CheckFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE,index:1));
|
||||
if(_flags.CheckFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_UIEFFECT_ON) && !_flags.CheckFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE,index:1))
|
||||
{
|
||||
propertyName = "_UI_MainTex_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = "_BaseMap_ST";
|
||||
}
|
||||
if (mat)
|
||||
{
|
||||
|
||||
_flags.SetMaterial(mat);
|
||||
_flags.SetFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER,index:1);
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// if (mat)
|
||||
// {
|
||||
// if (mat.shader.name == "Mh2/Effects/Particle_NiuBi")
|
||||
// {
|
||||
// _flags.SetMaterial(mat);
|
||||
// _flags.ClearFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER,index:1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// public void InitPostProcessToggle()
|
||||
// {
|
||||
// if (isPostProcessShader)
|
||||
// {
|
||||
// TryGetComponent<PostProcessingController>(out postProcessingController);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// postProcessingController = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
private int _lastIndex;
|
||||
private int _nextIndex = 1;
|
||||
private float _blendLerp;
|
||||
private void Update()
|
||||
{
|
||||
// if (!isPostProcessShader)//后处理控制不通过才知。
|
||||
// {
|
||||
// if(!mat || _propertyID==0) return;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
float frameIndexFloat;
|
||||
if (manualPlay)
|
||||
{
|
||||
float playPos = Mathf.Repeat(manualPlayePos, 1f);
|
||||
frameIndexFloat = playPos * frameCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_time += (float)editorDeltaTime * speed;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
_time += Time.deltaTime * speed;
|
||||
}
|
||||
frameIndexFloat = _time % frameCount;
|
||||
}
|
||||
frameIndex = (int) frameIndexFloat;
|
||||
if (frameIndex == frameCount)
|
||||
{
|
||||
frameIndex = frameCount - 1;
|
||||
}
|
||||
|
||||
|
||||
if (_lastIndex != frameIndex)
|
||||
{
|
||||
// if (isPostProcessShader)
|
||||
// {
|
||||
// postProcessingController.distortSpeedTexSt = CalSt(frameIndex);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
mat.SetVector(_propertyID,CalSt(frameIndex));
|
||||
// }
|
||||
_lastIndex = frameIndex;
|
||||
_nextIndex = frameIndex + 1;
|
||||
if (isParticleBaseShader)
|
||||
{
|
||||
mat.SetVector(_particleBaseAniBlendStPropertyID,CalSt(_nextIndex));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isParticleBaseShader)
|
||||
{
|
||||
_blendLerp = Mathf.Repeat(frameIndexFloat,1f);
|
||||
mat.SetFloat(_particleBaseAniBlendIntensityPropertyID,_blendLerp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Material GetModifiedMaterial(Material baseMaterial)
|
||||
{
|
||||
if (usedMaterialList.Contains(baseMaterial))
|
||||
{
|
||||
//有可能打断UI合批,烦请客户端判断
|
||||
Material newMat = Instantiate(baseMaterial);
|
||||
mat = newMat;
|
||||
usedMaterialList.Add(newMat);
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = baseMaterial;
|
||||
usedMaterialList.Add(baseMaterial);
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Vector4 CalSt(int index)
|
||||
{
|
||||
float xOffset = (index % xSize)*_xScale;
|
||||
float yOffset = (ySize - index / xSize -1)*_yScale;
|
||||
return new Vector4(_xScale, _yScale, xOffset, yOffset);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
private double editorDeltaTime = 0;
|
||||
private double lastEditorTime = 0;
|
||||
void EditorUpdate()
|
||||
{
|
||||
|
||||
if (lastEditorTime == 0)
|
||||
{
|
||||
lastEditorTime = EditorApplication.timeSinceStartup;
|
||||
}
|
||||
editorDeltaTime = EditorApplication.timeSinceStartup - lastEditorTime;
|
||||
lastEditorTime = EditorApplication.timeSinceStartup;
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf793623f3ea13b4db35460280cb6ded
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
// using Sirenix.OdinInspector;
|
||||
namespace NBShader
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class NBShaderSpriteHelper : MonoBehaviour
|
||||
{
|
||||
public Sprite sprite;
|
||||
|
||||
// [ReadOnly]
|
||||
public SpriteRenderer spRenderer;
|
||||
|
||||
// [ReadOnly]
|
||||
public Image image;
|
||||
|
||||
[InspectorButton("初始化", "Init")] public bool ButtomInspector;
|
||||
|
||||
private Material mat;
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
if (TryGetComponent<SpriteRenderer>(out SpriteRenderer spr))
|
||||
{
|
||||
spRenderer = spr;
|
||||
sprite = spr.sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TryGetComponent<Image>(out Image im))
|
||||
{
|
||||
image = im;
|
||||
sprite = im.sprite;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (sprite)
|
||||
{
|
||||
Texture texture = sprite.texture;
|
||||
Rect rect = sprite.textureRect;
|
||||
// sharedMaterial.SetVector("_BaseMapReverseST",CalScaleOffset(spRenderer.sprite.textureRect,spRenderer.sprite.texture));
|
||||
|
||||
if (spRenderer)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
mat = spRenderer.material;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = spRenderer.sharedMaterial;
|
||||
}
|
||||
}
|
||||
else if (image)
|
||||
{
|
||||
mat = image.material;
|
||||
}
|
||||
|
||||
if (mat && mat.shader.name == "Effects/NBShader")
|
||||
{
|
||||
mat.SetVector("_MainTex_Reverse_ST", CalScaleOffset(rect, texture));
|
||||
Debug.Log(mat.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Vector4 CalScaleOffset(Rect textureRect, Texture texture)
|
||||
{
|
||||
//这是一个反向的scale offset。
|
||||
//算法:如果原scale offset。转换后会是 scaleAfter= 1 / scale , offsetAfter = - offset/scale;
|
||||
Vector2 scaleAfter = new Vector2(texture.width / textureRect.width, texture.height / textureRect.height);
|
||||
Vector2 offsetAfter = new Vector2(-(textureRect.x / texture.width) * scaleAfter.x,
|
||||
-(textureRect.y / texture.height) * scaleAfter.y);
|
||||
Vector4 scaleOffset = new Vector4(scaleAfter.x, scaleAfter.y, offsetAfter.x, offsetAfter.y);
|
||||
return scaleOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58ec7ff2f9b58f5459946ac86028eacf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,768 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBShader
|
||||
{
|
||||
public class W9ParticleShaderFlags : ShaderFlagsBase
|
||||
{
|
||||
public const string FlagsName = "_W9ParticleShaderFlags";
|
||||
public static int FlagsId = Shader.PropertyToID(FlagsName);
|
||||
|
||||
|
||||
public const string Flags1Name = "_W9ParticleShaderFlags1";
|
||||
public static int Flags1Id = Shader.PropertyToID(Flags1Name);
|
||||
|
||||
public const string WrapFlagsName = "_W9ParticleShaderWrapFlags";
|
||||
public static int WrapFlagsId = Shader.PropertyToID(WrapFlagsName);
|
||||
|
||||
public const string foldOutFlagName = "_W9ParticleShaderGUIFoldToggle";
|
||||
public static int foldOutFlagId = Shader.PropertyToID(foldOutFlagName);
|
||||
|
||||
public const string foldOutFlagName1 = "_W9ParticleShaderGUIFoldToggle1";
|
||||
public static int foldOutFlagId1 = Shader.PropertyToID(foldOutFlagName1);
|
||||
|
||||
public const string foldOutFlagName2 = "_W9ParticleShaderGUIFoldToggle2";
|
||||
public static int foldOutFlagId2 = Shader.PropertyToID(foldOutFlagName2);
|
||||
|
||||
public const string colorChannelFlagName = "_W9ParticleShaderColorChannelFlag";
|
||||
public static int colorChannelFlagId = Shader.PropertyToID(colorChannelFlagName);
|
||||
|
||||
public const string pNoiseBlendFlagName = "_W9ParticleShaderPNoiseBlendFlag";
|
||||
public static int pNoiseBlendFlagId = Shader.PropertyToID(pNoiseBlendFlagName);
|
||||
|
||||
// public const string WrapFlags2Name = "_W9ParticleShaderWrapFlags2";
|
||||
// public static int WrapFlags2Id = Shader.PropertyToID(WrapFlags2Name);
|
||||
|
||||
public override int GetShaderFlagsId(int index = 0)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return FlagsId;
|
||||
|
||||
case 1:
|
||||
return Flags1Id;
|
||||
|
||||
case 2:
|
||||
return WrapFlagsId;
|
||||
|
||||
//FoldOut必须要紧挨着,因为按照Index去拿AnimBool
|
||||
case 3:
|
||||
return foldOutFlagId;
|
||||
|
||||
case 4:
|
||||
return foldOutFlagId1;
|
||||
|
||||
case 5:
|
||||
return foldOutFlagId2;
|
||||
|
||||
case 6:
|
||||
return colorChannelFlagId;
|
||||
|
||||
case 7:
|
||||
return pNoiseBlendFlagId;
|
||||
// case 8:
|
||||
// return WrapFlags2Id;
|
||||
|
||||
default:
|
||||
return FlagsId;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetShaderFlagsName(int index = 0)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return FlagsName;
|
||||
|
||||
case 1:
|
||||
return Flags1Name;
|
||||
|
||||
case 2:
|
||||
return WrapFlagsName;
|
||||
|
||||
case 3:
|
||||
return foldOutFlagName;
|
||||
|
||||
case 4:
|
||||
return foldOutFlagName1;
|
||||
|
||||
case 5:
|
||||
return colorChannelFlagName;
|
||||
|
||||
default:
|
||||
return FlagsName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public W9ParticleShaderFlags(Material material = null) : base(material)
|
||||
{
|
||||
}
|
||||
|
||||
public const int FLAG_BIT_SATURABILITY_ON = 1 << 0;
|
||||
public const int FLAG_BIT_PARTICLE_NOISE_CHORATICABERRAT_WITH_NOISE = 1 << 1;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_FADE_ON = 1 << 2;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_COLOR_ON = 1 << 3;
|
||||
public const int FLAG_BIT_PARTICLE_USETEXCOORD2 = 1 << 4;
|
||||
public const int FLAG_BIT_PARTICLE_DISTANCEFADE_ON = 1 << 5;
|
||||
public const int FLAG_BIT_PARTICLE_CHORATICABERRAT = 1 << 6;
|
||||
public const int FLAG_BIT_PARTILCE_MASKMAPROTATIONANIMATION_ON = 1 << 7;
|
||||
public const int FLAG_BIT_PARTICLE_POLARCOORDINATES_ON = 1 << 8;
|
||||
public const int FLAG_BIT_PARTICLE_UTWIRL_ON = 1 << 9;
|
||||
public const int FLAG_BIT_PARTICLE_LINEARTOGAMMA_ON = 1 << 10;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_ON = 1 << 11;
|
||||
public const int FLAG_BIT_PARTICLE_NOISEMAP_NORMALIZEED_ON = 1 << 12;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_COLOR_AFFETCT_BY_ALPHA = 1 << 13;
|
||||
public const int FLAG_BIT_PARTICLE_UIEFFECT_ON = 1 << 14;
|
||||
public const int FLAG_BIT_PARTICLE_UNSCALETIME_ON = 1 << 15;
|
||||
public const int FLAG_BIT_PARTICLE_SCRIPTABLETIME_ON = 1 << 16;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1_ON = 1 << 17;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_INVERT_ON = 1 << 18;
|
||||
public const int FLAG_BIT_HUESHIFT_ON = 1 << 19;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2_ON = 1 << 20;
|
||||
public const int FLAG_BIT_PARTICLE_NORMALMAP_MASK_MODE = 1 << 21;
|
||||
public const int FLAG_BIT_PARTICLE_COLOR_ADJUSTMENT_ONLY_AFFECT_MAINTEX = 1 << 22;
|
||||
public const int FLAG_BIT_PARTICLE_RAMP_COLOR_MAP_MODE_ON = 1 << 23;
|
||||
public const int FLAG_BIT_PARTICLE_RAMP_COLOR_BLEND_ADD = 1 << 24;
|
||||
public const int FLAG_BIT_PARTICLE_COLOR_BLEND_ALPHA_MULTIPLY_MODE = 1 << 25;
|
||||
public const int FLAG_BIT_PARTICLE_DISSOLVE_RAMP_MAP = 1 << 26;
|
||||
public const int FLAG_BIT_PARTICLE_DISSOLVE_MASK = 1 << 27;
|
||||
public const int FLAG_BIT_PARTICLE_BACKCOLOR = 1 << 28;
|
||||
public const int FLAG_BIT_PARTICLE_COLOR_MULTI_ALPHA = 1 << 29;
|
||||
public const int FLAG_BIT_PARTICLE_VERTEX_OFFSET_ON = 1 << 30;
|
||||
public const int FLAG_BIT_PARTICLE_VERTEX_OFFSET_NORMAL_DIR = 1 << 31;
|
||||
|
||||
public const int FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE = 1 << 0;
|
||||
public const int FLAG_BIT_PARTICLE_1_PARALLAX_MAPPING = 1 << 1;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASKMAP_GRADIENT = 1 << 2;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASKMAP_2_GRADIENT = 1 << 3;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASKMAP_3_GRADIENT = 1 << 4;
|
||||
public const int FLAG_BIT_PARTICLE_1_DISSOLVE_LINE_MASK = 1 << 5;
|
||||
public const int FLAG_BIT_PARTICLE_1_DISSOLVE_RAMP_MULITPLY = 1 << 6;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASK_REFINE = 1 << 7;
|
||||
public const int FLAG_BIT_PARTICLE_1_SCREEN_DISTORT_ALPHA_REFINE = 1 << 8;
|
||||
public const int FLAG_BIT_PARTICLE_1_IGNORE_VERTEX_COLOR = 1 << 9;
|
||||
public const int FLAG_BIT_PARTICLE_1_PROGRAM_NOISE_SIMPLE = 1 << 10;
|
||||
public const int FLAG_BIT_PARTICLE_1_DISSOVLE_USE_RAMP = 1 << 11;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASK_MAP2 = 1 << 12;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASK_MAP3 = 1 << 13;
|
||||
public const int FLAG_BIT_PARTICLE_1_NOISE_MASKMAP = 1 << 14;
|
||||
public const int FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER = 1 << 15;
|
||||
public const int FLAG_BIT_PARTICLE_1_PROGRAM_NOISE_VORONOI = 1 << 16;
|
||||
public const int FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE = 1 << 17;
|
||||
public const int FLAG_BIT_PARTICLE_1_USE_TEXCOORD1 = 1 << 18;
|
||||
public const int FLAG_BIT_PARTICLE_1_USE_TEXCOORD2 = 1 << 19;
|
||||
public const int FLAG_BIT_PARTICLE_1_CYLINDER_CORDINATE = 1 << 20;
|
||||
public const int FLAG_BIT_PARTICLE_1_UV_FROM_MESH = 1 << 21; //3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE = 1 << 22; //3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM = 1 << 23; //3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_MAINTEX_CONTRAST = 1 << 24;
|
||||
public const int FLAG_BIT_PARTICLE_1_VERTEXOFFSET_START_FROM_ZERO = 1 << 25;
|
||||
public const int FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP = 1 << 26;
|
||||
public const int FLAG_BIT_PARTICLE_1_MAINTEX_COLOR_REFINE = 1 << 27;
|
||||
public const int FLAG_BIT_PARTICLE_1_BUMP_TEX_UV_FOLLOW_MAINTEX = 1 << 28;
|
||||
public const int FLAG_BIT_PARTICLE_1_SIXWAY_RAMPMAP = 1 << 29;
|
||||
public const int FLAG_BIT_PARTICLE_1_MATCAP_MULTY_MODE = 1 << 30;
|
||||
|
||||
|
||||
public const int FLAG_BIT_WRAPMODE_BASEMAP = 1 << 0;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP = 1 << 1;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP2 = 1 << 2;
|
||||
public const int FLAG_BIT_WRAPMODE_NOISEMAP = 1 << 3;
|
||||
public const int FLAG_BIT_WRAPMODE_EMISSIONMAP = 1 << 4;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_MAP = 1 << 5;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP = 1 << 6;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP = 1 << 7;
|
||||
public const int FLAG_BIT_WRAPMODE_COLORBLENDMAP = 1 << 8;
|
||||
public const int FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP = 1 << 9;
|
||||
public const int FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP = 1 << 10;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP3 = 1 << 11;
|
||||
public const int FLAG_BIT_WRAPMODE_NOISE_MASKMAP = 1 << 12;
|
||||
public const int FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP = 1 << 13;
|
||||
public const int FLAG_BIT_WRAPMODE_BUMPTEX = 1 << 14;
|
||||
public const int FLAG_BIT_WRAPMODE_RAMP_COLOR_MAP = 1 << 15;
|
||||
|
||||
// public const int FLAG_BIT_WRAPMODE2_SHAREDUV = 1 << 0;
|
||||
|
||||
public const int foldOutBitMeshOption = 1 << 0;
|
||||
public const int foldOutBitMainTexOption = 1 << 1;
|
||||
public const int foldOutBitBaseOption = 1 << 2;
|
||||
public const int foldOutBitFeatureOption = 1 << 3;
|
||||
public const int foldOutBitBaseMap = 1 << 4;
|
||||
public const int foldOutBitMask = 1 << 5;
|
||||
public const int foldOutBitMaskMap = 1 << 6;
|
||||
public const int foldOutBitMask2 = 1 << 7;
|
||||
public const int foldOutBitMask3 = 1 << 8;
|
||||
public const int foldOutBitTwril = 1 << 9;
|
||||
public const int foldOutBitPolar = 1 << 10;
|
||||
public const int foldOutBitHueShift = 1 << 11;
|
||||
public const int foldOutBitSaturability = 1 << 12;
|
||||
public const int foldOutBitDistanceFade = 1 << 13;
|
||||
public const int foldOutBitSoftParticles = 1 << 14;
|
||||
public const int foldOutBitMaskRotate = 1 << 15;
|
||||
public const int foldOutBitNoise = 1 << 16;
|
||||
public const int foldOutBitNoiseMap = 1 << 17;
|
||||
public const int foldOutBitNoiseMaskToggle = 1 << 18;
|
||||
public const int foldOutBitEmission = 1 << 19;
|
||||
public const int foldOutBitDistortionChoraticaberrat = 1 << 20;
|
||||
public const int foldOutDissolve = 1 << 21;
|
||||
public const int foldOutDissolveMap = 1 << 22;
|
||||
public const int foldOutProgramNoise = 1 << 23;
|
||||
public const int foldOutDissolveRampMap = 1 << 24;
|
||||
public const int foldOutDissolveMask = 1 << 25;
|
||||
public const int foldOutColorBlend = 1 << 26;
|
||||
public const int foldOutFresnel = 1 << 27;
|
||||
public const int foldOutDepthOutline = 1 << 28;
|
||||
public const int foldOutVertexOffset = 1 << 29;
|
||||
public const int foldOutParallexMapping = 1 << 30;
|
||||
// public const int foldOutBit1Portal= 1 << 31;
|
||||
|
||||
|
||||
|
||||
|
||||
public const int foldOutBit1UVModeMainTex = 1 << 0;
|
||||
public const int foldOutBit1UVModeMaskMap = 1 << 1;
|
||||
public const int foldOutBit1UVModeMaskMap2 = 1 << 2;
|
||||
public const int foldOutBit1UVModeMaskMap3 = 1 << 3;
|
||||
public const int foldOutBit1UVModeNoiseMap = 1 << 4;
|
||||
public const int foldOutBit1UVModeNoiseMaskMap = 1 << 5;
|
||||
public const int foldOutBit1UVModeEmissionMap = 1 << 6;
|
||||
public const int foldOutBit1UVModeDissolveMap = 1 << 7;
|
||||
public const int foldOutBit1UVModeDissolveMaskMap = 1 << 8;
|
||||
public const int foldOutBit1UVModeColorBlendMap = 1 << 9;
|
||||
public const int foldOutBit1UVModeVertexOffsetMap = 1 << 10;
|
||||
public const int foldOutBit1UVModeVertexOffsetMaskMap = 1 << 11;
|
||||
public const int foldOutBit1UVModeBumpTex = 1 << 12;
|
||||
public const int foldOutBit1UVModeRampColorMap = 1 << 13;
|
||||
public const int foldOutBit1UVModeProgramNoise = 1 << 14;
|
||||
|
||||
//留一些位置给以后可能会增加的贴图。
|
||||
public const int foldOutBit1Portal = 1 << 20;
|
||||
public const int foldOutBit1ZOffset = 1 << 21;
|
||||
public const int foldOutBit1CustomStencilTest = 1 << 22;
|
||||
public const int foldOutBit1TaOption = 1 << 23;
|
||||
public const int foldOutBit1MianTexContrast = 1 << 24;
|
||||
public const int foldOutBit1VertexOffsetMask = 1 << 25;
|
||||
public const int foldOutBit1MainTexColorRefine = 1 << 26;
|
||||
public const int foldOutBit1LightOption = 1 << 27;
|
||||
public const int foldOutBit1ShaderKeyword = 1 << 28;
|
||||
public const int foldOutBit1BumpTex = 1 << 29;
|
||||
|
||||
public const int foldOutBit2BumpTexToggle = 1 << 0;
|
||||
public const int foldOutBit2MatCapToggle = 1 << 1;
|
||||
public const int foldOutBit2RampColor = 1 << 2;
|
||||
public const int foldOutBit2DissolveLine = 1 << 3;
|
||||
public const int foldOutBit2BaseBackColor = 1 << 4;
|
||||
public const int foldOutBit2MaskRefine = 1 << 5;
|
||||
public const int foldOutBit2ScreenDistortAlphaRefine = 1 << 6;
|
||||
public const int foldOutBit2ProgramNoiseSimple = 1 << 7;
|
||||
public const int foldOutBit2ProgramNoiseVoronoi = 1 << 8;
|
||||
public const int foldOutBit2ColorAdjustment = 1 << 9;
|
||||
public const int foldOutBit2SharedUV = 1 << 10;
|
||||
public const int foldOutBit2SharedUVMode = 1 << 11;
|
||||
|
||||
|
||||
#region CustomDataCodes
|
||||
|
||||
public const string CustomDataFlag0Name = "_W9ParticleCustomDataFlag0";
|
||||
public const string CustomDataFlag1Name = "_W9ParticleCustomDataFlag1";
|
||||
public const string CustomDataFlag2Name = "_W9ParticleCustomDataFlag2";
|
||||
public const string CustomDataFlag3Name = "_W9ParticleCustomDataFlag3";
|
||||
public static int CustomDataFlag0Id = Shader.PropertyToID(CustomDataFlag0Name);
|
||||
public static int CustomDataFlag1Id = Shader.PropertyToID(CustomDataFlag1Name);
|
||||
public static int CustomDataFlag2Id = Shader.PropertyToID(CustomDataFlag2Name);
|
||||
public static int CustomDataFlag3Id = Shader.PropertyToID(CustomDataFlag3Name);
|
||||
|
||||
public enum CutomDataComponent
|
||||
{
|
||||
Off,
|
||||
CustomData1X,
|
||||
CustomData1Y,
|
||||
CustomData1Z,
|
||||
CustomData1W,
|
||||
CustomData2X,
|
||||
CustomData2Y,
|
||||
CustomData2Z,
|
||||
CustomData2W,
|
||||
UnKnownOrMixed = -1
|
||||
}
|
||||
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_DISSOLVE_INTENSITY = 2 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_HUESHIFT = 3 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_X = 4 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_Y = 5 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_FRESNEL_OFFSET = 6 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_CHORATICABERRAT_INTENSITY = 7 * 4;
|
||||
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_NOISE_INTENSITY = 2 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_SATURATE = 3 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_X = 4 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_Y = 5 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEXOFFSET_INTENSITY = 6 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_MASK_INTENSITY = 7 * 4;
|
||||
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_X = 2 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_Y = 3 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_X = 4 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_Y = 5 * 4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_MAINTEX_CONTRAST = 6 * 4;
|
||||
//---->这里还有一个坑可以用哦
|
||||
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_SHARED_UV_OFFSET_X = 2 * 4;
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_SHARED_UV_OFFSET_Y = 3 * 4;
|
||||
|
||||
|
||||
public const int isCustomDataBit = 1 << 3;
|
||||
public const int Data12Bit = 1 << 2; //true CustomData1 / false CustomData2
|
||||
public const int DataXYorZWBit = 1 << 1; //true xy / false zw
|
||||
public const int DataXZorYWBit = 1 << 0; //true xz / false yw
|
||||
public const int CustomData1XBit = isCustomDataBit | Data12Bit | DataXYorZWBit | DataXZorYWBit;
|
||||
public const int CustomData1YBit = isCustomDataBit | Data12Bit | DataXYorZWBit;
|
||||
public const int CustomData1ZBit = isCustomDataBit | Data12Bit | DataXZorYWBit;
|
||||
public const int CustomData1WBit = isCustomDataBit | Data12Bit;
|
||||
public const int CustomData2XBit = isCustomDataBit | DataXYorZWBit | DataXZorYWBit;
|
||||
public const int CustomData2YBit = isCustomDataBit | DataXYorZWBit;
|
||||
public const int CustomData2ZBit = isCustomDataBit | DataXZorYWBit;
|
||||
public const int CustomData2WBit = isCustomDataBit;
|
||||
|
||||
private int GetCustomDataFlagID(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0:
|
||||
return CustomDataFlag0Id;
|
||||
|
||||
case 1:
|
||||
return CustomDataFlag1Id;
|
||||
|
||||
case 2:
|
||||
return CustomDataFlag2Id;
|
||||
case 3:
|
||||
return CustomDataFlag3Id;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public string GetCustomDataFlagPropertyName(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0:
|
||||
return CustomDataFlag0Name;
|
||||
|
||||
case 1:
|
||||
return CustomDataFlag1Name;
|
||||
|
||||
case 2:
|
||||
return CustomDataFlag2Name;
|
||||
|
||||
case 3:
|
||||
return CustomDataFlag3Name;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CutomDataComponent GetCustomDataFlag(int dataBitPos, int dataIndex)
|
||||
{
|
||||
int bit = material.GetInteger(GetCustomDataFlagID(dataIndex));
|
||||
|
||||
bit = bit >> dataBitPos;
|
||||
bit &= 15; // binary 1111
|
||||
|
||||
if ((bit & isCustomDataBit) == 0)
|
||||
{
|
||||
return CutomDataComponent.Off;
|
||||
}
|
||||
else if (bit == CustomData1XBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1X;
|
||||
}
|
||||
else if (bit == CustomData1YBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1Y;
|
||||
}
|
||||
else if (bit == CustomData1ZBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1Z;
|
||||
}
|
||||
else if (bit == CustomData1WBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1W;
|
||||
}
|
||||
else if (bit == CustomData2XBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2X;
|
||||
}
|
||||
else if (bit == CustomData2YBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2Y;
|
||||
}
|
||||
else if (bit == CustomData2ZBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2Z;
|
||||
}
|
||||
else if (bit == CustomData2WBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2W;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
Debug.Log("不可能存在的情况");
|
||||
return CutomDataComponent.Off;
|
||||
|
||||
}
|
||||
|
||||
public void SetCustomDataFlag(CutomDataComponent cutomDataComponent, int dataBitPos, int dataIndex)
|
||||
{
|
||||
int bit = 0;
|
||||
switch (cutomDataComponent)
|
||||
{
|
||||
case CutomDataComponent.Off:
|
||||
bit = 0;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1X:
|
||||
bit = CustomData1XBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1Y:
|
||||
bit = CustomData1YBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1Z:
|
||||
bit = CustomData1ZBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1W:
|
||||
bit = CustomData1WBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2X:
|
||||
bit = CustomData2XBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2Y:
|
||||
bit = CustomData2YBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2Z:
|
||||
bit = CustomData2ZBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2W:
|
||||
bit = CustomData2WBit;
|
||||
break;
|
||||
}
|
||||
|
||||
bit = bit << dataBitPos;
|
||||
int clearBit = ~(15 << dataBitPos); //~ (1111 << dataBitPos)
|
||||
|
||||
int materialBit = material.GetInteger(GetCustomDataFlagID(dataIndex));
|
||||
materialBit = materialBit & clearBit;
|
||||
materialBit = materialBit | bit;
|
||||
material.SetInteger(GetCustomDataFlagID(dataIndex), materialBit);
|
||||
}
|
||||
|
||||
public bool IsCustomDataOn()
|
||||
{
|
||||
int prop0Flag = material.GetInteger(CustomDataFlag0Id);
|
||||
int prop1Flag = material.GetInteger(CustomDataFlag1Id);
|
||||
int prop2Flag = material.GetInteger(CustomDataFlag2Id);
|
||||
int prop3Flag = material.GetInteger(CustomDataFlag3Id);
|
||||
uint dataOnBit = 0b_1000_1000_1000_1000_1000_1000_1000_1000; //10001000100010001000100010001000;
|
||||
|
||||
return ((prop0Flag & dataOnBit) > 0) || ((prop1Flag & dataOnBit) > 0) || ((prop2Flag & dataOnBit) > 0) ||
|
||||
((prop3Flag & dataOnBit) > 0);
|
||||
}
|
||||
|
||||
bool CheckCustomData(int dataIndex, int flagIndex)
|
||||
{
|
||||
int flagID = 0;
|
||||
switch (flagIndex)
|
||||
{
|
||||
case 0:
|
||||
flagID = CustomDataFlag0Id;
|
||||
break;
|
||||
case 1:
|
||||
flagID = CustomDataFlag1Id;
|
||||
break;
|
||||
case 2:
|
||||
flagID = CustomDataFlag2Id;
|
||||
break;
|
||||
case 3:
|
||||
flagID = CustomDataFlag3Id;
|
||||
break;
|
||||
}
|
||||
|
||||
int flag = material.GetInteger(flagID);
|
||||
int i = 0;
|
||||
while (i < 8)
|
||||
{
|
||||
int bit = flag >> (4 * i);
|
||||
if (dataIndex == 1)
|
||||
{
|
||||
if ((bit & 0b_1000) > 0 && (bit & 0b_0100) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (dataIndex == 2)
|
||||
{
|
||||
if ((bit & 0b_1000) > 0 && (bit & 0b_0100) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsCustomData1On()
|
||||
{
|
||||
if (!IsCustomDataOn())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isCustomData1On = false;
|
||||
isCustomData1On |= CheckCustomData(1, 0);
|
||||
isCustomData1On |= CheckCustomData(1, 1);
|
||||
isCustomData1On |= CheckCustomData(1, 2);
|
||||
isCustomData1On |= CheckCustomData(1, 3);
|
||||
return isCustomData1On;
|
||||
}
|
||||
|
||||
public bool IsCustomData2On()
|
||||
{
|
||||
if (!IsCustomDataOn())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isCustomData1On = false;
|
||||
isCustomData1On |= CheckCustomData(2, 0);
|
||||
isCustomData1On |= CheckCustomData(2, 1);
|
||||
isCustomData1On |= CheckCustomData(2, 2);
|
||||
isCustomData1On |= CheckCustomData(2, 3);
|
||||
return isCustomData1On;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public const string UVModeFlag0Name = "_UVModeFlag0";
|
||||
public const string UVModeFlagType0Name = "_UVModeFlagType0";
|
||||
public static int UVModeFlag0PropID = Shader.PropertyToID(UVModeFlag0Name);
|
||||
public static int UVModeFlagType0PropID = Shader.PropertyToID(UVModeFlagType0Name);
|
||||
|
||||
public string GetUVModePropName(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0:
|
||||
return UVModeFlag0Name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum UVMode
|
||||
{
|
||||
DefaultUVChannel, //0 0b_00 modeIndex 00
|
||||
SpecialUVChannel, //1 0b_01 modeIndex 00
|
||||
PolarOrTwirl, //2 0b_10 modeIndex 00
|
||||
Cylinder, //3 0b_11 modeIndex 00
|
||||
MainTex, //0 0b_00 modeIndex 01
|
||||
ScreenUV, //1 0b_01 modeIndex 01
|
||||
WorldPos, //2 0b_10 modeIndex 01
|
||||
ObjectPos, //3 0b_11 modeIndex 01
|
||||
CommonUV, //0 0b_00 modeIndex 10
|
||||
UnknownOrMixed = -1
|
||||
}
|
||||
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MAINTEX = 0 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP = 1 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP_2 = 2 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP_3 = 3 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_NOISE_MAP = 4 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_NOISE_MASK_MAP = 5 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_EMISSION_MAP = 6 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_DISSOLVE_MAP = 7 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_DISSOLVE_MASK_MAP = 8 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_COLOR_BLEND_MAP = 9 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MAP = 10 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MASKMAP = 11 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_BUMPMAP = 12 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_RAMP_COLOR_MAP = 13 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_PROGRAM_NOISE = 14 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_SHAREDUV = 15 * 2;
|
||||
|
||||
public void GetUVModeFlagPropID(int flagIndex, out int flagID, out int flagTypeID)
|
||||
{
|
||||
switch (flagIndex)
|
||||
{
|
||||
case 0:
|
||||
flagID = UVModeFlag0PropID;
|
||||
flagTypeID = UVModeFlagType0PropID;
|
||||
return;
|
||||
}
|
||||
|
||||
flagID = 0;
|
||||
flagTypeID = 0;
|
||||
|
||||
}
|
||||
|
||||
public void SetUVMode(UVMode mode, int uvModePos, int flagIndex = 0)
|
||||
{
|
||||
GetUVModeFlagPropID(flagIndex, out int uvModeFlagPropId, out int uvModeFlagTypePropId);
|
||||
int uvModeFlag = material.GetInteger(uvModeFlagPropId);
|
||||
int uvModeFlagType = material.GetInteger(uvModeFlagTypePropId);
|
||||
|
||||
|
||||
int clearFlag = 0b_11 << uvModePos;
|
||||
clearFlag = ~ clearFlag;
|
||||
|
||||
uvModeFlag &= clearFlag;
|
||||
int modeBit = (int)mode % 4 << uvModePos;
|
||||
uvModeFlag |= modeBit;
|
||||
uvModeFlagType &= clearFlag;
|
||||
int typeBit = (int)mode / 4 << uvModePos;
|
||||
uvModeFlagType |= typeBit;
|
||||
|
||||
material.SetInteger(uvModeFlagPropId, uvModeFlag);
|
||||
material.SetInteger(uvModeFlagTypePropId, uvModeFlagType);
|
||||
}
|
||||
|
||||
public UVMode GetUVMode(int uvModePos, int flagIndex = 0)
|
||||
{
|
||||
GetUVModeFlagPropID(flagIndex, out int uvModeFlagPropId, out int uvModeFlagTypePropId);
|
||||
int uvModeFlag = material.GetInteger(uvModeFlagPropId);
|
||||
uvModeFlag = uvModeFlag >> uvModePos;
|
||||
uvModeFlag &= 0b_11;
|
||||
int uvModeFlagType = material.GetInteger(uvModeFlagTypePropId);
|
||||
uvModeFlagType = uvModeFlagType >> uvModePos;
|
||||
uvModeFlagType &= 0b_11;
|
||||
return (UVMode)(uvModeFlag + 4 * uvModeFlagType);
|
||||
}
|
||||
|
||||
public bool CheckIsUVModeOn(UVMode mode)
|
||||
{
|
||||
uint uvModeFlag0 = (uint)material.GetInteger(UVModeFlag0PropID);
|
||||
uint uvModeFlagType0 = (uint)material.GetInteger(UVModeFlagType0PropID);
|
||||
|
||||
uint uvModeflagBit = (uint)mode % 4;
|
||||
uint uvModeflagTypeBit = (uint)mode / 4;
|
||||
|
||||
bool isUvMode = false;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
uint checkflagBit = uvModeFlag0 >> (i * 2);
|
||||
checkflagBit = checkflagBit & 0b_11;
|
||||
uint checkflagTypeBit = uvModeflagTypeBit >> (i * 2);
|
||||
checkflagTypeBit = checkflagTypeBit & 0b_11;
|
||||
if (checkflagBit == uvModeflagBit && checkflagTypeBit == uvModeflagTypeBit)
|
||||
{
|
||||
isUvMode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isUvMode;
|
||||
}
|
||||
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_MAINTEX_ALPHA = 0 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP1 = 1 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP2 = 2 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP3 = 3 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_NOISE_MASK = 4 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_DISSOLVE_MAP = 5 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_DISSOLVE_MASK_MAP = 6 * 2;
|
||||
public const int FLAG_BIT_COLOR_CHANNEL_POS_0_RAMP_COLOR_MAP = 7 * 2;
|
||||
|
||||
|
||||
public enum ColorChannel
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
W,
|
||||
UnKnownOrMixedValue
|
||||
}
|
||||
|
||||
public void SetColorChanel(ColorChannel channel, int colorChannelFlagPos)
|
||||
{
|
||||
int colorChannelFlag = material.GetInteger(colorChannelFlagId);
|
||||
|
||||
int clearFlag = 0b_11 << colorChannelFlagPos;
|
||||
clearFlag = ~ clearFlag;
|
||||
|
||||
colorChannelFlag &= clearFlag;
|
||||
int channelBit = (int)channel << colorChannelFlagPos;
|
||||
colorChannelFlag |= channelBit;
|
||||
|
||||
material.SetInteger(colorChannelFlagId, colorChannelFlag);
|
||||
}
|
||||
|
||||
public ColorChannel GetColorChanel(int colorChannelFlagPos)
|
||||
{
|
||||
int colorChannelFlag = material.GetInteger(colorChannelFlagId);
|
||||
colorChannelFlag = colorChannelFlag >> colorChannelFlagPos;
|
||||
colorChannelFlag &= 0b_11;
|
||||
return (ColorChannel)colorChannelFlag;
|
||||
}
|
||||
|
||||
public const int FLAG_BIT_PNOISE_BLEND_POS_0_BASE_BLEND = 0 * 3;
|
||||
public const int FLAG_BIT_PNOISE_BLEND_POS_0_MASK = 1 * 3;
|
||||
public const int FLAG_BIT_PNOISE_BLEND_POS_0_DISSOLVE = 2 * 3;
|
||||
public const int FLAG_BIT_PNOISE_BLEND_POS_0_DISTORT = 3 * 3;
|
||||
public const int FLAG_BIT_PNOISE_BLEND_POS_0_MAINTEX = 4 * 3;
|
||||
|
||||
public enum PNoiseBlendMode
|
||||
{
|
||||
NotUse = 0,
|
||||
Multiply = 1,
|
||||
Min = 2,
|
||||
HardLight = 3,
|
||||
UnKnownOrMixedValue = -1
|
||||
|
||||
//后续看看要不要更多吧
|
||||
}
|
||||
|
||||
public void SetPNoiseBlendMode(PNoiseBlendMode mode, int pNoiseBlendModeFlagPos)
|
||||
{
|
||||
int pNoiseBlendFlag = material.GetInteger(pNoiseBlendFlagId);
|
||||
int blendMode = (int)mode;
|
||||
if (blendMode < 0) return;
|
||||
int clearFlag = 0b_111 << pNoiseBlendModeFlagPos;
|
||||
clearFlag = ~clearFlag;
|
||||
pNoiseBlendFlag &= clearFlag;
|
||||
int pNoiseBlendBit = blendMode << pNoiseBlendModeFlagPos;
|
||||
//先不考虑超过4个选项(2bit)的情况
|
||||
pNoiseBlendFlag |= pNoiseBlendBit;
|
||||
material.SetInteger(pNoiseBlendFlagId, pNoiseBlendFlag);
|
||||
}
|
||||
|
||||
public PNoiseBlendMode GetPNoiseBlendMode(int pNoiseBlendModeFlagPos)
|
||||
{
|
||||
int pNoiseBlendFlag = material.GetInteger(pNoiseBlendFlagId);
|
||||
pNoiseBlendFlag = pNoiseBlendFlag >> pNoiseBlendModeFlagPos;
|
||||
pNoiseBlendFlag &= 0b_111;
|
||||
//先不考虑超过4个选项(2bit)的情况
|
||||
return (PNoiseBlendMode)pNoiseBlendFlag;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b13c8a972207b57458dd444106acbf3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.shaders",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e3b0e6ce60c7a34094f8f9822c0b7f2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fdc89efbf4a9bf4c9449cc01f16d08a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 944a1679494774748b2936893c18c9ce
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,320 @@
|
||||
#ifndef EFFECT_FLAGS
|
||||
#define EFFECT_FLAGS
|
||||
|
||||
#define FLAG_BIT_SATURABILITY_ON (1 << 0)
|
||||
#define FLAG_BIT_PARTICLE_NOISE_CHORATICABERRAT_WITH_NOISE (1 << 1)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_FADE_ON (1 << 2)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_COLOR_ON (1 << 3)
|
||||
#define FLAG_BIT_PARTICLE_USETEXCOORD2 (1 << 4)
|
||||
#define FLAG_BIT_PARTICLE_DISTANCEFADE_ON (1 << 5)
|
||||
#define FLAG_BIT_PARTICLE_CHORATICABERRAT (1 << 6)
|
||||
#define FLAG_BIT_PARTILCE_MASKMAPROTATIONANIMATION_ON (1 << 7)
|
||||
#define FLAG_BIT_PARTICLE_POLARCOORDINATES_ON (1 << 8)
|
||||
#define FLAG_BIT_PARTICLE_UTWIRL_ON (1 << 9)
|
||||
#define FLAG_BIT_PARTICLE_LINEARTOGAMMA_ON (1 << 10)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_ON (1 << 11)
|
||||
#define FLAG_BIT_PARTICLE_NOISEMAP_NORMALIZEED_ON (1 << 12)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_COLOR_AFFETCT_BY_ALPHA (1 << 13)
|
||||
#define FLAG_BIT_PARTICLE_UIEFFECT_ON (1 << 14)
|
||||
#define FLAG_BIT_PARTICLE_UNSCALETIME_ON (1 << 15)
|
||||
#define FLAG_BIT_PARTICLE_SCRIPTABLETIME_ON (1 << 16)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1_ON (1 << 17)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_INVERT_ON (1 << 18)
|
||||
#define FLAG_BIT_HUESHIFT_ON (1 << 19)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2_ON (1 << 20)
|
||||
#define FLAG_BIT_PARTICLE_NORMALMAP_MASK_MODE (1 << 21)
|
||||
#define FLAG_BIT_PARTICLE_COLOR_ADJUSTMENT_ONLY_AFFECT_MAINTEX (1 << 22)
|
||||
#define FLAG_BIT_PARTICLE_RAMP_COLOR_MAP_MODE_ON (1 << 23)
|
||||
#define FLAG_BIT_PARTICLE_RAMP_COLOR_BLEND_ADD (1 << 24)
|
||||
#define FLAG_BIT_PARTICLE_COLOR_BLEND_ALPHA_MULTIPLY_MODE (1 << 25)
|
||||
#define FLAG_BIT_PARTICLE_DISSOLVE_RAMP_MAP (1 << 26)
|
||||
#define FLAG_BIT_PARTICLE_DISSOLVE_MASK (1 << 27)
|
||||
#define FLAG_BIT_PARTICLE_BACKCOLOR (1 << 28)
|
||||
#define FLAG_BIT_PARTICLE_COLOR_MULTI_ALPHA (1 << 29)
|
||||
#define FLAG_BIT_PARTICLE_VERTEX_OFFSET_ON (1 << 30)
|
||||
#define FLAG_BIT_PARTICLE_VERTEX_OFFSET_NORMAL_DIR (1 << 31)
|
||||
// uint _W9ParticleShaderFlags;
|
||||
|
||||
#define FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE (1 << 0)
|
||||
#define FLAG_BIT_PARTICLE_1_PARALLAX_MAPPING (1 << 1)
|
||||
#define FLAG_BIT_PARTICLE_1_MASKMAP_GRADIENT (1 << 2)
|
||||
#define FLAG_BIT_PARTICLE_1_MASKMAP_2_GRADIENT (1 << 3)
|
||||
#define FLAG_BIT_PARTICLE_1_MASKMAP_3_GRADIENT (1 << 4)
|
||||
#define FLAG_BIT_PARTICLE_1_DISSOLVE_LINE_MASK (1 << 5)
|
||||
#define FLAG_BIT_PARTICLE_1_DISSOLVE_RAMP_MULITPLY (1 << 6)
|
||||
#define FLAG_BIT_PARTICLE_1_MASK_REFINE (1 << 7)
|
||||
#define FLAG_BIT_PARTICLE_1_SCREEN_DISTORT_ALPHA_REFINE (1 << 8)
|
||||
#define FLAG_BIT_PARTICLE_1_IGNORE_VERTEX_COLOR (1 << 9)
|
||||
#define FLAG_BIT_PARTICLE_1_PROGRAM_NOISE_SIMPLE (1 << 10)
|
||||
#define FLAG_BIT_PARTICLE_1_DISSOVLE_USE_RAMP (1 << 11)
|
||||
#define FLAG_BIT_PARTICLE_1_MASK_MAP2 (1 << 12)
|
||||
#define FLAG_BIT_PARTICLE_1_MASK_MAP3 (1 << 13)
|
||||
#define FLAG_BIT_PARTICLE_1_NOISE_MASKMAP (1 << 14)
|
||||
#define FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER (1 << 15)
|
||||
#define FLAG_BIT_PARTICLE_1_PROGRAM_NOISE_VORONOI (1 << 16)
|
||||
#define FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE (1 << 17)
|
||||
#define FLAG_BIT_PARTICLE_1_USE_TEXCOORD1 (1 << 18)
|
||||
#define FLAG_BIT_PARTICLE_1_USE_TEXCOORD2 (1 << 19)
|
||||
#define FLAG_BIT_PARTICLE_1_CYLINDER_CORDINATE (1 << 20)
|
||||
#define FLAG_BIT_PARTICLE_1_UV_FROM_MESH (1 << 21)
|
||||
#define FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE (1 << 22)
|
||||
#define FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM (1 << 23)
|
||||
#define FLAG_BIT_PARTICLE_1_MAINTEX_CONTRAST (1 << 24)
|
||||
#define FLAG_BIT_PARTICLE_1_VERTEXOFFSET_START_FROM_ZERO (1 << 25)
|
||||
#define FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP (1 << 26)
|
||||
#define FLAG_BIT_PARTICLE_1_MAINTEX_COLOR_REFINE (1 << 27)
|
||||
#define FLAG_BIT_PARTICLE_1_BUMP_TEX_UV_FOLLOW_MAINTEX (1 << 28)
|
||||
#define FLAG_BIT_PARTICLE_1_SIXWAY_RAMPMAP (1 << 29)
|
||||
#define FLAG_BIT_PARTICLE_1_MATCAP_MULTY_MODE (1 << 30)
|
||||
|
||||
|
||||
//WrapMode不能够超过16位(因为会占用x和x+16两个bit位)
|
||||
#define FLAG_BIT_WRAPMODE_BASEMAP (1 << 0)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP (1 << 1)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP2 (1 << 2)
|
||||
#define FLAG_BIT_WRAPMODE_NOISEMAP (1 << 3)
|
||||
#define FLAG_BIT_WRAPMODE_EMISSIONMAP (1 << 4)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_MAP (1 << 5)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP (1 << 6)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP (1 << 7)
|
||||
#define FLAG_BIT_WRAPMODE_COLORBLENDMAP (1 << 8)
|
||||
#define FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP (1 << 9)
|
||||
#define FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP (1 << 10)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP3 (1 << 11)
|
||||
#define FLAG_BIT_WRAPMODE_NOISE_MASKMAP (1 << 12)
|
||||
#define FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP (1 << 13)
|
||||
#define FLAG_BIT_WRAPMODE_BUMPTEX (1 << 14)
|
||||
#define FLAG_BIT_WRAPMODE_RAMP_COLOR_MAP (1 << 15)
|
||||
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_DISSOLVE_INTENSITY (2*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_HUESHIFT (3*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_X (4*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_Y (5*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_FRESNEL_OFFSET (6*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_CHORATICABERRAT_INTENSITY (7*4)
|
||||
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_NOISE_INTENSITY (2*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_SATURATE (3*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_X (4*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_Y (5*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEXOFFSET_INTENSITY (6*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_MASK_INTENSITY (7*4)
|
||||
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_X (2*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_Y (3*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_X (4*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_Y (5*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_MAINTEX_CONTRAST (6*4)
|
||||
//---->这里还有一个坑可以用哦
|
||||
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_X (0*4)
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_Y (1*4)
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_SHARED_UV_OFFSET_X (2*4)
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_SHARED_UV_OFFSET_Y (3*4)
|
||||
|
||||
#define isCustomDataBit (1 << 3)
|
||||
#define Data12Bit (1 << 2)
|
||||
#define DataXYorZWBit (1 << 1)
|
||||
#define DataXZorYWBit (1 << 0)
|
||||
|
||||
#define FLAG_BIT_UVMODE_POS_0_MAINTEX (0*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP (1*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP_2 (2*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP_3 (3*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_NOISE_MAP (4*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_NOISE_MASK_MAP (5*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_EMISSION_MAP (6*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_DISSOLVE_MAP (7*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_DISSOLVE_MASK_MAP (8*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_COLOR_BLEND_MAP (9*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MAP (10*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MASKMAP (11*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_BUMPTEX (12*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_RAMP_COLOR_MAP (13*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_PROGRAM_NOISE (14*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_SHAREDUV (15*2)
|
||||
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_MAINTEX_ALPHA (0*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP1 (1*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP2 (2*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_MASKMAP3 (3*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_NOISE_MASK (4*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_DISSOLVE_MAP (5*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_DISSOLVE_MASK_MAP (6*2)
|
||||
#define FLAG_BIT_COLOR_CHANNEL_POS_0_RAMP_COLOR_MAP (7*2)
|
||||
|
||||
float GetCustomData(uint flagProperty,int flagPos,float orignValue,half4 cutstomData1,half4 customData2)
|
||||
{
|
||||
uint bit = flagProperty >> flagPos;
|
||||
|
||||
// bit &= 15;// binary 1111 这一步可能是没必要的。
|
||||
UNITY_BRANCH
|
||||
if((bit & isCustomDataBit) == 0)
|
||||
{
|
||||
return orignValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
half4 customData = 0;
|
||||
if((bit & Data12Bit))
|
||||
{
|
||||
customData = cutstomData1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
customData = customData2;
|
||||
}
|
||||
|
||||
if(bit & DataXYorZWBit)
|
||||
{
|
||||
if(bit & DataXZorYWBit)
|
||||
{
|
||||
return customData.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return customData.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bit & DataXZorYWBit)
|
||||
{
|
||||
return customData.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
return customData.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 999;//提示错误
|
||||
}
|
||||
|
||||
|
||||
struct BaseUVs
|
||||
{
|
||||
float2 defaultUVChannel;
|
||||
float2 specialUVChannel;
|
||||
float2 uvAfterTwirlPolar;
|
||||
float2 cylinderUV;
|
||||
float2 mainTexUV;
|
||||
float2 screenUV;
|
||||
float2 worldPosUV;
|
||||
float2 objectPosUV;
|
||||
float2 sharedUV;
|
||||
};
|
||||
|
||||
float2 GetUVByUVMode(uint flagProperty,uint flagTypeProperty,int flagPos,BaseUVs baseUVs)
|
||||
{
|
||||
flagProperty = flagProperty >> flagPos;
|
||||
flagProperty &= 3;
|
||||
flagTypeProperty = flagTypeProperty >> flagPos;
|
||||
flagTypeProperty &= 3;
|
||||
switch (flagTypeProperty)
|
||||
{
|
||||
case 0:
|
||||
switch(flagProperty)
|
||||
{
|
||||
case 0:
|
||||
return baseUVs.defaultUVChannel;
|
||||
case 1:
|
||||
return baseUVs.specialUVChannel;
|
||||
case 2:
|
||||
return baseUVs.uvAfterTwirlPolar;
|
||||
case 3:
|
||||
return baseUVs.cylinderUV;
|
||||
default:
|
||||
return baseUVs.defaultUVChannel;
|
||||
}
|
||||
case 1:
|
||||
switch(flagProperty)
|
||||
{
|
||||
case 0:
|
||||
return baseUVs.mainTexUV;
|
||||
case 1:
|
||||
return baseUVs.screenUV;
|
||||
case 2:
|
||||
return baseUVs.worldPosUV;
|
||||
case 3:
|
||||
return baseUVs.objectPosUV;
|
||||
default:
|
||||
return baseUVs.defaultUVChannel;
|
||||
}
|
||||
case 2:
|
||||
switch(flagProperty)
|
||||
{
|
||||
case 0:
|
||||
return baseUVs.sharedUV;
|
||||
default:
|
||||
return baseUVs.defaultUVChannel;
|
||||
}
|
||||
default:
|
||||
return baseUVs.defaultUVChannel;
|
||||
}
|
||||
}
|
||||
|
||||
half Blend_HardLight(half Base, half Blend)
|
||||
{
|
||||
half result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
|
||||
half result2 = 2.0 * Base * Blend;
|
||||
half zeroOrOne = step(Blend, 0.5);
|
||||
half Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
|
||||
return Out;
|
||||
}
|
||||
|
||||
#define FLAG_BIT_PNOISE_BLEND_POS_0_BASE_BLEND (0*3)
|
||||
#define FLAG_BIT_PNOISE_BLEND_POS_0_MASK (1*3)
|
||||
#define FLAG_BIT_PNOISE_BLEND_POS_0_DISSOLVE (2*3)
|
||||
#define FLAG_BIT_PNOISE_BLEND_POS_0_DISTORT (3*3)
|
||||
#define FLAG_BIT_PNOISE_BLEND_POS_0_MAINTEX (4*3)
|
||||
|
||||
half BlendPNoise(uint flagProperty,int flagPos,half source,half pNoise,half opacity)
|
||||
{
|
||||
flagProperty = flagProperty >> flagPos;
|
||||
flagProperty &= 7;
|
||||
switch(flagProperty)
|
||||
{
|
||||
case 0:
|
||||
return source;
|
||||
case 1:
|
||||
return lerp(source,pNoise*source,opacity);
|
||||
case 2:
|
||||
return lerp(source,min(pNoise,source),opacity);
|
||||
case 3:
|
||||
return lerp(source,Blend_HardLight(source,pNoise),opacity);
|
||||
default:
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
//ForDistort
|
||||
half2 BlendPNoise(uint flagProperty,int flagPos,half2 source,half2 pNoise,half opacity)
|
||||
{
|
||||
flagProperty = flagProperty >> flagPos;
|
||||
flagProperty &= 7;
|
||||
switch(flagProperty)
|
||||
{
|
||||
case 0:
|
||||
return source;
|
||||
case 1:
|
||||
return lerp(source,pNoise*source,opacity);
|
||||
case 2:
|
||||
return lerp(source,min(pNoise,source),opacity);
|
||||
case 3:
|
||||
return lerp(source,Blend_HardLight(source,pNoise),opacity);
|
||||
default:
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4918b275ae4dce948a5cedc6f3612066
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9187c1d488f62d9458d6ce67858a43b3
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03da5256bb8bf0b4496b10ee6b449be4
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,357 @@
|
||||
#ifndef SIX_WAY_SMOKE_LIT_HLSL
|
||||
#define SIX_WAY_SMOKE_LIT_HLSL
|
||||
//这部分尽量借鉴 UnityEditor.VFX.HDRP.SixWaySmokeLit
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "ParticlesUnlitInputNew.hlsl"
|
||||
|
||||
// Generated from UnityEditor.VFX.HDRP.SixWaySmokeLit+BSDFData
|
||||
// PackingRules = Exact
|
||||
struct BSDFData
|
||||
{
|
||||
uint materialFeatures;
|
||||
float absorptionRange;
|
||||
real4 diffuseColor;
|
||||
real3 fresnel0;
|
||||
real ambientOcclusion;
|
||||
float3 normalWS;
|
||||
float4 tangentWS;
|
||||
real3 geomNormalWS;
|
||||
real3 rigRTBk;
|
||||
real3 rigLBtF;
|
||||
real3 bakeDiffuseLighting0;//rigRTBk.x
|
||||
real3 bakeDiffuseLighting1;//rigRTBk.y
|
||||
real3 bakeDiffuseLighting2;// bsdfData.tangentWS.w > 0.0f ? rigRTBk.z : rigLBtF.z
|
||||
real3 backBakeDiffuseLighting0;//rigLBtF.x
|
||||
real3 backBakeDiffuseLighting1;//rigLBtF.y
|
||||
real3 backBakeDiffuseLighting2;// bsdfData.tangentWS.w > 0.0f ? rigLBtF.z : rigRTBk.z
|
||||
|
||||
//-----NBShaders-----
|
||||
real3 emission;
|
||||
real emissionInput;//NegativeTex.a
|
||||
real alpha;//PositiveTex.a
|
||||
|
||||
};
|
||||
|
||||
#define ABSORPTION_EPSILON max(REAL_MIN, 1e-5)
|
||||
|
||||
real3 ComputeDensityScales(real3 absorptionColor)
|
||||
{
|
||||
absorptionColor.rgb = max(ABSORPTION_EPSILON, absorptionColor.rgb);
|
||||
|
||||
// Empirical value used to parametrize absorption from color
|
||||
const real absorptionStrength = 0.2f;
|
||||
return 1.0f + log2(absorptionColor.rgb) / log2(absorptionStrength);
|
||||
}
|
||||
|
||||
real3 GetTransmissionWithAbsorption(real transmission, real4 absorptionColor, real absorptionRange)
|
||||
{
|
||||
#if defined(VFX_SIX_WAY_ABSORPTION)
|
||||
real3 densityScales = ComputeDensityScales(absorptionColor.rgb);
|
||||
|
||||
#ifdef VFX_BLENDMODE_PREMULTIPLY
|
||||
absorptionRange *= (absorptionColor.a > 0) ? absorptionColor.a : 1.0f;
|
||||
#endif
|
||||
|
||||
// real3 outTransmission = GetTransmissionWithAbsorption(transmission, densityScales, absorptionRange);
|
||||
real3 outTransmission = pow(saturate(transmission / absorptionRange), densityScales);
|
||||
outTransmission *= absorptionRange;
|
||||
|
||||
return outTransmission;
|
||||
#else
|
||||
return transmission.xxx * absorptionColor.rgb; // simple multiply
|
||||
#endif
|
||||
}
|
||||
|
||||
void ModifyBakedDiffuseLighting(BSDFData bsdfData, inout float3 bakeDiffuseLighting)
|
||||
{
|
||||
bakeDiffuseLighting = 0;
|
||||
|
||||
// Scale to be energy conserving: Total energy = 4*pi; divided by 6 directions
|
||||
float scale = 4.0f * PI / 6.0f;
|
||||
|
||||
float3 frontBakeDiffuseLighting = bsdfData.tangentWS.w > 0.0f ? bsdfData.bakeDiffuseLighting2 : bsdfData.backBakeDiffuseLighting2;
|
||||
float3 backBakeDiffuseLighting = bsdfData.tangentWS.w > 0.0f ? bsdfData.backBakeDiffuseLighting2 : bsdfData.bakeDiffuseLighting2;
|
||||
|
||||
float3x3 bakeDiffuseLightingMat;
|
||||
bakeDiffuseLightingMat[0] = bsdfData.bakeDiffuseLighting0;
|
||||
bakeDiffuseLightingMat[1] = bsdfData.bakeDiffuseLighting1;
|
||||
bakeDiffuseLightingMat[2] = frontBakeDiffuseLighting;
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigRTBk.x, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[0];
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigRTBk.y, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[1];
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigRTBk.z, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[2];
|
||||
|
||||
bakeDiffuseLightingMat[0] = bsdfData.backBakeDiffuseLighting0;
|
||||
bakeDiffuseLightingMat[1] = bsdfData.backBakeDiffuseLighting1;
|
||||
bakeDiffuseLightingMat[2] = backBakeDiffuseLighting;
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigLBtF.x, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[0];
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigLBtF.y, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[1];
|
||||
bakeDiffuseLighting += GetTransmissionWithAbsorption(bsdfData.rigLBtF.z, bsdfData.diffuseColor, bsdfData.absorptionRange) * bakeDiffuseLightingMat[2];
|
||||
|
||||
bakeDiffuseLighting *= scale;
|
||||
|
||||
}
|
||||
|
||||
//世界空间到切线空间方向转换
|
||||
float3 TransformToLocalFrame(float3 L, BSDFData bsdfData)
|
||||
{
|
||||
float3 zVec = -bsdfData.normalWS;
|
||||
float3 xVec = bsdfData.tangentWS.xyz;
|
||||
float3 yVec = -cross(zVec, xVec) * bsdfData.tangentWS.w;//原代码没有负值,实际测试需要负值
|
||||
float3x3 tbn = float3x3(xVec, yVec, zVec);
|
||||
return mul(tbn, L);
|
||||
}
|
||||
|
||||
CBSDF EvaluateBSDF(float3 L, BSDFData bsdfData)
|
||||
{
|
||||
CBSDF cbsdf;
|
||||
ZERO_INITIALIZE(CBSDF, cbsdf);
|
||||
|
||||
float3 dir = TransformToLocalFrame(L, bsdfData);
|
||||
float3 weights = dir >= 0 ? bsdfData.rigRTBk.xyz : bsdfData.rigLBtF.xyz;
|
||||
float3 sqrDir = dir*dir;
|
||||
|
||||
cbsdf.diffR = GetTransmissionWithAbsorption(dot(sqrDir, weights), bsdfData.diffuseColor, bsdfData.absorptionRange);
|
||||
|
||||
return cbsdf;
|
||||
}
|
||||
|
||||
|
||||
//这一步最好在面板上做完
|
||||
half GetAbsorptionRange(float absorptionStrenth)
|
||||
{
|
||||
return INV_PI + saturate(absorptionStrenth) * (1 - INV_PI);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---------NBShaderUtility-----------
|
||||
|
||||
//UseInVerTex
|
||||
void GetSixWayBakeDiffuseLight(real3 normalWS,real3 tangentWS,real3 biTangentWS,
|
||||
inout half3 bakeDiffuseLighting0,inout half3 bakeDiffuseLighting1,inout half3 bakeDiffuseLighting2,
|
||||
inout half3 backBakeDiffuseLighting0,inout half3 backBakeDiffuseLighting1,inout half3 backBakeDiffuseLighting2)
|
||||
{
|
||||
bakeDiffuseLighting0 = SampleSHVertex(tangentWS);
|
||||
bakeDiffuseLighting1 = SampleSHVertex(biTangentWS);
|
||||
bakeDiffuseLighting2 = SampleSHVertex(-normalWS);
|
||||
backBakeDiffuseLighting0 = SampleSHVertex(-tangentWS);
|
||||
backBakeDiffuseLighting1 = SampleSHVertex(-biTangentWS);
|
||||
backBakeDiffuseLighting2 = SampleSHVertex(normalWS);
|
||||
}
|
||||
|
||||
LightingData CreateSixWayLightingData(InputData inputData, half3 emission)
|
||||
{
|
||||
LightingData lightingData;
|
||||
|
||||
lightingData.giColor = inputData.bakedGI;
|
||||
lightingData.emissionColor = emission;
|
||||
lightingData.vertexLightingColor = 0;
|
||||
lightingData.mainLightColor = 0;
|
||||
lightingData.additionalLightsColor = 0;
|
||||
|
||||
return lightingData;
|
||||
}
|
||||
|
||||
void GetSixWayEmission(inout BSDFData bsdfData,Texture2D rampMap,half4 emissionColor,bool isRampMap)
|
||||
{
|
||||
float input = pow(bsdfData.emissionInput,_SixWayInfo.y);
|
||||
half3 emission = emissionColor * emissionColor.a;
|
||||
if (isRampMap)
|
||||
{
|
||||
half4 rampSample = rampMap.Sample(sampler_linear_clamp,half2(input,0.5));
|
||||
emission = emission * rampSample * rampSample.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
emission *= input;
|
||||
}
|
||||
bsdfData.emission = emission;
|
||||
}
|
||||
|
||||
half3 LightingSixWay(Light light,InputData inputData, BSDFData bsdfData)
|
||||
{
|
||||
half3 cbsdf_R = EvaluateBSDF(light.direction,bsdfData).diffR;
|
||||
half3 radiance = light.color * light.distanceAttenuation * light.shadowAttenuation;
|
||||
return PI * cbsdf_R * radiance;
|
||||
}
|
||||
|
||||
|
||||
//光照流程--->原型为UniversalFragmentBlinnPhong
|
||||
half4 UniversalFragmentSixWay(InputData inputData,BSDFData bsdfData)
|
||||
{
|
||||
// #if defined(DEBUG_DISPLAY)
|
||||
// half4 debugColor;
|
||||
//
|
||||
// if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor))
|
||||
// {
|
||||
// return debugColor;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
half4 shadowMask = CalculateShadowMask(inputData);
|
||||
// AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData, surfaceData);
|
||||
AmbientOcclusionFactor aoFactor;
|
||||
aoFactor.directAmbientOcclusion = 1;
|
||||
aoFactor.indirectAmbientOcclusion = 1;
|
||||
Light mainLight = GetMainLight(inputData, shadowMask, aoFactor);
|
||||
|
||||
// MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, aoFactor);
|
||||
|
||||
// inputData.bakedGI *= surfaceData.albedo;
|
||||
|
||||
// LightingData lightingData = CreateLightingData(inputData, surfaceData);
|
||||
LightingData lightingData = CreateSixWayLightingData(inputData,bsdfData.emission);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.mainLightColor += LightingSixWay(mainLight, inputData, bsdfData);
|
||||
}
|
||||
|
||||
#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 += LightingSixWay(light, inputData, bsdfData);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.additionalLightsColor += LightingSixWay(light, inputData, bsdfData);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
#endif
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS_VERTEX)
|
||||
lightingData.vertexLightingColor += inputData.vertexLighting * surfaceData.albedo;
|
||||
#endif
|
||||
|
||||
return CalculateFinalColor(lightingData, bsdfData.alpha);
|
||||
}
|
||||
half3 LightingHalfLambert(half3 lightColor, half3 lightDir, half3 normal)
|
||||
{
|
||||
half NdotL = saturate(dot(normal, lightDir));
|
||||
NdotL = NdotL*0.5 + 0.5;
|
||||
return lightColor * NdotL;
|
||||
}
|
||||
half3 CalculateHalfLambertBlinnPhong(Light light, InputData inputData, SurfaceData surfaceData)
|
||||
{
|
||||
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
half3 lightDiffuseColor = LightingHalfLambert(attenuatedLightColor, light.direction, inputData.normalWS);
|
||||
|
||||
half3 lightSpecularColor = half3(0,0,0);
|
||||
#if defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
|
||||
half smoothness = exp2(10 * surfaceData.smoothness + 1);
|
||||
|
||||
lightSpecularColor += LightingSpecular(attenuatedLightColor, light.direction, inputData.normalWS, inputData.viewDirectionWS, half4(surfaceData.specular, 1), smoothness);
|
||||
#endif
|
||||
|
||||
#if _ALPHAPREMULTIPLY_ON
|
||||
return lightDiffuseColor * surfaceData.albedo * surfaceData.alpha + lightSpecularColor;
|
||||
#else
|
||||
return lightDiffuseColor * surfaceData.albedo + lightSpecularColor;
|
||||
#endif
|
||||
}
|
||||
half4 UniversalFragmentHalfLambert(InputData inputData, half3 diffuse, half4 specularGloss, half smoothness, half3 emission, half alpha, half3 normalTS)
|
||||
{
|
||||
|
||||
SurfaceData surfaceData;
|
||||
|
||||
surfaceData.albedo = diffuse;
|
||||
surfaceData.alpha = alpha;
|
||||
surfaceData.emission = emission;
|
||||
surfaceData.metallic = 0;
|
||||
surfaceData.occlusion = 1;
|
||||
surfaceData.smoothness = smoothness;
|
||||
surfaceData.specular = specularGloss.rgb;
|
||||
surfaceData.clearCoatMask = 0;
|
||||
surfaceData.clearCoatSmoothness = 1;
|
||||
surfaceData.normalTS = normalTS;
|
||||
|
||||
|
||||
// #if defined(DEBUG_DISPLAY)
|
||||
// half4 debugColor;
|
||||
//
|
||||
// if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor))
|
||||
// {
|
||||
// return debugColor;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
half4 shadowMask = CalculateShadowMask(inputData);
|
||||
AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData, surfaceData);
|
||||
Light mainLight = GetMainLight(inputData, shadowMask, aoFactor);
|
||||
|
||||
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, aoFactor);
|
||||
|
||||
inputData.bakedGI *= surfaceData.albedo;
|
||||
|
||||
LightingData lightingData = CreateLightingData(inputData, surfaceData);
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.mainLightColor += CalculateHalfLambertBlinnPhong(mainLight, inputData, surfaceData);
|
||||
}
|
||||
|
||||
#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 += CalculateBlinnPhong(light, inputData, surfaceData);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightingData.additionalLightsColor += CalculateHalfLambertBlinnPhong(light, inputData, surfaceData);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
#endif
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS_VERTEX)
|
||||
lightingData.vertexLightingColor += inputData.vertexLighting * surfaceData.albedo;
|
||||
#endif
|
||||
|
||||
return CalculateFinalColor(lightingData, surfaceData.alpha);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70e94bdedafe40bfb7f8e77cdc4bef0f
|
||||
timeCreated: 1751704445
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7184a95c20fc1a441a8815af4c795ccd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !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: 9177edf81a5b2354490ec4d66c4c069d, type: 3}
|
||||
m_Name: StencilConfig
|
||||
m_EditorClassIdentifier: Assembly-CSharp-Editor:stencilTestHelper:StencilValuesConfig
|
||||
Config:
|
||||
- key: ParticleBaseDefault
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 0
|
||||
Comp: 8
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: Disturbance
|
||||
Values:
|
||||
DefaultQueue: 3000
|
||||
Ref: 0
|
||||
Comp: 8
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticalBasePortal
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 200
|
||||
Comp: 3
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticalBasePortalMask
|
||||
Values:
|
||||
DefaultQueue: 2000
|
||||
Ref: 200
|
||||
Comp: 8
|
||||
Pass: 2
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticleBaseDecal
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 2
|
||||
Comp: 7
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticleWithoutPlayer
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 5
|
||||
Comp: 5
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7093501998f1b24483fa6c8eddcf8fb
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user