Last active
September 15, 2015 14:58
-
-
Save EsProgram/3f0209a1d7575db13b5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "Custom/TransEmissionVF" { | |
Properties{ | |
_MainTex("Texture", 2D) = "white"{} | |
_Emission("Emission", Range(0, 1)) = 0.1 | |
_RimWidth("RimWidth", Range(0.5, 5.0)) = 2 | |
} | |
SubShader{ | |
//Queue = Transparetとタグが付けられたオブジェクトのレンダリング順(キュー)が最後の方に回される | |
//そうしないと半透明にならないため | |
Tags{"Queue"="Transparent"} | |
//Blend SrcFactor DstFactor の形式 | |
//SrcFactor が Sourceの要素(これからレンダリングされるピクセル) | |
//2つ目に指定するのが Destinationの要素(既にレンダリングされている)を指定 | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata_t | |
{ | |
float4 vertex:POSITION; | |
float3 normal:NORMAL; | |
float4 texcoord:TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 pos:POSITION; | |
float3 viewDir:Any; | |
float3 normal:NORMAL; | |
float2 uv:TEXCOORD0; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float _Emission; | |
float _RimWidth; | |
v2f vert(appdata_t v) | |
{ | |
v2f o; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.viewDir = normalize(WorldSpaceViewDir(v.vertex)); | |
o.normal = normalize(v.normal); | |
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); | |
return o; | |
} | |
float4 frag(v2f i) :COLOR{ | |
half rim = saturate(dot(i.normal, i.viewDir)); | |
float4 col; | |
col.rgb = tex2D(_MainTex, i.uv).rgb; | |
//モデルの外側ほど透明に | |
col.a = pow(rim, _RimWidth); | |
//白色を加算(発光) | |
col.rgb += _Emission * rim; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment