-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix export of metallic and normal texture map. Add support for any shader that can support metallic roughness workflow. #133
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c7fca3
Fix export of metallic and normal texture map. Add support for any sh…
justinctlam ee18e8b
Addressed feedback
justinctlam 4fb29b3
Revert irrelevant files
justinctlam 42c2124
Fix indentation
justinctlam 435ad84
Update accessor for structs and enum
justinctlam a717efa
Update formatting
justinctlam e7f1308
Address feedback
justinctlam a578d25
Merge branch 'master' into master
75759a4
Remove exporter dependency on UnityEditor.
justinctlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
Shader "Hidden/MetalGlossChannelSwap" | ||
{ | ||
Properties | ||
{ | ||
_MainTex ("Texture", 2D) = "white" {} | ||
} | ||
SubShader | ||
{ | ||
// No culling or depth | ||
Cull Off ZWrite Off ZTest Always | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
|
||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 uv : TEXCOORD0; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float2 uv : TEXCOORD0; | ||
float4 vertex : SV_POSITION; | ||
}; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.vertex = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
sampler2D _MainTex; | ||
|
||
float4 frag (v2f i) : SV_Target | ||
{ | ||
float4 col = tex2D(_MainTex, i.uv); | ||
// From the GLTF 2.0 spec | ||
// The metallic-roughness texture. The metalness values are sampled from the B channel. | ||
// The roughness values are sampled from the G channel. These values are linear. | ||
// If other channels are present (R or A), they are ignored for metallic-roughness calculations. | ||
// | ||
// Unity, by default, puts metallic in R channel and glossiness in A channel. | ||
// Unity uses a metallic-gloss texture so we need to invert the value in the g channel. | ||
// | ||
// Conversion Summary | ||
// Unity R channel goes into B channel | ||
// Unity A channel goes into G channel, then inverted | ||
return float4(1, 1 - col.a, col.r, 1); | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
UnityGLTF/Assets/Resources/MetalGlossChannelSwap.shader.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Shader "Hidden/NormalChannel" | ||
{ | ||
Properties | ||
{ | ||
_MainTex ("Texture", 2D) = "white" {} | ||
} | ||
SubShader | ||
{ | ||
// No culling or depth | ||
Cull Off ZWrite Off ZTest Always | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
|
||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 uv : TEXCOORD0; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float2 uv : TEXCOORD0; | ||
float4 vertex : SV_POSITION; | ||
}; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.vertex = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
sampler2D _MainTex; | ||
|
||
fixed4 frag (v2f i) : SV_Target | ||
{ | ||
float4 col = tex2D(_MainTex, i.uv); | ||
// If a texture is marked as a normal map | ||
// the values are stored in the A and G channel. | ||
return float4(col.a, col.g, 1, 1); | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string.IsNullOrEmpty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated