Hi andeeee.
I need to apply transparency effect on SkinSpecular.shader:
Shader "Skin/Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_Wrap ("Wrap lighting", Range(0,1)) = 0.5
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
}
// ------------------------------------------------------------------
// Fragment program
SubShader {
Blend AppSrcAdd AppDstAdd
Fog { Color [_AddFog] }
TexCount 4
// Ambient pass
// This does ambient + rim lighting. Note that if you have vertexlit
// lights in the scene, then standard vertex lighting will be used instead,
// so you'll lose rim lighting.
Pass {
Name "BASE"
Tags {"LightMode" = "PixelOrNone"}
CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
V2F_POS_FOG;
float2 uv;
float3 viewDir;
float3 normal;
};
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.normal = v.normal;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.viewDir = ObjSpaceViewDir( v.vertex );
return o;
}
uniform float4 _Color;
uniform float4 _RimColor;
uniform float _RimPower;
uniform sampler2D _MainTex;
float4 frag (v2f i) : COLOR
{
i.normal = normalize(i.normal);
i.viewDir = normalize(i.viewDir);
half4 texcol = tex2D( _MainTex, i.uv );
// rim factor
float rim = 1.0 - saturate(dot( i.normal, i.viewDir ));
half3 ambient = texcol.rgb * _PPLAmbient.rgb * 2;
half3 rimcolor = pow( rim, _RimPower ) * _RimColor.rgb;
return float4( ambient + rimcolor, texcol.a * _Color.a );
}
ENDCG
}
// Vertex lights
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
Lighting On
Material {
Diffuse [_Color]
Emission [_PPLAmbient]
Specular [_SpecColor]
Shininess [_Shininess]
}
SeparateSpecular On
CGPROGRAM
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
half4 frag (v2f_vertex_lit i) : COLOR {
return VertexLight( i, _MainTex );
}
ENDCG
}
// Pixel lights
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#pragma multi_compile_builtin_noshadows
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
float3 uvK; // xy = UV, z = specular K
float3 viewDir;
float3 normal;
float3 lightDir;
};
uniform float _Shininess;
uniform float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.normal = v.normal;
o.uvK.xy = TRANSFORM_TEX(v.texcoord,_MainTex);
o.uvK.z = _Shininess * 128;
o.lightDir = ObjSpaceLightDir( v.vertex );
o.viewDir = ObjSpaceViewDir( v.vertex );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
uniform sampler2D _MainTex;
uniform float _Wrap;
// Mostly copied from UnityCG.cginc; modified to use wrap lighting
// instead of regular diffuse.
inline half4 SpecularLightWrap( half3 lightDir, half3 viewDir, half3 normal, half4 color, float specK, half atten )
{
normal = normalize(normal);
lightDir = normalize(lightDir);
viewDir = normalize(viewDir);
half3 h = normalize( lightDir + viewDir );
// This would be regular diffuse component
//half diffuse = dot( normal, lightDir );
// This is "wrap diffuse" lighting.
// Note that if you know the _Wrap parameter you will use, the
// shader can be optimized. E.g. if _Wrap is 1.0, then putting that
// and simplifying the math becomes just
// half diffuse = dot(normal, lightDir) * 0.5 + 0.5;
half diffuse = max(0.0, (dot(normal, lightDir) + _Wrap) / (1.0 + _Wrap));
float nh = saturate( dot( h, normal ) );
float spec = pow( nh, specK ) * color.a;
spec *= diffuse;
half4 c;
c.rgb = (color.rgb * _ModelLightColor0.rgb * diffuse + _SpecularLightColor0.rgb * spec) * (atten * 2);
c.a = _SpecularLightColor0.a * spec * atten; // specular passes by default put highlights to overbright
return c;
}
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D( _MainTex, i.uvK.xy );
return SpecularLightWrap( i.lightDir, i.viewDir, i.normal, texcol, i.uvK.z, LIGHT_ATTENUATION(i) );
}
ENDCG
}
}
Fallback "Specular"
}