Skip to content

Commit b4f8150

Browse files
authored
Task/uts2 feature table (#234)
* On the way to create new tables. [skip ci] * Added a function, GetShaderPath(). [skip ci] * Added a function, FindShaderFile(). [skip ci] * Implementing Subshader block parser. [skip ci] * Implemented parser roughly [skip ci]. * Implemented StencilMode parser. [skip ci] * Implemented clipping mode parser. [skip ci] * Updated UTSGuid.cs and UTS2ShaderInfo.cs [skip ci] * new table started to work. [skip ci] * Added parser for rendertype [skip ci]. * Tables in UTS2ShaderInfo classes are not UTS2INFO but UTSGUID. [skip ci] * Added capability to convert Tessallation shader * Rmoved fallback in the shaders as it seems to cause side effects. * Check if shader compile test failure on Mac can be fixed.
1 parent d9b6710 commit b4f8150

15 files changed

+840
-173
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
using UnityEditor;
3+
using UnityEngine;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
using UnityEngine.TestTools;
7+
8+
namespace Unity.Rendering.ToonShader.Tests {
9+
internal class ShaderCompileTest
10+
{
11+
// [MenuItem("Tests/Unity Toon Shader Compile Test", false, 51)]
12+
13+
internal static void CompileLegacyToonShadersDefault() {
14+
string[] guids = AssetDatabase.FindAssets("t:Shader", new[] { LEGACY_SHADERS_PATH});
15+
int numShaders = guids.Length;
16+
Debug.Assert(numShaders > 0);
17+
bool shaderHasError = false;
18+
for (int i=0;i<numShaders && !shaderHasError;++i) {
19+
string curAssetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
20+
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(curAssetPath);
21+
AssetDatabase.ImportAsset(curAssetPath); //Recompile the shader to make sure there are no compile errors
22+
23+
Debug.Assert(shader.isSupported);
24+
shaderHasError = ShaderUtil.ShaderHasError(shader);
25+
Debug.Assert(shaderHasError == false);
26+
}
27+
}
28+
29+
30+
31+
private const string LEGACY_SHADERS_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders";
32+
33+
}
34+
} //end namespace

com.unity.toonshader/Editor/ConverterWindow.cs.meta renamed to com.unity.toonshader/Editor/CompileTest.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.toonshader/Editor/Converter/FromUTS2/BuiltInUTS2toIntegratedConverter.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override void SetupConverter() {
4343
string content = File.ReadAllText(path);
4444
string[] lines = content.Split(lineSeparators, StringSplitOptions.None);
4545
// always two spaces before m_Shader?
46-
var targetLine = Array.Find<string>(lines, line => line.StartsWith(" m_Shader:"));
46+
var targetLine = Array.Find<string>(lines, line => line.StartsWith(kShaderKeywordInMatrial));
4747
if (targetLine == null)
4848
{
4949
continue; // todo. prefab?
@@ -200,7 +200,8 @@ bool CheckUTS2isInstalled()
200200
}
201201
UTSGUID FindUTS2GUID(string guid)
202202
{
203-
var ret = Array.Find<UTSGUID>(UTS2ShaderInfo.stdShaders, element => element.m_Guid == guid);
203+
// var ret = Array.Find<UTSGUID>(UTS2ShaderInfo.stdShaders, element => element.m_Guid == guid);
204+
#if false
204205
foreach (var utsGuid in UTS2ShaderInfo.stdShaders)
205206
{
206207
if (utsGuid.m_Guid == guid)
@@ -215,6 +216,16 @@ UTSGUID FindUTS2GUID(string guid)
215216
return utsGuid;
216217
}
217218
}
219+
#else
220+
foreach (var utsGuid in UTS2Table.tables)
221+
{
222+
if (utsGuid.m_Guid == guid)
223+
{
224+
return utsGuid;
225+
}
226+
}
227+
228+
#endif
218229
return null;
219230
}
220231

@@ -250,7 +261,7 @@ public override int CountErrors(bool addToScrollView)
250261
string content = File.ReadAllText(path);
251262
string[] lines = content.Split(lineSeparators, StringSplitOptions.None);
252263
// always two spaces before m_Shader?
253-
var targetLine = Array.Find<string>(lines, line => line.StartsWith(" m_Shader:"));
264+
var targetLine = Array.Find<string>(lines, line => line.StartsWith(kShaderKeywordInMatrial));
254265
if (targetLine == null)
255266
{
256267
continue; // todo. prefab?
@@ -366,17 +377,12 @@ void ConvertBuiltInUTS2Materials( string[] guids)
366377

367378
string path = AssetDatabase.GUIDToAssetPath(guid);
368379
Material material = AssetDatabase.LoadAssetAtPath<Material>(path);
369-
370-
if (material.name == "ShadingGradeMap")
371-
{
372-
Debug.Log("ShadingGradeMap");
373-
}
374-
375-
material.shader = Shader.Find(kIntegratedUTS3Name);
380+
var shaderID = GetShaderIDinMaterial(path);
381+
material.shader = Shader.Find(IsTesselationShader(path) ? kIntegratedTessllationUTS3Name : kIntegratedUTS3Name);
376382
var shaderGUID = m_Material2GUID_Dictionary[material];
377383
var UTS2Info = m_GuidToUTSID_Dictionary[shaderGUID] as UTS2INFO;
378384

379-
UTS3GUI.UTS_TransparentMode transparencyEnabled = (UTS2Info.m_renderQueue == RenderQueue.Transparent) ? UTS3GUI.UTS_TransparentMode.On : UTS3GUI.UTS_TransparentMode.Off;
385+
UTS3GUI.UTS_TransparentMode transparencyEnabled = (UTS2Info.m_renderQueue == UTS2RenderQueue.Transparent) ? UTS3GUI.UTS_TransparentMode.On : UTS3GUI.UTS_TransparentMode.Off;
380386

381387

382388

@@ -539,18 +545,18 @@ private bool IsShadingGrademap(Material material)
539545
return UTS3GUI.MaterialGetInt(material, UTS3GUI.ShaderPropUtsTechniqe) == (int)UTS3GUI.UTS_Mode.ShadingGradeMap;
540546
}
541547

542-
void ApplyQueueAndRenderType(Material material, UTS3GUI.UTS_Mode technique, RenderQueue renderQueue,UTS3GUI.UTS_TransparentMode transperentSetting )
548+
void ApplyQueueAndRenderType(Material material, UTS3GUI.UTS_Mode technique, UTS2RenderQueue renderQueue,UTS3GUI.UTS_TransparentMode transperentSetting )
543549
{
544550

545551

546552

547553

548-
var ignoreProjection = UTS2INFO.DONT_IGNOREPROJECTION;
554+
// var ignoreProjection = UTS2INFO.DONT_IGNOREPROJECTION;
549555

550556
if (transperentSetting == UTS3GUI.UTS_TransparentMode.On)
551557
{
552558

553-
ignoreProjection = UTS2INFO.DO_IGNOREPROJECTION;
559+
// ignoreProjection = UTS2INFO.DO_IGNOREPROJECTION;
554560
}
555561
else
556562
{
@@ -559,16 +565,16 @@ void ApplyQueueAndRenderType(Material material, UTS3GUI.UTS_Mode technique, Rend
559565
// material.SetOverrideTag(UTS2INFO.IGNOREPROJECTION, ignoreProjection);
560566
switch (renderQueue)
561567
{
562-
case RenderQueue.None:
568+
case UTS2RenderQueue.None:
563569
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
564570
break;
565-
case RenderQueue.AlphaTest:
571+
case UTS2RenderQueue.AlphaTest:
566572
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
567573
break;
568-
case RenderQueue.AlphaTestMinus1:
574+
case UTS2RenderQueue.AlphaTestMinus1:
569575
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest - 1;
570576
break;
571-
case RenderQueue.Transparent:
577+
case UTS2RenderQueue.Transparent:
572578
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
573579
break;
574580
}

0 commit comments

Comments
 (0)