Fresnel reflection of Unity3d shaderlab cubic graph
Fresnel reflection is a relatively common type of reflection, and when our eyes are on the surface of the object, the amount of reflection increases significantly,
We can see this on almost any surface of the object that supports the reflective type, and we'll do it next.
Create Shader and Materialfirst, followed by the cube diagram of the previous section. The code changes less, look directly at the following completion code:
Code Start--------------------------------------------------------------------------
Shader "91ygame/fresnelreflection" {
Properties {
_maintint ("Diffuse Tint", Color) = (1,1,1,1)
_maintex ("Base (RGB)", 2D) = "White" {}
_cubemap ("CubeMap", CUBE) = "" "{}
_reflamount ("Reflection Amount", Range (0.1,3)) =0.5
_rimpower ("Fresnel Falloff", Range (0.1,3)) =1
reflection Color ;
_speccolor ("Specular color", color) = (1,1,1,1)
Reflection Strength Value ;
_specpower ("Specular Power", Range (0.02,1)) =0.5
}
Subshader {
Tags {"Rendertype" = "Opaque"}
LOD 200
Cgprogram
Use Unity 's built-in blinnphong lighting model ;
#pragma surface surf Blinnphong
use Shader Mode 3.0;
#pragma target 3.0
Sampler2d _maintex;
Samplercube _cubemap;
FLOAT4 _maintint;
float _reflamount;
float _rimpower;
float _specpower;
struct Input {
FLOAT2 Uv_maintex;
FLOAT3 WORLDREFL;
FLOAT3 Viewdir;
};
void Surf (Input in, InOut surfaceoutput o) {
Half4 C = tex2d (_maintex, In.uv_maintex);
Reverses the value of 0-1 obtained by the saturate function;
float rim = 1.0-saturate (dot (o.normal,normalize (in.viewdir)));
Rim = POW (rim,_rimpower);
Calculate reflectivity;
O.albedo = C.rgb*_maintint.rgb;
Calculating spontaneous light and assigning values;
O.emission = (Texcube (_CUBEMAP,IN.WORLDREFL). Rgb*_reflamount) *rim;
Mirror-assigned value;
O.specular = _specpower;
The gloss value is assigned;
O.gloss = 1;
O.alpha = C.A;
}
Endcg
}
FallBack "Diffuse"
}
Code End-----------------------------------------------------------------------------
Finally, return to unityand see the results below. Still on the left is our newest Fresnel reflex effect:
In the above implementation process described in more detail, we simply pass an attenuation value, so that it can be too much or too little to adjust the surface reflection, by comparing the line of sight direction with the surface normals,
We can calculate the attenuation value that the camera faces. We then invert the value to achieve a simple matte effect so that the edges of the object's surface become whiter and the camera's orientation is darker.
Fresnel reflection of Unity3d shaderlab cubic graph