Skip to content

Instantly share code, notes, and snippets.

@JeOam
Created September 23, 2018 04:46
Show Gist options
  • Save JeOam/30efe6861a78ed23ef0e6252cb82fb9b to your computer and use it in GitHub Desktop.
Save JeOam/30efe6861a78ed23ef0e6252cb82fb9b to your computer and use it in GitHub Desktop.
Unity Shader Notes
@JeOam
Copy link
Author

JeOam commented Sep 26, 2018

#prama surface surf Lambert aplha:fade nolighting
  • Lambert: Use Lambertian Reflectance lighting model
  • nolighting: disable any lighting
  • alpha:face: signal to Cg that this is a Transparent Shader

@JeOam
Copy link
Author

JeOam commented Sep 27, 2018

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; 

@JeOam
Copy link
Author

JeOam commented Sep 27, 2018

Blending textures:

float4 aTexData = tex2D(_ATexture, IN.uv_ATexture); 
float4 bTexData = tex2D(_GTexture, IN.uv_BTexture); 
float4 blendData = tex2D(_BlendTex, IN.uv_BlendTex); 

float4 finalColor = lerp(aTexData, bTexData, blendData.g); 

screen shot 2018-09-24 at 01 02 02

@JeOam
Copy link
Author

JeOam commented Nov 27, 2018

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

@JeOam
Copy link
Author

JeOam commented Nov 27, 2018

图片变灰:由于视觉感光对 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);
}

@JeOam
Copy link
Author

JeOam commented Nov 27, 2018

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