Last active
July 5, 2018 11:02
-
-
Save keijiro/01e009421a6aa4ac0bc06ab2431b82d3 to your computer and use it in GitHub Desktop.
A Unity shader that detects flipped polygons.
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
Shader "FlipCheck" | |
{ | |
SubShader | |
{ | |
Cull Off | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex Vertex | |
#pragma fragment Fragment | |
#include "UnityCG.cginc" | |
struct Attributes | |
{ | |
float4 position : POSITION; | |
half3 normal : NORMAL; | |
}; | |
struct Varyings | |
{ | |
float4 position : SV_POSITION; | |
half3 normal : NORMAL; | |
}; | |
Varyings Vertex(Attributes input) | |
{ | |
Varyings o; | |
o.position = UnityObjectToClipPos(input.position); | |
o.normal = UnityObjectToWorldNormal(input.normal); | |
return o; | |
} | |
fixed4 Fragment(Varyings input, fixed vface : VFACE) : SV_Target | |
{ | |
fixed3 c = input.normal / 2 + 0.5; | |
c = lerp(c, half3(1, 0, 0), vface < 0); | |
c = GammaToLinearSpace(c); | |
return fixed4(c, 1); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment