[UnityShader基础]08.UI-Default.shader
参考链接:
https://zhuanlan.zhihu.com/p/32561155
https://blog.csdn.net/WuShangLZ/article/details/80401441
https://www.jianshu.com/p/2d98fad196d2
unity版本:2018.3.8f1
内置UI-Default.shader:
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) Shader "UI/Default"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (,,,) _StencilComp ("Stencil Comparison", Float) =
_Stencil ("Stencil ID", Float) =
_StencilOp ("Stencil Operation", Float) =
_StencilWriteMask ("Stencil Write Mask", Float) =
_StencilReadMask ("Stencil Read Mask", Float) = _ColorMask ("Color Mask", Float) = [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) =
} SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
} Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
} Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask] Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0 #include "UnityCG.cginc"
#include "UnityUI.cginc" #pragma multi_compile __ UNITY_UI_CLIP_RECT
#pragma multi_compile __ UNITY_UI_ALPHACLIP struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
}; struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
}; sampler2D _MainTex;
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
float4 _MainTex_ST; v2f vert(appdata_t v)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = v.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); OUT.color = v.color * _Color;
return OUT;
} fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color; #ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#endif #ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif return color;
}
ENDCG
}
}
}
1.模板测试
2.
UnityGet2DClipping的定义在UnityUI.cginc中:
inline float UnityGet2DClipping (in float2 position, in float4 clipRect)
{
float2 inside = step(clipRect.xy, position.xy) * step(position.xy, clipRect.zw);
return inside.x * inside.y;
}
step(a, x):如果a>x,返回0;否则,返回1
clipRect:左下角为xy,右上角为zw
因此,也就是说,如果点不在clipRect中,则返回0
[UnityShader基础]08.UI-Default.shader的更多相关文章
- javaEE基础08
javaEE基础08 一.继承 特点:继承父类的属性和方法,单继承(多继承) 特性:方法的复写(重写) 比如:人可以养狗 人------>狗:整体和部分(拥有)关系 关键字:extends 结构 ...
- [UnityShader基础]03.透明度混合
如果要渲染半透明物体,那么就需要用到透明度混合. 需要注意的有这几点: 1.设置标签:Tags { "Queue"="Transparent" "Ig ...
- Python基础08 面向对象的基本概念
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 谢谢逆水寒龙,topmad和Liqing纠错 Python使用类(class)和对 ...
- Java基础08 继承
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 继承(inheritance)是面向对象的重要概念.继承是除组合(composit ...
- android插件技术-apkplug于OSGI服务基础-08
我们提供 apkplug 下OSGI使用demo 源代码托管地址为 http://git.oschina.net/plug/OSGIService 一 OSGI与android Service 异同点 ...
- <Android基础>(三) UI开发 Part 3 RecyclerView
RecyclerView 1)RecyclerView的基本用法 2)横向滚动和瀑布流滚动 3)注册点击事件 3.6 强大的滚动控件 RecyclerView ListView缺点: 1.不使用技巧优 ...
- [UnityShader基础]07.MaterialPropertyDrawer
参考链接: https://blog.csdn.net/e295166319/article/details/60141677 https://docs.unity3d.com/ScriptRefer ...
- [UnityShader基础]06.#pragma multi_compile
参考链接: https://blog.csdn.net/qq826364410/article/details/81774741 https://docs.unity3d.com/Manual/SL- ...
- [UnityShader基础]05.模板测试
参考链接: https://blog.csdn.net/u011047171/article/details/46928463 https://blog.csdn.net/JohnBlu/articl ...
随机推荐
- linux中mysql配置文件和jdk环境变量
mysql配置文件 [client]default-character-set = utf8mb4 [mysql]socket = /var/lib/mysql/mysql.sockdefault-c ...
- 增加删除的js
<!doctype html><html lang="en"> <head> <meta charset="UTF-8&quo ...
- poj 3641 快速幂
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- 谈一谈java中的Canves机制
0--写在前面: 很多初学java的童鞋,常常很苦恼,一天天的都跟命令行较劲,好像很无聊的样子,如果能跳出命令行做出界面甚至一个画图界面,那将是一件很兴奋的事情:也可以让编程变的有趣:有脑洞的同学还可 ...
- HttpClient设置连接超时时间
https://www.cnblogs.com/winner-0715/p/7087591.html 使用HttpClient,一般都需要设置连接超时时间和获取数据超时时间.这两个参数很重要,目的是为 ...
- js for循环中定义clike事件由于闭包导致的循环变量获取不到的问题
在网上找的 记下来以备不时之需 案例; 本人有一个数组按钮 循环数组按钮 给每个按钮添加click事件 原本以为搞定但是出现了 每个按钮都是数组最后的方法 然后查找问题 发现onclike事件中的i ...
- python通配符之glob模块
转自:https://blog.csdn.net/dcrmg/article/details/78309469 官方链接:https://docs.python.org/3.6/library/glo ...
- dd/MMM/yyyy:hh:mm:ss +0800日期格式的转化
private static void myHandler() throws ParseException { String dtime1 = "23/Apr/2019:04:08:00 + ...
- vn.trader的Ubuntu运行环境搭建教程
作者:量衍投资 转载请注明来源:维恩的派(www.vnpie.com) 准备Ubuntu 建议使用一个新安装干净的Ubuntu环境(如果你一定要使用老环境也行,万一不幸掉坑后再回到这步就好),我这里使 ...
- mysql update where
UPDATE car_approval a JOIN car_distribute b ON a.id = b.APPROVAL_FOR_CAR_ID SET a.APPROVAL_STATUS = ...