//全息影像shader
Shader "Custom/trans" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_DotProduct("Rim effect", Range(-1,1)) = 0.25 //参数
}
SubShader {
Tags {
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
LOD 200
Cull Off
//介绍UnityShader的表面剔除(表面剪裁)技术
// ShaderLab Cull命令
// shaderLab语句 说明
// Cull Off 不剔除
// Cull Back(默认) 剔除背面(内表面)
// Cull Front 剔除正面(外表面)
//这里需要背面
CGPROGRAM
// 这个着色器不是试图模拟一个现实的材料,所以没有必要使用真实的光照模式
// 使用非常便宜的朗伯反射系数来代替。此外,我们应该禁用任何照明和信号
// 这是一个使用alpha:fade:
#pragma surface surf Lambert alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float3 worldNormal; //包含世界法线向量 内部的函数,自动指定
float3 viewDir;//包含视图方向,用于计算视差效果,边缘照明等。
};
// Surface Shader input structure
// The input structure Input generally has any texture coordinates needed by the shader. Texture coordinates must be named “uv” followed by texture name (or start it with “uv2” to use second texture coordinate set).
// Additional values that can be put into Input structure:
// float3 viewDir - contains view direction, for computing Parallax effects, rim lighting etc.
// float4 with COLOR semantic - contains interpolated per-vertex color.
// float4 screenPos - contains screen space position for reflection or screenspace effects. Note that this is not suitable for GrabPass; you need to compute custom UV yourself using ComputeGrabScreenPos function.
// float3 worldPos - contains world space position.
// float3 worldRefl - contains world reflection vector if surface shader does not write to o.Normal. See Reflect-Diffuse shader for example.
// float3 worldNormal - contains world normal vector if surface shader does not write to o.Normal.
// float3 worldRefl; INTERNAL_DATA - contains world reflection vector if surface shader writes to o.Normal. To get the reflection vector based on per-pixel normal map
// , use WorldReflectionVector (IN, o.Normal). See Reflect-Bumped shader for example.
// float3 worldNormal; INTERNAL_DATA - contains world normal vector if surface shader writes to o.Normal. To get the normal vector based on per-pixel normal map, use WorldNormalVector (IN, o.Normal).
fixed4 _Color;
float _DotProduct;
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutput o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
float border = 1 - (abs(dot(IN.viewDir, IN.worldNormal)));//法线向量和视觉朝向取点积,再取绝对值,取负再加1,范围0-1
float alpha = (border * (1 - _DotProduct) + _DotProduct);
//如果border是0,也就是法线和视角向量方向一致,那么中心点的透明度随rim变量变化
//如果border取1,那么法线和视角方向垂直,近似理解为模型边缘,那么透明度总为非透明
//如果rim值取-1,就可以导致越中心的区域 alpha取负
//产生的实际效果,颜色貌似会 对背景色反向?
o.Alpha = c.a*alpha;
}
ENDCG
}
FallBack "Diffuse"
}