0.3:Before We Start
文章著作权归作者所有。转载请联系作者,并在文中注明出处,给出原文链接。
本系列原更新于作者的github博客,这里给出链接。
需要做的准备
首先肯定是需要安装Unity,我这里选择的版本是Unity version :2018.3.7f1。学习任何事物都离不开趁手的工具,Shader也不例外。我们可以选择Sublime Text,JB Rider Free For Student,甚至VS作为我们的编辑器,但试用之后还是觉得VSCode是比较优的选择。下面我们将基于VSCode搭建一个Shaderlab编辑器。(编辑器不带调试功能,我们仍需要借助Unity进行调试。)
首先我们直接从VSCode官网下载VSCode Free ver。打开VSCode,选择Extensions--Search “Shaderlab”--Install “ShaderlabVSCode”。
接着我们配置Shaderlab的json文件。上方菜单:File--Preferences--User Snippets--Search “shaderlab”--选择shader.json进入。
// Place your snippets for shaderlab here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
我们可以看到如上的文档说明,大意是:
在这里你可以定制你的shaderlab语法模板。用 {} 包围整个代码块,每一个模板用 , 分隔开。
对于每一个模板,内部每一个属性也用 , 分隔开。首先为模板起一个名字,对应 "Print to console" ,接着我们声明它的 prefix 属性,这是用于匹配你的模板的检索标志,对应 “log” ,即我们输入log时,匹配栏会出现这个模板。
接着编辑 “body” 部分,这是模板的内容,格式为["string",],在[]内部,每一个字符串自成一行,可以用转义字符实现缩进换行,若想实现高级定制,则可插入 \({number:hint}** 对于每一个 **\) ,会按照 number 从小到大的顺序,给出 hint 提示补全模板,使用 Tab 切换至下一个可编辑的单元,最终光标会停留在 $0 处。
基于这些,我们便可以灵活的配置自己所需的模板。下面也给出一份我自己常用的模板配置,这份模板也会不定期更新。
{
"Shaderlab": {
"prefix": "shaderlab",
"body": [
"Shader \"${1:Shader Name}\" {\n",
"\tProperties {",
"\t\t_MainTex (\"Base (RGB)\", 2D) = \"white\" {}",
"\t\t_Color (\"Color\", Color) = (1, 1, 1, 1)",
"\t}\n",
"\tSubShader {",
"\t\tCGINCLUDE",
"\t\t#include \"UnityCG.cginc\"\n",
"\t\tsampler2D _MainTex;",
"\t\tfloat4 _MainTex_ST;\n",
"\t\tstruct a2v {",
"\t\t\tfloat4 vertex : POSITION;",
"\t\t\tfloat2 texcoord : TEXCOORD0;",
"\t\t};\n",
"\t\tstruct v2f {",
"\t\t\tfloat4 pos : SV_POSITION;",
"\t\t\tfloat2 uv : TEXCOORD0;",
"\t\t};\n",
"\t\tv2f vert(a2v v) {",
"\t\t\tv2f o;",
"\t\t\to.pos = UnityObjectToClipPos(v.vertex);",
"\t\t\to.uv = TRANSFORM_TEX(v.texcoord, _MainTex);",
"\t\t\treturn o;",
"\t\t}\n",
"\t\tfixed4 frag(v2f i) : SV_Target {",
"\t\t\tfixed4 color;",
"\t\t\tcolor = tex2D(_MainTex, i.uv);",
"\t\t\treturn color;",
"\t\t}",
"\t\tENDCG\n",
"\t\tPass {\n",
"\t\t\tCGPROGRAM",
"\t\t\t#pragma vertex vert",
"\t\t\t#pragma fragment frag",
"\t\t\tENDCG",
"\t\t}",
"\t}\n",
"\tFallBack \"Diffuse\"",
"}"
],
"description": "Shaderlab Template"
},
"Range()": {
"prefix": "range",
"body": [
"Range(${1:left}, ${2:right})"
],
"description": "Range for properties"
},
"Pass": {
"prefix": "pass",
"body": [
"Pass {",
"\t$0",
"}"
],
"description": "Pass for Shaderlab Subshader"
},
"Tags": {
"prefix": "tags",
"body": [
"Tags {",
"\t$0",
"}"
],
"description": "Tags in Pass"
}
}
0.3:Before We Start的更多相关文章
- css隐藏元素display:none,opacity:0;filter:alpha(opacity=0-100;,visibility:hidden的区别
在CSS中,让元素隐藏(指屏幕范围内肉眼不可见)的方法很多,有的占据空间,有的不占据空间:有的可以响应点击,有的不能响应点击.我们一般有三种方式:display:none, opacity:0;fil ...
- SignalR 2.0 系列: 开始使用SignalR 2.0
这是微软官方SignalR 2.0教程Getting Started with ASP.NET SignalR 2.0系列的翻译,这里是第四篇:开始使用SignalR 2.0 原文:Getting S ...
- Common Lisp学习笔记(0):从SLIME开始 | 优哉·幽斋
Common Lisp学习笔记(0):从SLIME开始 | 优哉·幽斋 Common Lisp学习笔记(0):从SLIME开始
- [渣译文] SignalR 2.0 系列:SignalR的高频实时通讯
原文:[渣译文] SignalR 2.0 系列:SignalR的高频实时通讯 英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with ASP.N ...
- [渣译文] SignalR 2.0 系列: SignalR 自托管主机
原文:[渣译文] SignalR 2.0 系列: SignalR 自托管主机 英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with ASP.N ...
- [渣译文] SignalR 2.0 系列: 开始使用SignalR 2.0
原文:[渣译文] SignalR 2.0 系列: 开始使用SignalR 2.0 英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with ASP ...
- [渣译文] SignalR 2.0 系列: 支持的平台
原文:[渣译文] SignalR 2.0 系列: 支持的平台 英文渣水平,大伙凑合着看吧,并不是逐字翻译的…… 这是微软官方SignalR 2.0教程Getting Started with ASP. ...
- [渣译文] SignalR 2.0 系列: SignalR简介
原文:[渣译文] SignalR 2.0 系列: SignalR简介 英文渣水平,大伙凑合着看吧,并不是逐字翻译的…… 这是微软官方SignalR 2.0教程Getting Started with ...
- .Net 2.0实例学习:WebBrowser页面与WinForm交互技巧
原文:.Net 2.0实例学习:WebBrowser页面与WinForm交互技巧 最近看到博客园入门教学文章比较流行,自己最近又偷懒比较多,没啥心得,不妨写一篇没啥深度的入门文章吧. 话说有了WebB ...
- SignalR 2.0 系列: SignalR简介
SignalR 2.0 系列: SignalR简介 英文渣水平,大伙凑合着看吧,并不是逐字翻译的…… 这是微软官方SignalR 2.0教程Getting Started with ASP.NET S ...
随机推荐
- eclipse启动时 failed to create the java virtual machine 解决办法
解决步骤: 1.打开eclipse解压目录下的配置文件eclipse.ini: 2.找到 --launcher.XXMaxPermSize 256M 并改为 --launcher.XXMaxPermS ...
- springCloud之配置中心学习
调试了好久,中与在地址栏输入http://localhost:9004/liyong-test/ms-dev.properties,奇迹出现了,终于可以访问我的配置中心了.这次也是碰运气,并没有觉得会 ...
- 守护线程daemon
如下代码: from threading import Thread import time def func1(n): time.sleep(10) print(n) t = Thread(targ ...
- 11.4vue(3)
2018-11-4 20:57:28 越努力越幸运!永远不要高估自己!!!!! 要主动学习!!! 快把vue看完,进行路飞项目!明天整理一下vue知识点!
- poj3335
半平面交&多边形内核.因为没注意了点的情况自闭了. https://blog.csdn.net/qq_40861916/article/details/83541403 这个说的贼好. 多边形 ...
- 设置弹窗、遮罩的样式设置(包括:left、heigh等)
.zhezhao { width:100%; background-color:#000; filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0. ...
- xpinyin模块
import xpinyin s = xpinyin.Pinyin() #一个实例化,以后了解 print(s.get_pinyin('小小军')) #get_pinyin方法,转出来的拼音,每一个汉 ...
- ES6 数组
数组创建 Array.of() 将参数中所有值作为元素形成数组. console.log(Array.of(1, 2, 3, 4)); // [1, 2, 3, 4] // 参数值可为不同类型 con ...
- TZOJ:区间问题
描述 有n项工作,每项工作分别在 si时间开始,ti时间结束.对于每项工作你选择参与与否,如果选择 了参与,那么自始至终就必须全程参与.参与工作的时间段不可以重叠(即使是开始的瞬间和结束的瞬间重叠也是 ...
- array 和 alloc init 以及 new 区别
当你使用new.alloc或copy方法创建一个对象时,该对象的引用计数器值为1.当不再使用该对象时,你要负责向该对象发送一条release或autorelease消息.这样,该对象将在其使用寿命结束 ...