新增动态水物理插件
This commit is contained in:
14
Packages/com.nwh.common/Editor/NWH.Common.Editor.asmdef
Normal file
14
Packages/com.nwh.common/Editor/NWH.Common.Editor.asmdef
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "NWH.Common.Editor",
|
||||
"rootNamespace": "NWH.Common.Editor",
|
||||
"references": [],
|
||||
"includePlatforms": ["Editor"],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4024694a8eb78ec4887a68873cb904fc
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/com.nwh.common/Editor/Resources.meta
Normal file
8
Packages/com.nwh.common/Editor/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c29951a1c9d83f944becafef9c1d2725
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/com.nwh.common/Editor/Resources/NWH.meta
Normal file
8
Packages/com.nwh.common/Editor/Resources/NWH.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6403896494d134e45bbdf7f4b50c5720
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/com.nwh.common/Editor/Resources/NWH/Editor.meta
Normal file
8
Packages/com.nwh.common/Editor/Resources/NWH/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26b8c499356132e49a2d9d436440505b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@@ -0,0 +1,122 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fde4d0f34470624fbed94f695585e63
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMasterTextureLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Server
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
@@ -0,0 +1,98 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f529537840cdb34e9b744ffe2fec59b
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMasterTextureLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
418
Packages/com.nwh.common/Editor/URPToBuiltInConverter.cs
Normal file
418
Packages/com.nwh.common/Editor/URPToBuiltInConverter.cs
Normal file
@@ -0,0 +1,418 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NWH.Common.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts materials in a folder from URP shaders to Built-in render pipeline shaders.
|
||||
/// </summary>
|
||||
public static class URPToBuiltInConverter
|
||||
{
|
||||
private static readonly Dictionary<string, string> ShaderMapping = new Dictionary<string, string>
|
||||
{
|
||||
// Lit shaders
|
||||
{ "Universal Render Pipeline/Lit", "Standard" },
|
||||
{ "Universal Render Pipeline/Simple Lit", "Mobile/Diffuse" },
|
||||
{ "Universal Render Pipeline/Baked Lit", "Legacy Shaders/Lightmapped/Diffuse" },
|
||||
{ "Universal Render Pipeline/Unlit", "Unlit/Texture" },
|
||||
|
||||
// Particle shaders
|
||||
{ "Universal Render Pipeline/Particles/Lit", "Particles/Standard Surface" },
|
||||
{ "Universal Render Pipeline/Particles/Unlit", "Particles/Standard Unlit" },
|
||||
{ "Universal Render Pipeline/Particles/Simple Lit", "Particles/Standard Surface" },
|
||||
|
||||
// Terrain shaders
|
||||
{ "Universal Render Pipeline/Terrain/Lit", "Nature/Terrain/Standard" },
|
||||
|
||||
// Nature/SpeedTree shaders
|
||||
{ "Universal Render Pipeline/Nature/SpeedTree7", "Nature/SpeedTree" },
|
||||
{ "Universal Render Pipeline/Nature/SpeedTree7 Billboard", "Nature/SpeedTree Billboard" },
|
||||
{ "Universal Render Pipeline/Nature/SpeedTree8", "Nature/SpeedTree8" },
|
||||
};
|
||||
|
||||
// Property mappings from URP to Built-in
|
||||
private static readonly Dictionary<string, string> TexturePropertyMapping = new Dictionary<string, string>
|
||||
{
|
||||
{ "_BaseMap", "_MainTex" },
|
||||
{ "_BumpMap", "_BumpMap" },
|
||||
{ "_NormalMap", "_BumpMap" },
|
||||
{ "_EmissionMap", "_EmissionMap" },
|
||||
{ "_OcclusionMap", "_OcclusionMap" },
|
||||
{ "_MetallicGlossMap", "_MetallicGlossMap" },
|
||||
{ "_SpecGlossMap", "_SpecGlossMap" },
|
||||
{ "_ParallaxMap", "_ParallaxMap" },
|
||||
{ "_DetailAlbedoMap", "_DetailAlbedoMap" },
|
||||
{ "_DetailNormalMap", "_DetailNormalMap" },
|
||||
{ "_DetailMask", "_DetailMask" },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> ColorPropertyMapping = new Dictionary<string, string>
|
||||
{
|
||||
{ "_BaseColor", "_Color" },
|
||||
{ "_EmissionColor", "_EmissionColor" },
|
||||
{ "_SpecColor", "_SpecColor" },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> FloatPropertyMapping = new Dictionary<string, string>
|
||||
{
|
||||
{ "_Smoothness", "_Glossiness" },
|
||||
{ "_Metallic", "_Metallic" },
|
||||
{ "_BumpScale", "_BumpScale" },
|
||||
{ "_OcclusionStrength", "_OcclusionStrength" },
|
||||
{ "_Cutoff", "_Cutoff" },
|
||||
{ "_Parallax", "_Parallax" },
|
||||
{ "_DetailNormalMapScale", "_DetailNormalMapScale" },
|
||||
};
|
||||
|
||||
[MenuItem("Tools/NWH/Convert Folder URP to Built-in")]
|
||||
public static void ConvertFolder()
|
||||
{
|
||||
string folderPath = EditorUtility.OpenFolderPanel("Select Folder to Convert", "Assets", "");
|
||||
|
||||
if (string.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert to relative path if inside project
|
||||
string projectPath = Application.dataPath;
|
||||
string relativePath;
|
||||
|
||||
if (folderPath.StartsWith(projectPath))
|
||||
{
|
||||
relativePath = "Assets" + folderPath.Substring(projectPath.Length);
|
||||
}
|
||||
else if (folderPath.Contains("Packages"))
|
||||
{
|
||||
int packagesIndex = folderPath.IndexOf("Packages");
|
||||
relativePath = folderPath.Substring(packagesIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[URPToBuiltIn] Selected folder must be inside the project.");
|
||||
return;
|
||||
}
|
||||
|
||||
ConvertMaterialsInFolder(folderPath, relativePath);
|
||||
}
|
||||
|
||||
public static void ConvertMaterialsInFolder(string absolutePath, string relativePath)
|
||||
{
|
||||
if (!Directory.Exists(absolutePath))
|
||||
{
|
||||
Debug.LogError($"[URPToBuiltIn] Folder not found: {absolutePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] materialFiles = Directory.GetFiles(absolutePath, "*.mat", SearchOption.AllDirectories);
|
||||
|
||||
if (materialFiles.Length == 0)
|
||||
{
|
||||
Debug.Log("[URPToBuiltIn] No material files found in the selected folder.");
|
||||
return;
|
||||
}
|
||||
|
||||
int converted = 0;
|
||||
int skipped = 0;
|
||||
int failed = 0;
|
||||
List<string> warnings = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
AssetDatabase.StartAssetEditing();
|
||||
|
||||
for (int i = 0; i < materialFiles.Length; i++)
|
||||
{
|
||||
string filePath = materialFiles[i].Replace("\\", "/");
|
||||
float progress = (float)i / materialFiles.Length;
|
||||
|
||||
if (EditorUtility.DisplayCancelableProgressBar(
|
||||
"Converting Materials",
|
||||
$"Processing {Path.GetFileName(filePath)} ({i + 1}/{materialFiles.Length})",
|
||||
progress))
|
||||
{
|
||||
Debug.Log("[URPToBuiltIn] Conversion cancelled by user.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert absolute path to asset path
|
||||
string assetPath = ConvertToAssetPath(filePath);
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
warnings.Add($"Could not resolve asset path: {filePath}");
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
Material material = AssetDatabase.LoadAssetAtPath<Material>(assetPath);
|
||||
if (material == null)
|
||||
{
|
||||
warnings.Add($"Could not load material: {assetPath}");
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (material.shader == null)
|
||||
{
|
||||
warnings.Add($"Material has no shader: {assetPath}");
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
string shaderName = material.shader.name;
|
||||
|
||||
// Check if this is a URP shader
|
||||
if (!IsURPShader(shaderName))
|
||||
{
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find target shader
|
||||
string targetShaderName = GetTargetShaderName(shaderName);
|
||||
Shader targetShader = Shader.Find(targetShaderName);
|
||||
|
||||
if (targetShader == null)
|
||||
{
|
||||
warnings.Add($"Target shader not found '{targetShaderName}' for material: {assetPath}");
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert the material
|
||||
if (ConvertMaterial(material, targetShader))
|
||||
{
|
||||
EditorUtility.SetDirty(material);
|
||||
converted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
AssetDatabase.StopAssetEditing();
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
// Log summary
|
||||
Debug.Log($"[URPToBuiltIn] Conversion complete:\n" +
|
||||
$" Converted: {converted}\n" +
|
||||
$" Skipped (not URP): {skipped}\n" +
|
||||
$" Failed: {failed}");
|
||||
|
||||
if (warnings.Count > 0)
|
||||
{
|
||||
Debug.LogWarning("[URPToBuiltIn] Warnings:\n" + string.Join("\n", warnings));
|
||||
}
|
||||
}
|
||||
|
||||
private static string ConvertToAssetPath(string absolutePath)
|
||||
{
|
||||
absolutePath = absolutePath.Replace("\\", "/");
|
||||
|
||||
// Check for Assets folder
|
||||
int assetsIndex = absolutePath.IndexOf("/Assets/");
|
||||
if (assetsIndex >= 0)
|
||||
{
|
||||
return absolutePath.Substring(assetsIndex + 1);
|
||||
}
|
||||
|
||||
// Check for Packages folder
|
||||
int packagesIndex = absolutePath.IndexOf("/Packages/");
|
||||
if (packagesIndex >= 0)
|
||||
{
|
||||
return absolutePath.Substring(packagesIndex + 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsURPShader(string shaderName)
|
||||
{
|
||||
return shaderName.StartsWith("Universal Render Pipeline") ||
|
||||
shaderName.StartsWith("Shader Graphs/") ||
|
||||
shaderName.Contains("URP") ||
|
||||
shaderName.Contains("/Universal/");
|
||||
}
|
||||
|
||||
private static string GetTargetShaderName(string urpShaderName)
|
||||
{
|
||||
if (ShaderMapping.TryGetValue(urpShaderName, out string targetName))
|
||||
{
|
||||
return targetName;
|
||||
}
|
||||
|
||||
// Fallback to Standard for unknown URP shaders
|
||||
return "Standard";
|
||||
}
|
||||
|
||||
private static bool ConvertMaterial(Material material, Shader targetShader)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Cache current properties before changing shader
|
||||
var cachedTextures = new Dictionary<string, Texture>();
|
||||
var cachedColors = new Dictionary<string, Color>();
|
||||
var cachedFloats = new Dictionary<string, float>();
|
||||
var cachedKeywords = new HashSet<string>(material.shaderKeywords);
|
||||
|
||||
// Cache textures
|
||||
foreach (var mapping in TexturePropertyMapping)
|
||||
{
|
||||
if (material.HasProperty(mapping.Key))
|
||||
{
|
||||
Texture tex = material.GetTexture(mapping.Key);
|
||||
if (tex != null)
|
||||
{
|
||||
cachedTextures[mapping.Value] = tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache colors
|
||||
foreach (var mapping in ColorPropertyMapping)
|
||||
{
|
||||
if (material.HasProperty(mapping.Key))
|
||||
{
|
||||
cachedColors[mapping.Value] = material.GetColor(mapping.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Cache floats
|
||||
foreach (var mapping in FloatPropertyMapping)
|
||||
{
|
||||
if (material.HasProperty(mapping.Key))
|
||||
{
|
||||
cachedFloats[mapping.Value] = material.GetFloat(mapping.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Cache render mode settings
|
||||
float surface = material.HasProperty("_Surface") ? material.GetFloat("_Surface") : 0;
|
||||
float alphaClip = material.HasProperty("_AlphaClip") ? material.GetFloat("_AlphaClip") : 0;
|
||||
float blend = material.HasProperty("_Blend") ? material.GetFloat("_Blend") : 0;
|
||||
|
||||
// Change shader
|
||||
material.shader = targetShader;
|
||||
|
||||
// Apply cached textures
|
||||
foreach (var kvp in cachedTextures)
|
||||
{
|
||||
if (material.HasProperty(kvp.Key))
|
||||
{
|
||||
material.SetTexture(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply cached colors
|
||||
foreach (var kvp in cachedColors)
|
||||
{
|
||||
if (material.HasProperty(kvp.Key))
|
||||
{
|
||||
material.SetColor(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply cached floats
|
||||
foreach (var kvp in cachedFloats)
|
||||
{
|
||||
if (material.HasProperty(kvp.Key))
|
||||
{
|
||||
material.SetFloat(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle emission
|
||||
if (cachedColors.TryGetValue("_EmissionColor", out Color emissionColor))
|
||||
{
|
||||
if (emissionColor.r > 0 || emissionColor.g > 0 || emissionColor.b > 0)
|
||||
{
|
||||
material.EnableKeyword("_EMISSION");
|
||||
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
|
||||
}
|
||||
}
|
||||
|
||||
// Set render mode for Standard shader
|
||||
if (targetShader.name == "Standard")
|
||||
{
|
||||
SetupStandardShaderRenderMode(material, surface, alphaClip, blend);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError($"[URPToBuiltIn] Error converting material {material.name}: {e.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetupStandardShaderRenderMode(Material material, float surface, float alphaClip, float blend)
|
||||
{
|
||||
// URP: _Surface 0=Opaque, 1=Transparent
|
||||
// URP: _AlphaClip 0=Off, 1=On
|
||||
// Standard modes: 0=Opaque, 1=Cutout, 2=Fade, 3=Transparent
|
||||
|
||||
if (surface == 0) // Opaque
|
||||
{
|
||||
if (alphaClip > 0.5f)
|
||||
{
|
||||
// Cutout mode
|
||||
material.SetFloat("_Mode", 1);
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt("_ZWrite", 1);
|
||||
material.EnableKeyword("_ALPHATEST_ON");
|
||||
material.DisableKeyword("_ALPHABLEND_ON");
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opaque mode
|
||||
material.SetFloat("_Mode", 0);
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt("_ZWrite", 1);
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
material.DisableKeyword("_ALPHABLEND_ON");
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = -1;
|
||||
}
|
||||
}
|
||||
else // Transparent
|
||||
{
|
||||
if (blend == 0) // Alpha blend
|
||||
{
|
||||
// Fade mode
|
||||
material.SetFloat("_Mode", 2);
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt("_ZWrite", 0);
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
material.EnableKeyword("_ALPHABLEND_ON");
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
else // Premultiply or Additive
|
||||
{
|
||||
// Transparent mode
|
||||
material.SetFloat("_Mode", 3);
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt("_ZWrite", 0);
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
material.DisableKeyword("_ALPHABLEND_ON");
|
||||
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb384c7cca2197b4e902f6b94022665a
|
||||
Reference in New Issue
Block a user