Shader "NewShader/Fresnel"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_FresnelIntensity("FresnelIntensity",Float)=5
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend One One
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct a2v
{
float4 vertex : POSITION;
float4 color : COLOR;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : SV_POSITION;
float3 texcoord : TEXCOORD0;
float3 texcoord1 : TEXCOORD1;
};
fixed4 _Color;
float _FresnelIntensity;
v2f vert ( a2v v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.texcoord.xyz = worldPos;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.texcoord1.xyz = worldNormal;
return o;
}
fixed4 frag (v2f i ) : SV_Target
{
float3 worldPos = i.texcoord.xyz;
float3 worldViewDir = UnityWorldSpaceViewDir(worldPos);
worldViewDir = normalize(worldViewDir);
float3 worldNormal = i.texcoord1.xyz;
float fresnelColor = ( 0.0 + 1.0 * pow( 1.0 - dot( worldNormal, worldViewDir ), _FresnelIntensity ) )* _Color;
float4 col = fresnelColor * _Color;
return col;
}
ENDCG
}
}
}
|