You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
Shader "Unlit/TestFresnelShader" |
|
{ |
|
Properties { |
|
_Color ("Color Tint", Color) = (0, 0, 0, 1) |
|
_ReflectColor ("Reflect Color",Color) = (0, 0, 1, 1) |
|
_FresnelScale ("Fresnel Scale", Range(0, 1)) = 1 |
|
_FresnelBias ("Bias", Range(0, 1)) = 0 |
|
_FresnelPower ("Power", Range(0, 5)) = 3 |
|
} |
|
SubShader { |
|
Tags { "RenderType"="Opaque" "Queue"="Geometry"} |
|
Pass { |
|
Tags { "LightMode"="ForwardBase" } |
|
CGPROGRAM |
|
#pragma multi_compile_fwdbase |
|
#pragma vertex vert |
|
#pragma fragment frag |
|
|
|
#include "UnityCG.cginc" |
|
|
|
fixed4 _Color; |
|
fixed4 _ReflectColor; |
|
|
|
fixed _FresnelScale; |
|
float _FresnelBias; |
|
int _FresnelPower; |
|
|
|
struct a2v { |
|
float4 vertex : POSITION; |
|
float3 normal : NORMAL; |
|
}; |
|
|
|
struct v2f { |
|
float4 pos : SV_POSITION; |
|
float3 worldPos : TEXCOORD0; |
|
fixed3 worldNormal : TEXCOORD1; |
|
fixed3 worldViewDir : TEXCOORD2; |
|
}; |
|
|
|
v2f vert(a2v v) { |
|
v2f o; |
|
o.pos = UnityObjectToClipPos(v.vertex); |
|
o.worldNormal = UnityObjectToWorldNormal(v.normal); |
|
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|
o.worldViewDir = UnityWorldSpaceViewDir(o.worldPos); |
|
return o; |
|
} |
|
|
|
fixed4 frag(v2f i) : SV_Target { |
|
fixed3 worldNormal = normalize(i.worldNormal); |
|
fixed3 worldViewDir = normalize(i.worldViewDir); |
|
fixed3 ambient = ShadeSH9(fixed4(i.worldNormal,1)); |
|
fixed3 reflection = _ReflectColor.rgb; |
|
//fixed fresnel = _FresnelScale + (1 - _FresnelScale) * pow(1 - dot(worldViewDir, worldNormal), 5); |
|
fixed fresnel = max(0,min(1,_FresnelBias+_FresnelScale * pow(1 - dot(worldViewDir, worldNormal),_FresnelPower))); |
|
|
|
fixed3 diffuse = _Color.rgb; |
|
fixed3 color = ambient + lerp(diffuse, reflection, saturate(fresnel)); |
|
return fixed4(color, 1.0); |
|
} |
|
ENDCG |
|
} |
|
} |
|
FallBack "Reflective/VertexLit" |
|
}
|
|
|