浏览代码
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop into SkySystem
/main
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop into SkySystem
/main
Evgenii Golubev
8 年前
当前提交
fc0cb9a4
共有 61 个文件被更改,包括 1187 次插入 和 333 次删除
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Debug.meta
-
28Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
-
5Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
-
2Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
-
53Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Forward.hlsl
-
5Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Resources/Deferred.shader
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass.meta
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePassLoop.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ClusteredUtils.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute
-
129Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs.hlsl
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.hlsl
-
17Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/Editor/LayeredLitUI.cs
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/LitUI.cs
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/UnlitUI.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/PostProcess.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Shadow.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Shadow/FixedSizePCF.meta
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
-
9Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs
-
1Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
23Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
6Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
-
39Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl
-
6Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
152Assets/ScriptableRenderLoop/fptl/LightingUtils.hlsl
-
250Assets/TestScenes/HDTest/LayeredLitTest.unity
-
89Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered/Layered.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered/Layered.mat.meta
-
9Assets/ScriptableRenderLoop/Editor.meta
-
130Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader.meta
-
42Assets/ScriptableRenderLoop/HDRenderLoop/Editor/UpgradeStandardShaderMaterials.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Editor/UpgradeStandardShaderMaterials.cs.meta
-
63Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader.cs.meta
-
69Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/StandardToHDLitMaterialUpgrader.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/StandardToHDLitMaterialUpgrader.cs.meta
-
20Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/PatchStandardShaderToNewNamingConvention.cginc
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/PatchStandardShaderToNewNamingConvention.cginc.meta
-
12Assets/ScriptableRenderLoop/Editor/MaterialUpgrader.cs.meta
-
173Assets/ScriptableRenderLoop/Editor/MaterialUpgrader.cs
-
20Assets/forwardrenderloop.asset
-
8Assets/forwardrenderloop.asset.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 2400b74f5ce370c4481e5dc417d03703 |
|||
timeCreated: 1479691644 |
|||
timeCreated: 1480265826 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
250
Assets/TestScenes/HDTest/LayeredLitTest.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 6e7fa39a7d1b15c4184c9f51d86eba22 |
|||
timeCreated: 1479379836 |
|||
timeCreated: 1480070650 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: '{"GUIDArray":["01fa3be727161d249a81ad7065c15459","3acf8f156d29e494e8cd196462d1a17c","62b3c923bc540b94a803550e9927936a","c569253e641dc934db7c3595b31890da"]}' |
|
|||
fileFormatVersion: 2 |
|||
guid: 74ae8146f4a01491ba1306f3db78139d |
|||
folderAsset: yes |
|||
timeCreated: 1479851675 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/HDRenderLoop/DebugViewTiles" |
|||
{ |
|||
SubShader |
|||
{ |
|||
|
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
|
|||
HLSLPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma vertex VertViewTiles |
|||
#pragma fragment FragViewTiles |
|||
|
|||
#define LIGHTLOOP_TILE_PASS 1 |
|||
#define USE_FPTL_LIGHTLIST 1 //TODO: make it also work with clustered |
|||
#define LIGHTLOOP_TILE_ALL 1 |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new |
|||
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem), |
|||
// the deferred shader will require to use multicompile. |
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
uint _ViewTilesFlags; |
|||
|
|||
TEXTURE2D(_CameraDepthTexture); |
|||
SAMPLER2D(sampler_CameraDepthTexture); |
|||
|
|||
float4 VertViewTiles(float3 positionOS : POSITION): SV_POSITION |
|||
{ |
|||
return TransformWorldToHClip(TransformObjectToWorld(positionOS)); |
|||
} |
|||
|
|||
float4 OverlayHeatMap(uint2 pixCoord, uint numLights) |
|||
{ |
|||
const float4 kRadarColors[12] = |
|||
{ |
|||
float4(0.0, 0.0, 0.0, 0.0), // black |
|||
float4(0.0, 0.0, 0.6, 0.5), // dark blue |
|||
float4(0.0, 0.0, 0.9, 0.5), // blue |
|||
float4(0.0, 0.6, 0.9, 0.5), // light blue |
|||
float4(0.0, 0.9, 0.9, 0.5), // cyan |
|||
float4(0.0, 0.9, 0.6, 0.5), // blueish green |
|||
float4(0.0, 0.9, 0.0, 0.5), // green |
|||
float4(0.6, 0.9, 0.0, 0.5), // yellowish green |
|||
float4(0.9, 0.9, 0.0, 0.5), // yellow |
|||
float4(0.9, 0.6, 0.0, 0.5), // orange |
|||
float4(0.9, 0.0, 0.0, 0.5), // red |
|||
float4(1.0, 0.0, 0.0, 0.9) // strong red |
|||
}; |
|||
|
|||
float maxNrLightsPerTile = 31; |
|||
|
|||
int nColorIndex = numLights == 0 ? 0 : (1 + (int)floor(10 * (log2((float)numLights) / log2(maxNrLightsPerTile)))); |
|||
nColorIndex = nColorIndex<0 ? 0 : nColorIndex; |
|||
float4 col = nColorIndex>11 ? float4(1.0, 1.0, 1.0, 1.0) : kRadarColors[nColorIndex]; |
|||
|
|||
int2 coord = pixCoord - int2(1, 1); |
|||
|
|||
float4 color = float4(pow(col.xyz, 2.2), 0.3*col.w); |
|||
if (numLights > 0) |
|||
{ |
|||
if (SampleDebugFontNumber(coord, numLights)) // Shadow |
|||
color = float4(0, 0, 0, 1); |
|||
if (SampleDebugFontNumber(coord + 1, numLights)) // Text |
|||
color = float4(1, 1, 1, 1); |
|||
} |
|||
return color; |
|||
} |
|||
|
|||
float4 FragViewTiles(float4 positionCS : SV_POSITION) : SV_Target |
|||
{ |
|||
Coordinate coord = GetCoordinate(positionCS.xy, _ScreenSize.zw); |
|||
|
|||
#if USE_FPTL_LIGHTLIST |
|||
float linearDepth = 0.0; |
|||
#else |
|||
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).x; |
|||
float linearDepth = GetLinearDepth(depth); |
|||
#endif |
|||
|
|||
int n = 0; |
|||
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_DIRECT_LIGHTING) |
|||
{ |
|||
uint punctualLightStart; |
|||
uint punctualLightCount; |
|||
GetCountAndStart(coord, DIRECT_LIGHT, linearDepth, punctualLightStart, punctualLightCount); |
|||
n += punctualLightCount; |
|||
} |
|||
|
|||
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_REFLECTION) |
|||
{ |
|||
uint envLightStart; |
|||
uint envLightCount; |
|||
GetCountAndStart(coord, REFLECTION_LIGHT, linearDepth, envLightStart, envLightCount); |
|||
n += envLightCount; |
|||
} |
|||
|
|||
if (n > 0) |
|||
{ |
|||
return OverlayHeatMap(int2(coord.unPositionSS.xy) & 15, n); |
|||
} |
|||
else |
|||
{ |
|||
return 0.0; |
|||
} |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
Fallback Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c7c2bd17b06ceb4468e14081aaf1b96f |
|||
timeCreated: 1480329456 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System; |
|||
using NUnit.Framework; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public class UpgradeStandardShaderMaterials |
|||
{ |
|||
static List<MaterialUpgrader> GetHDUpgraders() |
|||
{ |
|||
var upgraders = new List<MaterialUpgrader>(); |
|||
upgraders.Add(new StandardToHDLitMaterialUpgrader()); |
|||
upgraders.Add(new StandardSpecularToHDLitMaterialUpgrader()); |
|||
return upgraders; |
|||
} |
|||
|
|||
[MenuItem("HDRenderLoop/Upgrade Materials - Project")] |
|||
static void UpgradeMaterialsProject() |
|||
{ |
|||
MaterialUpgrader.UpgradeProjectFolder(GetHDUpgraders(), "Upgrade to HD Material"); |
|||
} |
|||
|
|||
[MenuItem("HDRenderLoop/Upgrade Materials - Selection")] |
|||
static void UpgradeMaterialsSelection() |
|||
{ |
|||
MaterialUpgrader.UpgradeSelection(GetHDUpgraders(), "Upgrade to HD Material"); |
|||
} |
|||
|
|||
[MenuItem("HDRenderLoop/Modify Light Intensity for Upgrade - Scene Only")] |
|||
static void UpgradeLights() |
|||
{ |
|||
Light[] lights = Light.GetLights(LightType.Directional, 0); |
|||
foreach (var l in lights) |
|||
{ |
|||
l.intensity *= Mathf.PI; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9384735d0665f47539990919bf72504e |
|||
timeCreated: 1479839793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
class StandardSpecularToHDLitMaterialUpgrader : MaterialUpgrader |
|||
{ |
|||
public StandardSpecularToHDLitMaterialUpgrader() |
|||
{ |
|||
RenameShader("Standard (Specular setup)", "HDRenderLoop/LitLegacySupport"); |
|||
|
|||
RenameTexture("_MainTex", "_BaseColorMap"); |
|||
RenameColor("_Color", "_BaseColor"); |
|||
RenameFloat("_Glossiness", "_Smoothness"); |
|||
RenameTexture("_BumpMap", "_NormalMap"); |
|||
RenameColor("_EmissionColor", "_EmissiveColor"); |
|||
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|||
RenameTexture("_DetailNormalMap", "_DetailMap"); |
|||
|
|||
//@Seb: Bumpmap scale doesn't exist in new shader
|
|||
//_BumpScale("Scale", Float) = 1.0
|
|||
|
|||
// Anything reasonable that can be done here?
|
|||
//RenameFloat("_SpecColor", ...);
|
|||
|
|||
//@TODO: Seb. Why do we multiply color by intensity
|
|||
// in shader when we can just store a color?
|
|||
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
base.Convert(srcMaterial, dstMaterial); |
|||
//@TODO: Find a good way of setting up keywords etc from properties.
|
|||
// Code should be shared with material UI code.
|
|||
} |
|||
|
|||
[Test] |
|||
public void UpgradeMaterial() |
|||
{ |
|||
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport"); |
|||
var mat = new Material(Shader.Find("Standard (Specular setup)")); |
|||
var albedo = new Texture2D(1, 1); |
|||
var normals = new Texture2D(1, 1); |
|||
var baseScale = new Vector2(1, 1); |
|||
var color = Color.red; |
|||
mat.mainTexture = albedo; |
|||
mat.SetTexture("_BumpMap", normals); |
|||
mat.color = color; |
|||
mat.SetTextureScale("_MainTex", baseScale); |
|||
|
|||
MaterialUpgrader.Upgrade(mat, new StandardSpecularToHDLitMaterialUpgrader(), MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties); |
|||
|
|||
Assert.AreEqual(newShader, mat.shader); |
|||
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap")); |
|||
Assert.AreEqual(color, mat.GetColor("_BaseColor")); |
|||
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap")); |
|||
Assert.AreEqual(normals, mat.GetTexture("_NormalMap")); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 775bef174b1e2ed47972a143845e1191 |
|||
timeCreated: 1479911618 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
class StandardToHDLitMaterialUpgrader : MaterialUpgrader |
|||
{ |
|||
public StandardToHDLitMaterialUpgrader() |
|||
{ |
|||
RenameShader("Standard", "HDRenderLoop/LitLegacySupport"); |
|||
|
|||
RenameTexture("_MainTex", "_BaseColorMap"); |
|||
RenameColor("_Color", "_BaseColor"); |
|||
RenameFloat("_Glossiness", "_Smoothness"); |
|||
RenameTexture("_BumpMap", "_NormalMap"); |
|||
RenameColor("_EmissionColor", "_EmissiveColor"); |
|||
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|||
|
|||
// the HD renderloop packs detail albedo and detail normals into a single texture.
|
|||
// mapping the detail normal map, if any, to the detail map, should do the right thing if
|
|||
// there is no detail albedo.
|
|||
RenameTexture("_DetailNormalMap", "_DetailMap"); |
|||
|
|||
//@Seb: Bumpmap scale doesn't exist in new shader
|
|||
//_BumpScale("Scale", Float) = 1.0
|
|||
|
|||
// Metallic uses [Gamma] attribute in standard shader but not in Lit.
|
|||
// @Seb: Should we convert?
|
|||
RenameFloat("_Metallic", "_Metallic"); |
|||
|
|||
//@TODO: Seb. Why do we multiply color by intensity
|
|||
// in shader when we can just store a color?
|
|||
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
base.Convert(srcMaterial, dstMaterial); |
|||
//@TODO: Find a good way of setting up keywords etc from properties.
|
|||
// Code should be shared with material UI code.
|
|||
} |
|||
|
|||
[Test] |
|||
public void UpgradeMaterial() |
|||
{ |
|||
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport"); |
|||
var mat = new Material(Shader.Find("Standard")); |
|||
var albedo = new Texture2D(1, 1); |
|||
var normals = new Texture2D(1, 1); |
|||
var baseScale = new Vector2(1, 1); |
|||
var color = Color.red; |
|||
mat.mainTexture = albedo; |
|||
mat.SetTexture("_BumpMap", normals); |
|||
mat.color = color; |
|||
mat.SetTextureScale("_MainTex", baseScale); |
|||
|
|||
|
|||
MaterialUpgrader.Upgrade(mat, new StandardToHDLitMaterialUpgrader(), MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties); |
|||
|
|||
Assert.AreEqual(newShader, mat.shader); |
|||
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap")); |
|||
Assert.AreEqual(color, mat.GetColor("_BaseColor")); |
|||
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap")); |
|||
Assert.AreEqual(normals, mat.GetTexture("_NormalMap")); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: fedbd6bc5d95f4d768cb8077e8454b4e |
|||
timeCreated: 1479851295 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// NOTE: For performing a project upgrade where you temporarily support both old and new renderloops |
|||
// in the same sahder |
|||
// |
|||
// The basic approach is: |
|||
// Upgrade all your shaders to the new naming convention, using a SubShader that also contains the legacy // renderloop code. |
|||
// |
|||
// 1. Copy HDRenderloop Lit.shader into your project |
|||
// 2. Add a SubShader and copy old Standard shader passes into it. |
|||
// 2. Set LOD on subshader to make Unity pick at runtime to use new renderloop shaders or |
|||
// legacy standard shaders based on if SRL is enabled or not. |
|||
// In the legacy standard shader section add |
|||
// #include "PatchStandardShaderToNewNamingConvention.cginc" |
|||
|
|||
// List of name remaps |
|||
#define _MainTex _BaseColorMap |
|||
#define _MainTex_ST _BaseColorMap_ST |
|||
#define _BumpMap _NormalMap |
|||
#define _ParallaxMap _HeightMap |
|||
#define _Parallax _HeightScale |
|||
#define _Glossiness _Smoothness |
|
|||
fileFormatVersion: 2 |
|||
guid: a9b4e2b7ef9a45f49834b052e7722acb |
|||
timeCreated: 1480085057 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 67b996d0727a74b029aff1545143be17 |
|||
timeCreated: 1479851694 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public class MaterialUpgrader |
|||
{ |
|||
string m_OldShader; |
|||
string m_NewShader; |
|||
|
|||
Dictionary<string, string> m_TextureRename = new Dictionary<string, string>(); |
|||
Dictionary<string, string> m_FloatRename = new Dictionary<string, string>(); |
|||
Dictionary<string, string> m_ColorRename = new Dictionary<string, string>(); |
|||
|
|||
[Flags] |
|||
public enum UpgradeFlags |
|||
{ |
|||
None = 0, |
|||
LogErrorOnNonExistingProperty = 1, |
|||
CleanupNonUpgradedProperties = 2, |
|||
} |
|||
|
|||
public void Upgrade(Material material, UpgradeFlags flags) |
|||
{ |
|||
Material newMaterial; |
|||
if ((flags & UpgradeFlags.CleanupNonUpgradedProperties) != 0) |
|||
{ |
|||
newMaterial = new Material(Shader.Find(m_NewShader)); |
|||
} |
|||
else |
|||
{ |
|||
newMaterial = UnityEngine.Object.Instantiate(material) as Material; |
|||
newMaterial.shader = Shader.Find(m_NewShader); |
|||
} |
|||
|
|||
Convert(material, newMaterial); |
|||
|
|||
material.shader = Shader.Find(m_NewShader); |
|||
material.CopyPropertiesFromMaterial(newMaterial); |
|||
UnityEngine.Object.DestroyImmediate(newMaterial); |
|||
} |
|||
|
|||
// Overridable function to implement custom material upgrading functionality
|
|||
public virtual void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
foreach (var t in m_TextureRename) |
|||
{ |
|||
dstMaterial.SetTextureScale(t.Value, srcMaterial.GetTextureScale(t.Key)); |
|||
dstMaterial.SetTextureOffset(t.Value, srcMaterial.GetTextureOffset(t.Key)); |
|||
dstMaterial.SetTexture(t.Value, srcMaterial.GetTexture(t.Key)); |
|||
} |
|||
|
|||
foreach (var t in m_FloatRename) |
|||
dstMaterial.SetFloat(t.Value, srcMaterial.GetFloat(t.Key)); |
|||
|
|||
foreach (var t in m_ColorRename) |
|||
dstMaterial.SetColor(t.Value, srcMaterial.GetColor(t.Key)); |
|||
} |
|||
|
|||
public void RenameShader(string oldName, string newName) |
|||
{ |
|||
m_OldShader = oldName; |
|||
m_NewShader = newName; |
|||
} |
|||
|
|||
public void RenameTexture(string oldName, string newName) |
|||
{ |
|||
m_TextureRename[oldName] = newName; |
|||
} |
|||
|
|||
public void RenameFloat(string oldName, string newName) |
|||
{ |
|||
m_FloatRename[oldName] = newName; |
|||
} |
|||
|
|||
public void RenameColor(string oldName, string newName) |
|||
{ |
|||
m_ColorRename[oldName] = newName; |
|||
} |
|||
|
|||
static bool IsMaterialPath(string path) |
|||
{ |
|||
return path.EndsWith(".mat", StringComparison.OrdinalIgnoreCase); |
|||
} |
|||
|
|||
static MaterialUpgrader GetUpgrader(List<MaterialUpgrader> upgraders, Material material) |
|||
{ |
|||
if (material == null || material.shader == null) |
|||
return null; |
|||
|
|||
string shaderName = material.shader.name; |
|||
for (int i = 0; i != upgraders.Count; i++) |
|||
{ |
|||
if (upgraders[i].m_OldShader == shaderName) |
|||
return upgraders[i]; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
//@TODO: Only do this when it exceeds memory consumption...
|
|||
static void SaveAssetsAndFreeMemory() |
|||
{ |
|||
AssetDatabase.SaveAssets(); |
|||
GC.Collect(); |
|||
EditorUtility.UnloadUnusedAssetsImmediate(); |
|||
AssetDatabase.Refresh(); |
|||
} |
|||
|
|||
public static void UpgradeProjectFolder(List<MaterialUpgrader> upgraders, string progressBarName) |
|||
{ |
|||
int totalMaterialCount = 0; |
|||
foreach (string s in UnityEditor.AssetDatabase.GetAllAssetPaths()) |
|||
{ |
|||
if (IsMaterialPath(s)) |
|||
totalMaterialCount++; |
|||
} |
|||
|
|||
int materialIndex = 0; |
|||
foreach (string path in UnityEditor.AssetDatabase.GetAllAssetPaths()) |
|||
{ |
|||
if (IsMaterialPath(path)) |
|||
{ |
|||
materialIndex++; |
|||
if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(progressBarName, string.Format("({0} of {1}) {2}", materialIndex, totalMaterialCount, path), (float)materialIndex / (float)totalMaterialCount)) |
|||
break; |
|||
|
|||
Material m = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path) as Material; |
|||
Upgrade(m, upgraders, UpgradeFlags.None); |
|||
|
|||
//SaveAssetsAndFreeMemory();
|
|||
} |
|||
} |
|||
|
|||
UnityEditor.EditorUtility.ClearProgressBar(); |
|||
} |
|||
|
|||
public static void Upgrade(Material material, MaterialUpgrader upgrader, UpgradeFlags flags) |
|||
{ |
|||
var upgraders = new List<MaterialUpgrader>(); |
|||
upgraders.Add(upgrader); |
|||
Upgrade(material, upgraders, flags); |
|||
} |
|||
|
|||
public static void Upgrade(Material material, List<MaterialUpgrader> upgraders, UpgradeFlags flags) |
|||
{ |
|||
var upgrader = GetUpgrader(upgraders, material); |
|||
if (upgrader != null) |
|||
upgrader.Upgrade(material, flags); |
|||
} |
|||
|
|||
public static void UpgradeSelection(List<MaterialUpgrader> upgraders, string progressBarName) |
|||
{ |
|||
string lastMaterialName = ""; |
|||
var selection = Selection.objects; |
|||
for (int i = 0; i < selection.Length; i++) |
|||
{ |
|||
|
|||
if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(progressBarName, string.Format("({0} of {1}) {2}", i, selection.Length, lastMaterialName), (float)i / (float)selection.Length)) |
|||
break; |
|||
|
|||
var material = selection[i] as Material; |
|||
Upgrade(material, upgraders, UpgradeFlags.None); |
|||
if (material != null) |
|||
lastMaterialName = material.name; |
|||
} |
|||
|
|||
UnityEditor.EditorUtility.ClearProgressBar(); |
|||
} |
|||
} |
|||
} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 98fe12104b04e43dd9a963f3f7b26e8e, type: 3} |
|||
m_Name: forwardrenderloop |
|||
m_EditorClassIdentifier: |
|||
m_ShadowSettings: |
|||
enabled: 1 |
|||
shadowAtlasWidth: 4096 |
|||
shadowAtlasHeight: 4096 |
|||
maxShadowDistance: 1000 |
|||
directionalLightCascadeCount: 4 |
|||
directionalLightCascades: {x: 0.05, y: 0.2, z: 0.3} |
|
|||
fileFormatVersion: 2 |
|||
guid: bfc231f294556ca4799e7f7feddee50d |
|||
timeCreated: 1475076344 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue