-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does what the title says! Co-authored-by: CosmicCoincidence <[email protected]>
- Loading branch information
1 parent
6d95aab
commit c63d426
Showing
78 changed files
with
25,702 additions
and
9,496 deletions.
There are no files selected for viewing
Binary file not shown.
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,102 @@ | ||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' | ||
|
||
Shader "Custom/GlassBackfaceCull" | ||
{ | ||
|
||
Properties | ||
{ | ||
_MainTex("Texture", 2D) = "white" {} | ||
_Color("Color", Color) = (1, 1, 1, 1) | ||
_EdgeColor("Edge Color", Color) = (1, 1, 1, 1) | ||
_EdgeThickness("Silouette Dropoff Rate", float) = 1.0 | ||
} | ||
|
||
SubShader | ||
{ | ||
Tags | ||
{ | ||
"Queue" = "Transparent" | ||
} | ||
|
||
Pass | ||
{ | ||
ZWrite Off | ||
Blend SrcAlpha OneMinusSrcAlpha // standard alpha blending | ||
|
||
CGPROGRAM | ||
|
||
#pragma vertex vert | ||
#pragma fragment frag | ||
|
||
// Properties | ||
sampler2D _MainTex; | ||
uniform float4 _Color; | ||
uniform float4 _EdgeColor; | ||
uniform float _EdgeThickness; | ||
|
||
struct vertexInput | ||
{ | ||
float4 vertex : POSITION; | ||
float3 normal : NORMAL; | ||
float3 texCoord : TEXCOORD0; | ||
}; | ||
|
||
struct vertexOutput | ||
{ | ||
float4 pos : SV_POSITION; | ||
float3 normal : NORMAL; | ||
float3 texCoord : TEXCOORD0; | ||
float3 viewDir : TEXCOORD1; | ||
}; | ||
|
||
vertexOutput vert(vertexInput input) | ||
{ | ||
vertexOutput output; | ||
|
||
// convert input to world space | ||
output.pos = UnityObjectToClipPos(input.vertex); | ||
float4 normal4 = float4(input.normal, 0.0); | ||
output.normal = normalize(mul(normal4, unity_WorldToObject).xyz); | ||
output.viewDir = normalize(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, input.vertex).xyz); | ||
|
||
output.texCoord = input.texCoord; | ||
|
||
return output; | ||
} | ||
|
||
float4 frag(vertexOutput input) : COLOR | ||
{ | ||
// sample texture for color | ||
float4 texColor = tex2D(_MainTex, input.texCoord.xy); | ||
|
||
// apply silouette equation | ||
// based on how close normal is to being orthogonal to view vector | ||
// dot product is smaller the smaller the angle bw the vectors is | ||
// close to edge = closer to 0 | ||
// far from edge = closer to 1 | ||
float edgeFactor = abs(dot(input.viewDir, input.normal)); | ||
|
||
// apply edgeFactor to Albedo color & EdgeColor | ||
float oneMinusEdge = 1.0 - edgeFactor; | ||
float3 rgb = (_Color.rgb * edgeFactor) + (_EdgeColor * oneMinusEdge); | ||
rgb = min(float3(1, 1, 1), rgb); // clamp to real color vals | ||
rgb = rgb * texColor.rgb; | ||
|
||
// apply edgeFactor to Albedo transparency & EdgeColor transparency | ||
// close to edge = more opaque EdgeColor & more transparent Albedo | ||
float opacity = min(1.0, _Color.a / edgeFactor); | ||
|
||
// opacity^thickness means the edge color will be near 0 away from the edges | ||
// and escalate quickly in opacity towards the edges | ||
opacity = pow(opacity, _EdgeThickness); | ||
opacity = opacity * texColor.a; | ||
|
||
float4 output = float4(rgb, opacity); | ||
return output; | ||
} | ||
|
||
ENDCG | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.