当前位置:网站首页>UnityShader入门学习(三)——Unity的Shader
UnityShader入门学习(三)——Unity的Shader
2022-07-31 14:09:00 【番茄猿】
1 Unity Shader介绍
1.1 Unity Shader的基础:ShaderLab
1.2 Unity Shader属性块
Shader ""
{
Properties
{
_Int("Int", Int) = 2
_Float("Float", float) = 1.5
_Range("Range", range(0.0, 2.0)) = 1.0
_Color("Color", Color) = (1, 1, 1, 1)
_Vector("Vector", Vector) = (1, 4, 3, 8)
_MainTex("Texture", 2D) = "white"{
}
_3D("3D", 3D) = "black"{
}
}
}
1.3 Unity Shader SubShader
Tags
Tags可以写在SubShader的一开始(所有的Pass用),也可以写在Pass块的内部(该Pass用)
渲染设置
同Tags一样也可以写在Pass中或者写在Pass外面(SubShader一开始)
Pass介绍
Pass里面可以定义Pass名称
Pass里面的Tags还可以有额外的设置
还有CG语言所写的代码,主要是顶点片元着色器,使用以下关键字包裹
CGPROGRAM
ENDCG
FallBack
2 SurfaceShader介绍
SurfaceShader实际上是在顶点、片元着色器的基础上又进行了一层的封装,我们可以通过Show GenerateCode来查看到。(我们可以看到编译后的顶点、片元着色器是非常复杂的)
SurfaceShader的结构和前面的顶点、片元着色器的结构是一样的。主要区别在于SubShader中。
3 UnityShader != 真正的Shader
Unity Shader实际上指的就是一个ShaderLab文件。以.shader作为后缀的一种文件。在Unity shader里面,我们可以做的事情远多于一个传统意义上的Shader。
在传统的shader中,我们仅可以编写特定类型的Shader,例如顶点着色器,片元着色器等。在Unity Shader中,我们可以在同一个文件里面同时包含需要的顶点着色器和片元着色器代码。
在传统shader中,我们无法设置一些渲染设置,例如是否开启混合,深度测试等,这些是开发者在另外的代码中自行设置的。而Unity shader中,我们通过一行特定的指令就可以完成这些设置。
在传统shader中,我们需要编写冗长的代码设置着色器的输入和输出,要小心的处理这些输入输出的位置对应关系等。而在Unity shader中,我们只需要在特定语句块中声明一些属性,就可以依靠材质来方便的改变这些属性。而对于模型自带的数据(如顶点,纹理坐标,法线等),Unity Shader也提供了直接访问的方法,不需要开发者自行编码来传给着色器。
边栏推荐
- AI cocoa AI frontier introduction (7.31)
- MySQL 23道经典面试吊打面试官
- Unity study notes Description of AVPro video jump function (Seeking)
- C# using ComboBox control
- Description of Hikvision camera streaming RTSP address rules
- All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
- mysql8, starttime的下一个值作为endtime的上一个值?
- hyperf的启动源码分析(二)——请求如何到达控制器
- 对数字化时代的企业来说,数据治理难做,但应该去做
- 推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
猜你喜欢
MySQL [subquery]
CodeIgniter 打开错误日志
Nuget package and upload tutorial
Open Inventor 10.12 Major Improvements - Harmony Edition
ADS communicate with c #
技能大赛训练题:MS15_034漏洞验证与安全加固
CLion用于STM32开发
For enterprises in the digital age, data governance is difficult, but it should be done
已解决(pymysqL连接数据库报错)pymysqL.err.ProgrammingError: (1146,“Table ‘test.students‘ doesn‘t exist“)
最近很火的国产接口神器Apipost体验
随机推荐
Open Inventor 10.12 Major Improvements - Harmony Edition
搭建私有的的Nuget包服务器教程
MySQL 23 classic interviews hang the interviewer
技能大赛训练题: 子网掩码划分案例
The magic of SQL MERGE statement (detailed instructions)
Shell script classic case: backup of files
Why do we need to sub-library and sub-table?
ERROR: Failed building wheel for osgeo
Sentinel服务熔断和降级
mysql8, starttime的下一个值作为endtime的上一个值?
Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details
redhat/openssl生成自签ca证书并使用
[Pytorch] torch.argmax() usage
The use of thread pool two
Install the latest pytorch gpu version
技能大赛训练题:交换机虚拟化练习
机器学习模型验证:被低估的重要一环
技能大赛训练题:ftp 服务攻防与加固
我把问烂了的MySQL面试题总结了一下
Miller_Rabin Miller Rabin probability sieve [template]