Last active
December 16, 2015 13:14
-
-
Save HilariousCow/65b4e5fb9f090c19ef02 to your computer and use it in GitHub Desktop.
So, blender doesn't do vertex alpha, annoyingly, which would be great, as it's a good way to mask out edges of meshs when you have other groovey effects going on the surface (think skyrim's wind gusts). This shader will just take blender's RGB values (i.e. luminescance) and use THAT as the alpha mask. It's otherwise a bog standard Texture * colo…
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 "Unlit/VertexAlphaPlusColour" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_Color("Color", Color) = (1,1,1,1) | |
} | |
SubShader | |
{ | |
Tags { "Queue"="Transparent" "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
Blend SrcAlpha OneMinusSrcAlpha | |
ZWrite Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// make fog work | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR0; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
UNITY_FOG_COORDS(1) | |
float4 vertex : SV_POSITION; | |
float4 color : COLOR0; | |
}; | |
sampler2D _MainTex; | |
float4 _Color; | |
float4 _MainTex_ST; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
o.color = v.color; | |
UNITY_TRANSFER_FOG(o,o.vertex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
// sample the texture | |
fixed4 col = tex2D(_MainTex, i.uv) * _Color; | |
col.a *= i.color;//use vertex color luminescence to adjust alpha | |
// apply fog | |
UNITY_APPLY_FOG(i.fogCoord, col); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment