-
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.
- Loading branch information
1 parent
92dfc69
commit 8aac380
Showing
9 changed files
with
227 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace UnityToRebelFork.Editor | ||
{ | ||
public class LitOpaqueShaderMapping : ShaderMappingBase, IShaderMapping | ||
{ | ||
public int Priority { get; } = 0; | ||
|
||
public LitOpaqueShaderMapping(Lazy<ExportOrchestrator> 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; | ||
} | ||
} | ||
} |
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.
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,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"); } | ||
} | ||
} | ||
} |
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,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" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.