UNITY SHADER入门精要 看了将近三个月,虽然去年因为有点事情暂停了看书计划,今年在业余时间一直看,终于看完了。大致了解了shader的渲染,但是写shader还是。。。。。。需要多看大佬的shader代码,学习更多的书籍。
ch2_0.渲染流水线:
应用阶段->几何阶段->光栅化阶段
应用阶段:输出渲染图元
几何阶段:处理所有和我们要绘制的几何相关的事情, 将顶点坐标变换到屏幕坐标
光栅化阶段:决定每个渲染图元中的那些像素要绘制在屏幕上
ch2_1.注意OpenGL和DirectX的坐标轴:
ch3_0.部分专业名词介绍
#pragma surface surfaceFunction lightModel[optionalparams]
声称着色器 表面着色器 着色器代码名称 光照模型
It uses #pragma surface ... directive to indicate it’s a surface shader.
eg:#pragma surface surf Standard fullforwardshadows
介绍lightModel
1)Standard:
This lighting model uses SurfaceOutputStandard output struct,
and matches the Standard (metallic workflow) shader in Unity.
2)Standard:
This Specular lighting model uses SurfaceOutputStandardSpecular output struct,
and matches the Standard (specular setup) shader in Unity.
3).Lambert and BlinnPhong:郎伯模型
This lighting models are not physically based (coming from Unity 4.x),
but the shaders using them can be faster to render on low-end hardware.
3.Unity shader类型
1)Standard Surface Shader:标准光照模型
2)Standard Surface Shader(instanced)
3)Unlit Shader:不包含光照,包含雾效
4)Image Effect Shader:实现屏幕后处理效果
5)Compute Shader:产生一个特殊的shader文件,目的是利用cpu的并行性进行一些与常规渲染流水线无关·
ch3_1.Unity Shader语法
查API:https://docs.unity3d.com/Manual/SL-CullAndDepth.html
SubShader{
Tags {}
Log 200
Pass{
.........
Cull off
.......
}
}
UsePass :Pass的名字时候一定要大写,
ch3_1.自定义材质编辑界面:https://docs.unity3d.com/Manual/SL-CustomShaderGUI.html
ch4_0.unity内置的变化矩阵:
举例:把顶点从观察空间变换到模型空间
ch4_1.摄像机和屏幕参数
ch4_2.CG是行优先,一行一行的填充矩阵。Unity Shader使用的是行类型,但是有一种矩阵类型Matrix4x4是列优先。