Created
September 23, 2018 04:46
-
-
Save JeOam/30efe6861a78ed23ef0e6252cb82fb9b to your computer and use it in GitHub Desktop.
Unity Shader Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tags
are used to add infomation about how the object is going to be rendered. Unity has provided us with some default render queues, each with a unique value that directs Unity when to draw the object to the screen.
This are built-in render queues:
Render queue | Desc | value |
---|---|---|
Background |
This render queue is rendered first. It is used for skyboxes and so on. | 1000 |
Geometry |
This is the default render queue. This is used for most objects. Opaque geometry use this queue. | 2000 |
AlphaTest |
'Alpha-tested geometry uses this queue. It's different from the Geometry queue as it's more efficient to render alpha-tested objects after all the solid objects are drawn. | 2450 |
Transparent |
This render queue is rendered after Geometry and AlphaTest queues in back-to-front order. Anything alpha-blended (that is, shaders that don't write to the depth buffer) should go here, for example, glass and particle effects. | 3000 |
Overlay |
This render queue is meant for overlay effects. Anything rendered last should go here, for example, lens flares. | 4000 |
#prama surface surf Lambert aplha:fade nolighting
Lambert
: Use Lambertian Reflectance lighting modelnolighting
: disable any lightingalpha:face
: signal to Cg that this is a Transparent Shader
Holographic Effect:
float4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
float border = 1 - (abs(dot(IN.viewDir, IN.worldNormal)));
float alpha = (border * (1 - _DotProduct) + _DotProduct);
// viewDir 是平面的 nomal direction
// dot: 0 border: 1 alpha: 向量正
// _DotProduct: 0.25 alpha: 1
// _DotProduct: 0.75 alpha: 1
// dot: 0.5 border: 0.5 alpha:
// _DotProduct: 0.25 alpha: 0.625
// _DotProduct: 0.75 alpha: 0.875
// dot: 1 border: 0 alpha: 向量平行
// _DotProduct: 0.25 alpha: 0.25
// _DotProduct: 0.75 alpha: 0.75
o.Alpha = c.a * alpha;
sampler2D myTex;
float4 myTex_ST; // 附带的一个变量
// ...
float2 tiling = myTex_ST.xy; // 放大缩小的倍数
float2 offset = myTex_ST.zw; // 位移
float4 o = tex2D(myTex, i.uv * tiling + offset)
return o
图片变灰:由于视觉感光对 R,G, B 的敏感度不一样,所以取不同的权重。
float4 grayScale(float4 v) {
float g = v.r * 0.299 + v.g * 0.578 + v.b * 0.114;
return float4(g, g, g, v.a);
}
if (w < 0) w = 0;
if (w > 1) w = 1;
// 等于
w = clamp(w, 0, 1);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_Time
: This built-in variable return a variable of thefloat4
type, meaning that each component of this variable contians different values of time as it pertains to game time.Unity - Manual: Built-in shader variables