[Add] All in one shader

This commit is contained in:
2026-02-23 22:01:07 +07:00
parent ec0aa86ac2
commit 4f942cd7c0
806 changed files with 401510 additions and 33 deletions
@@ -0,0 +1,9 @@
using UnityEngine;
namespace AllIn13DShader
{
public class ConversionConfig : ScriptableObject
{
public ConversionProperty[] conversionProperties;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 466e422414ab2d84fa4f40d216c7e612
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs
uploadId: 865720
@@ -0,0 +1,17 @@
using UnityEngine;
namespace AllIn13DShader
{
public class ConversionProperty : ScriptableObject
{
public ConversionPropertyType propertyType;
public string propertyName;
[Header("Effect")]
public string belongingToEffect;
public bool requiredProperty;
[Header("Alternative Names")]
public string[] alternativeNames;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 95c835d611027ef4e8f42f58386c1d3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs
uploadId: 865720
@@ -0,0 +1,10 @@
namespace AllIn13DShader
{
public enum ConversionPropertyType
{
FLOAT,
TEXTURE,
COLOR,
VECTOR,
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f4436880cfef3ea4bab5b36df4eb5345
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs
uploadId: 865720
@@ -0,0 +1,199 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn13DShader
{
public class ConverterGeneral
{
protected Material from;
protected Material target;
protected ConversionConfig conversionConfig;
protected PropertiesConfigCollection propertiesConfigCollection;
protected PropertiesConfig propertiesConfig;
public virtual void ApplyConversion(Material from, Material target)
{
this.from = from;
this.target = target;
this.conversionConfig = EditorUtils.FindAssetByName<ConversionConfig>("ConversionConfig");
this.propertiesConfigCollection = EditorUtils.FindAssetByName<PropertiesConfigCollection>("PropertiesConfigCollection");
this.propertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(target.shader);
for (int i = 0; i < conversionConfig.conversionProperties.Length; i++)
{
ConversionProperty conversionProperty = conversionConfig.conversionProperties[i];
bool propertiveActive = false;
ApplyConversionProperty(conversionProperty, from, target, ref propertiveActive);
if (!string.IsNullOrEmpty(conversionProperty.belongingToEffect) && conversionProperty.requiredProperty && propertiveActive)
{
AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(conversionProperty.belongingToEffect);
EnableEffect(effectConfig);
}
}
target.renderQueue = from.renderQueue;
}
protected void SetEnableEffect(string effectID, bool enabled)
{
AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(effectID);
if (enabled)
{
EnableEffect(effectConfig);
}
else
{
DisableEffect(effectConfig);
}
}
protected void EnableEffect(AllIn13DEffectConfig effectConfig)
{
if (effectConfig.keywords.Count == 1)
{
target.EnableKeyword(effectConfig.keywords[0].keyword);
target.SetFloat(effectConfig.keywordPropertyName, 1f);
}
}
protected void DisableEffect(string effectID)
{
AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(effectID);
DisableEffect(effectConfig);
}
protected void DisableEffect(AllIn13DEffectConfig effectConfig)
{
for (int i = 0; i < effectConfig.keywords.Count; i++)
{
target.DisableKeyword(effectConfig.keywords[i].keyword);
}
target.SetFloat(effectConfig.keywordPropertyName, 0f);
}
protected void EnablePBR()
{
AllIn13DEffectConfig shadingModelEffect = propertiesConfig.FindEffectConfigByID("SHADINGMODEL");
DisableEffect(shadingModelEffect);
string pbrKeyword = shadingModelEffect.keywords[1].keyword;
target.EnableKeyword(pbrKeyword);
target.SetFloat("_ShadingModel", 1.0f);
}
protected void EnableLightModelClassic()
{
AllIn13DEffectConfig lightModelEffect = propertiesConfig.FindEffectConfigByID("LIGHTMODEL");
DisableEffect(lightModelEffect);
string lightModelClassicKeyword = lightModelEffect.keywords[1].keyword;
target.EnableKeyword(lightModelClassicKeyword);
target.SetFloat(lightModelEffect.keywordPropertyName, 1.0f);
}
protected void EnableSpecularClassic()
{
AllIn13DEffectConfig specularModelEffect = propertiesConfig.FindEffectConfigByID("SPECULARMODEL");
DisableEffect(specularModelEffect);
string specularModelClassicKeyword = specularModelEffect.keywords[1].keyword;
target.EnableKeyword(specularModelClassicKeyword);
target.SetFloat(specularModelEffect.keywordPropertyName, 1.0f);
}
protected void SetBlendSrc(UnityEngine.Rendering.BlendMode blendMode)
{
target.SetInt("_BlendSrc", (int)blendMode);
}
protected void SetBlendDst(UnityEngine.Rendering.BlendMode blendMode)
{
target.SetInt("_BlendDst", (int)blendMode);
}
protected void SetAlphaPreset()
{
target.SetFloat("_RenderPreset", 2);
}
protected void SetOpaquePreset()
{
target.SetFloat("_RenderPreset", 1);
}
protected void ApplyConversionProperty(ConversionProperty conversionProperty, Material from, Material target, ref bool propertyActive)
{
string propertyNameFrom = string.Empty;
string propertyNameTarget = conversionProperty.propertyName;
if (from.HasProperty(conversionProperty.propertyName))
{
propertyNameFrom = conversionProperty.propertyName;
}
else
{
for (int i = 0; i < conversionProperty.alternativeNames.Length; i++)
{
if (from.HasProperty(conversionProperty.alternativeNames[i]))
{
propertyNameFrom = conversionProperty.alternativeNames[i];
break;
}
}
}
if (!string.IsNullOrEmpty(propertyNameFrom))
{
switch (conversionProperty.propertyType)
{
case ConversionPropertyType.TEXTURE:
Texture texValue = from.GetTexture(propertyNameFrom);
Vector2 texOffset = from.GetTextureOffset(propertyNameFrom);
Vector2 texScale = from.GetTextureScale(propertyNameFrom);
target.SetTexture(propertyNameTarget, texValue);
target.SetTextureOffset(propertyNameTarget, texOffset);
target.SetTextureScale(propertyNameTarget, texScale);
propertyActive = texValue != null;
break;
case ConversionPropertyType.FLOAT:
float floatValue = from.GetFloat(propertyNameFrom);
target.SetFloat(propertyNameTarget, floatValue);
propertyActive = true;
break;
case ConversionPropertyType.COLOR:
Color colorValue = from.GetColor(propertyNameFrom);
target.SetColor(propertyNameTarget, colorValue);
propertyActive = true;
break;
case ConversionPropertyType.VECTOR:
Vector4 vectorValue = from.GetVector(propertyNameFrom);
target.SetVector(propertyNameTarget, vectorValue);
propertyActive = true;
break;
}
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: fe8d92d4b6d87fd4892ac9b7eaa2bd37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs
uploadId: 865720
@@ -0,0 +1,47 @@
using UnityEngine;
namespace AllIn13DShader
{
public class ConverterStandard : ConverterGeneral
{
public override void ApplyConversion(Material from, Material target)
{
base.ApplyConversion(from, target);
DisableEffect("ALPHA_CUTOFF");
bool emissionEffectEnabled = from.IsKeywordEnabled("_EMISSION");
SetEnableEffect("EMISSION", emissionEffectEnabled);
bool normalMapEffectEnabled = from.IsKeywordEnabled("_NORMALMAP");
SetEnableEffect("NORMAL_MAP", normalMapEffectEnabled);
EnableLightModelClassic();
EnablePBR();
target.SetFloat("_ReflectionsAtten", 1.0f);
bool specularEnabled = !from.IsKeywordEnabled("_SPECULARHIGHLIGHTS_OFF");
if (specularEnabled)
{
EnableSpecularClassic();
target.SetFloat("_SpecularAtten", 1.0f);
}
else
{
DisableEffect("SPECULARMODEL");
}
DisableEffect("RIM_LIGHTING");
//Blending Mode
ConvertBlending();
}
protected virtual void ConvertBlending()
{
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: e0584ca1f69659048b2a800ed4d52cd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs
uploadId: 865720
@@ -0,0 +1,29 @@
using UnityEngine.Rendering;
namespace AllIn13DShader
{
public class ConverterStandardBIRP : ConverterStandard
{
protected override void ConvertBlending()
{
if (from.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON"))
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.One);
SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
SetAlphaPreset();
}
else if (from.IsKeywordEnabled("_ALPHABLEND_ON"))
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.SrcAlpha);
SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
SetAlphaPreset();
}
else
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.One);
SetBlendDst(UnityEngine.Rendering.BlendMode.Zero);
SetOpaquePreset();
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1a12bb5293276e74daff29adac53e710
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs
uploadId: 865720
@@ -0,0 +1,32 @@
using UnityEngine.Rendering;
namespace AllIn13DShader
{
public class ConverterURPLit : ConverterStandard
{
protected override void ConvertBlending()
{
if (from.IsKeywordEnabled("_SURFACE_TYPE_TRANSPARENT"))
{
if (from.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON"))
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.One);
SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
}
else
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.SrcAlpha);
SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
}
SetAlphaPreset();
}
else
{
SetBlendSrc(UnityEngine.Rendering.BlendMode.One);
SetBlendDst(UnityEngine.Rendering.BlendMode.Zero);
SetOpaquePreset();
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: eda76fc9b5ca6914ea7ea1048cecba9d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs
uploadId: 865720
@@ -0,0 +1,248 @@
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace AllIn13DShader
{
public static class MaterialConverterTool
{
private const int OVERRIDE = 0;
private const int CANCEL = 1;
private const int KEEP_ORIGINALS = 2;
[MenuItem(itemName: "Assets/AllIn1/Convert ALL materials to AllIn13DShader", isValidateFunction: true)]
public static bool ValidateBatchConvert()
{
bool res = true;
Object[] selectedAssets = Selection.GetFiltered<Object>(SelectionMode.Assets);
foreach (Object asset in selectedAssets)
{
string path = AssetDatabase.GetAssetPath(asset);
bool isValidFolder = AssetDatabase.IsValidFolder(path);
Material mat = AssetDatabase.LoadAssetAtPath<Material>(path);
bool isMaterial = mat != null;
res = res && (isValidFolder || isMaterial);
}
return res;
}
[MenuItem(itemName: "Assets/AllIn1/Convert ALL materials to AllIn13DShader")]
public static void BatchConvert()
{
Object[] selectedAssets = Selection.GetFiltered<Object>(SelectionMode.Assets);
HashSet<string> pathsToConvert = CollectPathsToConvert(selectedAssets);
string title = "Converting materials to AllIn13D";
string message = $"You are about to convert {pathsToConvert.Count} materials to AllIn13D";
string okButton = "Convert and Override";
string altButton = "Convert and keep originals";
string cancelButton = "Cancel";
int dialog = EditorUtility.DisplayDialogComplex(title, message, okButton, cancelButton, altButton);
if(dialog == CANCEL) { return; }
ConvertMaterials(pathsToConvert, dialog);
}
[MenuItem(itemName: "Assets/AllIn1/Convert Standard materials to AllIn13DShader")]
public static void BatchConvertStandardMats()
{
Object[] selectedAssets = Selection.GetFiltered<Object>(SelectionMode.Assets);
HashSet<string> pathsToConvert = CollectPathsToConvert(selectedAssets);
//Remove pathsToConvert of materials that have a shader name that contains Standard
HashSet<string> standardMaterialPaths = new HashSet<string>(pathsToConvert.Count);
foreach(string path in pathsToConvert)
{
Material mat = AssetDatabase.LoadAssetAtPath<Material>(path);
if(mat != null && mat.shader != null && mat.shader.name.Contains("Standard"))
standardMaterialPaths.Add(path);
}
string title = "Converting Standard materials to AllIn13D";
string message = $"You are about to convert {standardMaterialPaths.Count} Standard materials to AllIn13D";
string okButton = "Convert and Override";
string altButton = "Convert and keep originals";
string cancelButton = "Cancel";
int dialog = EditorUtility.DisplayDialogComplex(title, message, okButton, cancelButton, altButton);
if(dialog == CANCEL) return;
ConvertMaterials(standardMaterialPaths, dialog);
}
private static HashSet<string> CollectPathsToConvert(Object[] selectedAssets)
{
HashSet<string> res = new HashSet<string>();
foreach (Object asset in selectedAssets)
{
string path = AssetDatabase.GetAssetPath(asset);
if (asset is Material)
{
res.Add(path);
}
else
{
string[] materialsInFolderGUIDs = AssetDatabase.FindAssets("t: Material", new string[] { path });
foreach (string guid in materialsInFolderGUIDs)
{
res.Add(AssetDatabase.GUIDToAssetPath(guid));
}
}
}
return res;
}
private static void ConvertMaterials(HashSet<string> materialsPaths, int dialog)
{
Undo.IncrementCurrentGroup();
Material matTemplate = GlobalConfiguration.instance.defaultPreset;
foreach (string path in materialsPaths)
{
ConvertMaterial(path, matTemplate, dialog);
}
Undo.SetCurrentGroupName("Materials conversion to AllIn13DShader");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
private static void ConvertMaterial(string path, Material matTemplate, int dialog)
{
Material matFrom = AssetDatabase.LoadAssetAtPath<Material>(path);
Material target = new Material(matTemplate);
ApplyConversion(matFrom, target);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
string folder = Path.GetDirectoryName(path);
string fileName = Path.GetFileName(path);
string fileNameNewAsset = fileNameWithoutExtension + "_AllIn13D" + ".mat";
string pathNewAsset = Path.Combine(folder, fileNameNewAsset);
if (dialog == KEEP_ORIGINALS)
{
AssetDatabase.CreateAsset(target, pathNewAsset);
Object createdObject = AssetDatabase.LoadAssetAtPath<Object>(pathNewAsset);
}
else if (dialog == OVERRIDE)
{
Undo.RecordObject(matFrom, "Material converted");
matFrom.shader = target.shader;
matFrom.CopyMatchingPropertiesFromMaterial(target);
EditorUtility.SetDirty(matFrom);
}
}
public static Material Convert(Shader shader, Material from)
{
Material res = new Material(shader);
Texture normalMap = from.GetTexture("_BumpMap");
if (normalMap != null)
{
res.SetTexture("_NormalMap", normalMap);
}
return res;
}
public static ConverterGeneral GetConverterByShader(Shader shader)
{
ConverterGeneral res = new ConverterGeneral();
if(shader.name == "Standard")
{
res = new ConverterStandardBIRP();
}
else if(shader.name == "Universal Render Pipeline/Lit")
{
res = new ConverterURPLit();
}
return res;
}
public static void ApplyConversion(Material from, Material target)
{
if(from != null && target != null)
{
ConverterGeneral converter = GetConverterByShader(from.shader);
converter.ApplyConversion(from, target);
}
}
public static void ApplyConversionProperty(ConversionProperty conversionProperty, Material from, Material target, ref bool propertyActive)
{
string propertyNameFrom = string.Empty;
string propertyNameTarget = conversionProperty.propertyName;
if (from.HasProperty(conversionProperty.propertyName))
{
propertyNameFrom = conversionProperty.propertyName;
}
else
{
for (int i = 0; i < conversionProperty.alternativeNames.Length; i++)
{
if (from.HasProperty(conversionProperty.alternativeNames[i]))
{
propertyNameFrom = conversionProperty.alternativeNames[i];
break;
}
}
}
if (!string.IsNullOrEmpty(propertyNameFrom))
{
switch (conversionProperty.propertyType)
{
case ConversionPropertyType.TEXTURE:
Texture texValue = from.GetTexture(propertyNameFrom);
target.SetTexture(propertyNameTarget, texValue);
propertyActive = texValue != null;
break;
case ConversionPropertyType.FLOAT:
float floatValue = from.GetFloat(propertyNameFrom);
target.SetFloat(propertyNameTarget, floatValue);
propertyActive = true;
break;
case ConversionPropertyType.COLOR:
Color colorValue = from.GetColor(propertyNameFrom);
target.SetColor(propertyNameTarget, colorValue);
propertyActive = true;
break;
case ConversionPropertyType.VECTOR:
Vector4 vectorValue = from.GetVector(propertyNameFrom);
target.SetVector(propertyNameTarget, vectorValue);
propertyActive = true;
break;
}
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c83ec1dea52056c478b8a512b7ea53a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316173
packageName: All In 1 3D-Shader
packageVersion: 2.72
assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs
uploadId: 865720