-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export Legacy Shaders/Diffuse shader
- Loading branch information
1 parent
35881e0
commit cc81958
Showing
12 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace UnityToRebelFork.Editor | ||
{ | ||
public class LegacyDiffuseShaderMapping : ShaderMappingBase, IShaderMapping | ||
{ | ||
public int Priority { get; } = 0; | ||
|
||
public bool CanMap(UnityEngine.Shader shader) | ||
{ | ||
if (shader.name == Shaders.LegacyShaders.DiffuseShaderAdapter.ShaderName) | ||
return true; | ||
return false; | ||
} | ||
|
||
public MaterialModel Map(UnityEngine.Material material) | ||
{ | ||
var model = new MaterialModel(); | ||
|
||
MapCommonParameters(material, model); | ||
MapDefaultTechnique(material, model); | ||
|
||
var shaderArgs = new Shaders.LegacyShaders.DiffuseShaderAdapter(material); | ||
|
||
model.MatDiffColor = shaderArgs._Color; | ||
|
||
if (shaderArgs._MainTex != null) | ||
model.Albedo = orchestrator.ScheduleExport(shaderArgs._MainTex); | ||
|
||
return model; | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
Editor/Material/Shaders/LegacyShaders/DiffuseShaderAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace UnityToRebelFork.Editor.Shaders.LegacyShaders | ||
{ | ||
public class DiffuseShaderAdapter | ||
{ | ||
public static readonly string ShaderName = "Legacy Shaders/Diffuse"; | ||
|
||
UnityEngine.Material material; | ||
|
||
public DiffuseShaderAdapter(UnityEngine.Material material) | ||
{ | ||
this.material = material; | ||
} | ||
|
||
public UnityEngine.Color _Color | ||
{ | ||
get { return material.GetColor("_Color"); } | ||
} | ||
|
||
public UnityEngine.Texture _MainTex | ||
{ | ||
get { return material.GetTexture("_MainTex"); } | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/Material/Shaders/LegacyShaders/DiffuseShaderAdapter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.Rendering; | ||
using UnityToRebelFork.Editor; | ||
|
||
namespace UnityToRebelFork | ||
{ | ||
[TestFixture] | ||
public class GenerateShaderAdapter | ||
{ | ||
[Test] | ||
[TestCaseSource(nameof(ShaderNames))] | ||
public void GenerateShader(string shaderName) | ||
{ | ||
var adapterBuilder = new StringBuilder(); | ||
|
||
var pathSeparator = shaderName.LastIndexOf('/'); | ||
var name = shaderName.Substring(pathSeparator + 1); | ||
var nameSpace = (pathSeparator > 0) ? shaderName.Substring(0, pathSeparator) : ""; | ||
nameSpace = nameSpace.Replace('/', '.').Replace(" ", ""); | ||
|
||
var foundShader = UnityEngine.Shader.Find(shaderName); | ||
|
||
if (nameSpace.Length > 0) | ||
adapterBuilder.AppendLine("namespace UnityToRebelFork.Editor.Shaders."+nameSpace); | ||
else | ||
adapterBuilder.AppendLine("namespace UnityToRebelFork.Editor.Shaders"); | ||
adapterBuilder.AppendLine("{"); | ||
adapterBuilder.AppendLine($" public class {name}ShaderAdapter"); | ||
adapterBuilder.AppendLine(" {"); | ||
adapterBuilder.AppendLine($" public static readonly string ShaderName = \"{shaderName}\";"); | ||
adapterBuilder.AppendLine(); | ||
adapterBuilder.AppendLine($" UnityEngine.Material material;"); | ||
adapterBuilder.AppendLine(); | ||
adapterBuilder.AppendLine($" public {name}ShaderAdapter(UnityEngine.Material material)"); | ||
adapterBuilder.AppendLine(" {"); | ||
adapterBuilder.AppendLine(" this.material = material;"); | ||
adapterBuilder.AppendLine(" }"); | ||
|
||
for (int i = 0; i < foundShader.GetPropertyCount(); ++i) | ||
{ | ||
var propertyName = foundShader.GetPropertyName(i); | ||
var propertyType = foundShader.GetPropertyType(i); | ||
switch (propertyType) | ||
{ | ||
case ShaderPropertyType.Color: | ||
adapterBuilder.AppendLine(); | ||
adapterBuilder.AppendLine($" public UnityEngine.Color {propertyName}"); | ||
adapterBuilder.AppendLine(" {"); | ||
adapterBuilder.AppendLine($" get {{ return material.GetColor(\"{propertyName}\"); }}"); | ||
adapterBuilder.AppendLine(" }"); | ||
break; | ||
case ShaderPropertyType.Texture: | ||
adapterBuilder.AppendLine(); | ||
adapterBuilder.AppendLine($" public UnityEngine.Texture {propertyName}"); | ||
adapterBuilder.AppendLine(" {"); | ||
adapterBuilder.AppendLine($" get {{ return material.GetTexture(\"{propertyName}\"); }}"); | ||
adapterBuilder.AppendLine(" }"); | ||
break; | ||
case ShaderPropertyType.Range: | ||
case ShaderPropertyType.Float: | ||
adapterBuilder.AppendLine(); | ||
adapterBuilder.AppendLine($" public float {propertyName}"); | ||
adapterBuilder.AppendLine(" {"); | ||
adapterBuilder.AppendLine($" get {{ return material.GetFloat(\"{propertyName}\"); }}"); | ||
adapterBuilder.AppendLine(" }"); | ||
break; | ||
} | ||
} | ||
|
||
adapterBuilder.AppendLine(" }"); | ||
adapterBuilder.AppendLine("}"); | ||
|
||
TestContext.Out.WriteLine(adapterBuilder.ToString()); | ||
} | ||
|
||
[Test] | ||
public void GenerateShader2() | ||
{ | ||
} | ||
|
||
public static string[] ShaderNames() | ||
{ | ||
return ShaderUtil.GetAllShaderInfo().Select(_=>_.name).ToArray(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "UnityToRebelFork.Tests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityToRebelFork", | ||
"UnityToRebelFork.Editor" | ||
], | ||
"optionalUnityReferences": [ | ||
"TestAssemblies" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": true, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.