BlueRoseNote/07-Other/Unity/Unity-Chan Toon Shader 学习.md

105 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

2023-06-29 11:55:02 +08:00
## 资料
- [ ] 游戏诞生之日09 - 美术篇 卡通渲染着色器 UTS2 https://zhuanlan.zhihu.com/p/137288013
- [ ] MMD联动Unity学习笔记 Vol.42 UTS2进阶慎入长篇多图预警https://www.bilibili.com/read/cv3347514
- [ ] 官方文档https://github.com/unity3d-jp/UnityChanToonShaderVer2_Project/blob/release/urp/2.3.0/Documentation~/index.md
- [ ] 官方文档——属性解释https://github.com/unity3d-jp/UnityChanToonShaderVer2_Project/blob/release/urp/2.3.0/Documentation~/Props_en.md
## 总览
没有后处理效果
两种着色方式:
DoubleShadeWithFeatherUTS/UniversalToon 的标准工作流程模式。允许 2 种阴影颜色(双阴影颜色)和颜色之间的渐变(羽化)。
ShadingGradeMap更高级的工作流程模式。除了 DoubleShadeWithFeather 功能之外,此着色器还可以保存称为 ShadingGradeMap 的特殊贴图。
- UniversalToonInput.hlsl定义各种变量与资料实现采样AO贴图`SampleOcclusion()`与初始化Lit表面数据`InitializeStandardLitSurfaceData()`
- UniversalToonHead.hlsl定义了一些宏与函数雾、坐标转换、线性空间与GammaSpace转换相关。
## 光照
## Pass
顺序为:
1. Outline
2. ForwardLit
3. ShadowCaster
4. DepthOnly
模板测试语法:
```c#
Stencil
{
Ref[_StencilNo] //设置渲染的模板缓存值0~255
Comp[_StencilComp] //模板测试的通过条件有除了equal还有Greater、Less、Always、Never等类似ZTest。
Pass[_StencilOpPass] //表示通过模板测试和Z测试注意是都通过的像素怎么处置它的模板值。
Fail[_StencilOpFail] //表示通过了模板测试但没通过Z测试的像素怎么处置它的模板值。
}
```
### Outline
```c#
Tags {"LightMode" = "SRPDefaultUnlit"}:使用这个LightMode标签值在渲染物体时绘制一个额外的Pass。也是URP光照模式的默认值。
Cull [_SRPDefaultUnlitColMode]
ColorMask [_SPRDefaultUnlitColorMask]
Blend SrcAlpha OneMinusSrcAlpha
Stencil
{
Ref[_StencilNo]
Comp[_StencilComp]
Pass[_StencilOpPass]
Fail[_StencilOpFail]
}
```
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "UniversalToonHead.hlsl"
#include "UniversalToonOutline.hlsl"
### ForwardLit
```c#
Tags{"LightMode" = "UniversalForward"}:URP前向渲染
ZWrite[_ZWriteMode]
Cull[_CullMode]
Blend SrcAlpha OneMinusSrcAlpha
Stencil {
Ref[_StencilNo]
Comp[_StencilComp]
Pass[_StencilOpPass]
Fail[_StencilOpFail]
}
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
#include "UniversalToonHead.hlsl"
#include "UniversalToonBody.hlsl"
```
### ShadowCaster
渲染阴影贴图
```c#
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On
ZTest LEqual
Cull[_CullMode]
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
```
### DepthOnly
渲染深度缓存
```c#
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask 0
Cull[_CullMode]
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
```