Shader "ShaderDemo/AlphaMap" {
Properties {
_Texture ("Texture", 2D) = "white" {}
_outlineWidth ("outline Width", Float ) = 0.02
_outlineColor ("outline Color", Color) = (0.2438253,0.9852941,0.2173443,1)
_Normal ("Normal", 2D) = "bump" {}
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
Pass {
Name "Outline"
Tags {
}
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float _outlineWidth;
uniform float4 _outlineColor;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : SV_POSITION;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, float4(v.vertex.xyz + v.normal*_outlineWidth,1));
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
return fixed4(_outlineColor.rgb,0);
}
ENDCG
}
Pass {
Name "ForwardBase"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform sampler2D _Texture; uniform float4 _Texture_ST;
uniform sampler2D _Normal; uniform float4 _Normal_ST;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 uv0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 uv0 : TEXCOORD0;
float4 posWorld : TEXCOORD1;
float3 normalDir : TEXCOORD2;
float3 tangentDir : TEXCOORD3;
float3 binormalDir : TEXCOORD4;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.uv0;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/// Normals:
float2 node_745 = i.uv0;
float3 normalLocal = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_745.rg, _Normal))).rgb;
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 halfDirection = normalize(viewDirection+lightDirection);
// Lighting:
float attenuation = 1;
float3 attenColor = attenuation * _LightColor0.xyz;
/// Diffuse:
float NdotL = dot( normalDirection, lightDirection );
float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.xyz;
/ Gloss:
float gloss = 0.5;
float specPow = exp2( gloss * 10.0+1.0);
// Specular:
NdotL = max(0.0, NdotL);
float3 specularColor = UNITY_LIGHTMODEL_AMBIENT.rgb;
float3 specular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
float3 finalColor = 0;
float3 diffuseLight = diffuse;
finalColor += diffuseLight * tex2D(_Texture,TRANSFORM_TEX(node_745.rg, _Texture)).rgb;
finalColor += specular;
/// Final Color:
return fixed4(finalColor,1);
}
ENDCG
}
Pass {
Name "ForwardAdd"
Tags {
"LightMode"="ForwardAdd"
}
Blend One One
ZWrite Off
Fog { Color (0,0,0,0) }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDADD
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#pragma multi_compile_fwdadd
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform sampler2D _Texture; uniform float4 _Texture_ST;
uniform sampler2D _Normal; uniform float4 _Normal_ST;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 uv0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 uv0 : TEXCOORD0;
float4 posWorld : TEXCOORD1;
float3 normalDir : TEXCOORD2;
float3 tangentDir : TEXCOORD3;
float3 binormalDir : TEXCOORD4;
LIGHTING_COORDS(5,6)
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.uv0;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/// Normals:
float2 node_746 = i.uv0;
float3 normalLocal = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_746.rg, _Normal))).rgb;
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
float3 halfDirection = normalize(viewDirection+lightDirection);
// Lighting:
float attenuation = LIGHT_ATTENUATION(i);
float3 attenColor = attenuation * _LightColor0.xyz;
/// Diffuse:
float NdotL = dot( normalDirection, lightDirection );
float3 diffuse = max( 0.0, NdotL) * attenColor;
/ Gloss:
float gloss = 0.5;
float specPow = exp2( gloss * 10.0+1.0);
// Specular:
NdotL = max(0.0, NdotL);
float3 specularColor = UNITY_LIGHTMODEL_AMBIENT.rgb;
float3 specular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
float3 finalColor = 0;
float3 diffuseLight = diffuse;
finalColor += diffuseLight * tex2D(_Texture,TRANSFORM_TEX(node_746.rg, _Texture)).rgb;
finalColor += specular;
/// Final Color:
return fixed4(finalColor * 1,0);
}
ENDCG
}
}
FallBack "Diffuse"
}