diff --git a/Editor/Material/LitOpaqueShaderMapping.cs b/Editor/Material/LitOpaqueShaderMapping.cs new file mode 100644 index 0000000..d435ad7 --- /dev/null +++ b/Editor/Material/LitOpaqueShaderMapping.cs @@ -0,0 +1,52 @@ +using System; +using UnityEngine; + +namespace UnityToRebelFork.Editor +{ + public class LitOpaqueShaderMapping : ShaderMappingBase, IShaderMapping + { + public int Priority { get; } = 0; + + public LitOpaqueShaderMapping(Lazy orchestrator, ExportSettings settings) : base(orchestrator, settings) + { + } + + public bool CanMap(UnityEngine.Shader shader) + { + if (shader.name == Shaders.RBFX.LitOpaqueShaderAdapter.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.RBFX.LitOpaqueShaderAdapter(material); + + model.MatDiffColor = shaderArgs._Color; + model.MatEmissiveColor = (Vector4)shaderArgs._EmissionColor; + model.NormalScale = shaderArgs._BumpScale; + model.AlphaCutoff = shaderArgs._Cutoff; + model.Metallic = shaderArgs._Metallic; + model.Roughness = shaderArgs._Roughness; + + if (shaderArgs._BumpMap != null) + model.Normal = orchestrator.Value.ScheduleExport(shaderArgs._BumpMap); + + if (shaderArgs._EmissionMap != null) + model.Emission = orchestrator.Value.ScheduleExport(shaderArgs._EmissionMap); + + if (shaderArgs._MainTex != null) + model.Albedo = orchestrator.Value.ScheduleExport(shaderArgs._MainTex); + + if (shaderArgs._PBRMap != null) + model.Properties = orchestrator.Value.ScheduleExport(shaderArgs._PBRMap); + + return model; + } + } +} \ No newline at end of file diff --git a/Editor/Material/LitOpaqueShaderMapping.cs.meta b/Editor/Material/LitOpaqueShaderMapping.cs.meta new file mode 100644 index 0000000..e4f4dfb --- /dev/null +++ b/Editor/Material/LitOpaqueShaderMapping.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ce85be14a1549f41a1a5fc3f3541263 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Material/Shaders/RBFX.meta b/Editor/Material/Shaders/RBFX.meta new file mode 100644 index 0000000..3f399b9 --- /dev/null +++ b/Editor/Material/Shaders/RBFX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 039711ffae19c614cb786b587bdedcd0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Material/Shaders/RBFX/LitOpaque.cs b/Editor/Material/Shaders/RBFX/LitOpaque.cs new file mode 100644 index 0000000..b294655 --- /dev/null +++ b/Editor/Material/Shaders/RBFX/LitOpaque.cs @@ -0,0 +1,64 @@ +namespace UnityToRebelFork.Editor.Shaders.RBFX +{ + public class LitOpaqueShaderAdapter + { + public static readonly string ShaderName = "RBFX/LitOpaque"; + + UnityEngine.Material material; + + public LitOpaqueShaderAdapter(UnityEngine.Material material) + { + this.material = material; + } + + public UnityEngine.Texture _MainTex + { + get { return material.GetTexture("_MainTex"); } + } + + public UnityEngine.Texture _BumpMap + { + get { return material.GetTexture("_BumpMap"); } + } + + public UnityEngine.Texture _PBRMap + { + get { return material.GetTexture("_PBRMap"); } + } + + public UnityEngine.Texture _EmissionMap + { + get { return material.GetTexture("_EmissionMap"); } + } + + public UnityEngine.Color _EmissionColor + { + get { return material.GetColor("_EmissionColor"); } + } + + public UnityEngine.Color _Color + { + get { return material.GetColor("_Color"); } + } + + public float _BumpScale + { + get { return material.GetFloat("_BumpScale"); } + } + + public float _Metallic + { + get { return material.GetFloat("_Metallic"); } + } + + public float _Roughness + { + get { return material.GetFloat("_Roughness"); } + } + + public float _Cutoff + { + get { return material.GetFloat("_Cutoff"); } + } + } +} \ No newline at end of file diff --git a/Editor/Material/Shaders/RBFX/LitOpaque.cs.meta b/Editor/Material/Shaders/RBFX/LitOpaque.cs.meta new file mode 100644 index 0000000..515d1f3 --- /dev/null +++ b/Editor/Material/Shaders/RBFX/LitOpaque.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 064b084e5bcf5c2408e57dbc097e8a65 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Material/StandardSpecularShaderMapping.cs b/Editor/Material/StandardSpecularShaderMapping.cs index 28043f7..c3ea29c 100644 --- a/Editor/Material/StandardSpecularShaderMapping.cs +++ b/Editor/Material/StandardSpecularShaderMapping.cs @@ -1,5 +1,6 @@ using System; using UnityEngine; +using UnityToRebelFork.Editor.Shaders; namespace UnityToRebelFork.Editor { @@ -13,7 +14,7 @@ public StandardSpecularShaderMapping(Lazy orchestrator, Expo public bool CanMap(UnityEngine.Shader shader) { - if (shader.name == "Standard (Specular setup)") + if (shader.name == Standard_Specularsetup_ShaderAdapter.ShaderName) return true; return false; } diff --git a/Editor/RebelForkInstaller.cs b/Editor/RebelForkInstaller.cs index f8a2a0b..b14a837 100644 --- a/Editor/RebelForkInstaller.cs +++ b/Editor/RebelForkInstaller.cs @@ -24,8 +24,9 @@ public static void Install(Rbfx.LightInject.ServiceContainer container, ExportSe container.RegisterSingleton(nameof(MobileVertexLitShaderMapping)); container.RegisterSingleton(nameof(StandardShaderMapping)); container.RegisterSingleton(nameof(StandardSpecularShaderMapping)); - container.RegisterSingleton(nameof(DefaultShaderMapping)); container.RegisterSingleton(nameof(LegacyDiffuseShaderMapping)); + container.RegisterSingleton(nameof(LitOpaqueShaderMapping)); + container.RegisterSingleton(nameof(DefaultShaderMapping)); container.RegisterSingleton(); container.Register(); diff --git a/Runtime/LitOpaque.shader b/Runtime/LitOpaque.shader new file mode 100644 index 0000000..00118dc --- /dev/null +++ b/Runtime/LitOpaque.shader @@ -0,0 +1,68 @@ +Shader "RBFX/LitOpaque" +{ + Properties + { + _MainTex ("Albedo (RGB)", 2D) = "white" {} + _BumpMap ("Normal Map", 2D) = "bump" {} + _PBRMap ("PBR Map (R: Roughness, G: Metallic, A: AO)", 2D) = "white" {} + _EmissionMap ("Emission Map", 2D) = "white" {} + _EmissionColor ("Emission Color", Color) = (0,0,0,1) + _Color ("Albedo", Color) = (1,1,1,1) + _BumpScale ("Normal Map Scale", Range(0, 1)) = 1 + _Metallic ("Metallic Multiplier", Range(0, 1)) = 1 + _Roughness ("Roughness Multiplier", Range(0, 1)) = 1 + _Cutoff ("Alpha Mask Threshold", Range(0, 1)) = 0.5 + } + + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 200 + + CGPROGRAM + #pragma surface surf Standard fullforwardshadows + + sampler2D _MainTex; + sampler2D _BumpMap; + sampler2D _PBRMap; + sampler2D _EmissionMap; + fixed4 _Color; + fixed4 _EmissionColor; + float _BumpScale; + float _Metallic; + float _Roughness; + float _Cutoff; + + struct Input + { + float2 uv_MainTex; + float4 color : COLOR; + }; + + void surf (Input IN, inout SurfaceOutputStandard o) + { + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + clip(c.a - _Cutoff); + o.Albedo = c.rgb * IN.color.rgb; + + // PBR map unpacking + half4 pbr = tex2D(_PBRMap, IN.uv_MainTex); + half roughness = pbr.r * _Roughness; + half metallic = pbr.g * _Metallic; + half ao = pbr.a; + + o.Metallic = metallic; + o.Smoothness = 1.0 - roughness; + o.Occlusion = ao; + + // Apply the normal map + o.Normal = UnpackNormalWithScale(tex2D(_BumpMap, IN.uv_MainTex), _BumpScale); + + // Apply emission map + fixed4 emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor; + o.Emission = emission.rgb; + } + ENDCG + } + FallBack "Diffuse" +} diff --git a/Runtime/LitOpaque.shader.meta b/Runtime/LitOpaque.shader.meta new file mode 100644 index 0000000..0130998 --- /dev/null +++ b/Runtime/LitOpaque.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 82f9b11ad505c044c8360e5ee3a24970 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: