2023-12-08 18:00:41 +08:00
|
|
|
|
---
|
|
|
|
|
title: Material&BasePass
|
|
|
|
|
date: 2023-12-08 17:34:58
|
|
|
|
|
excerpt:
|
|
|
|
|
tags:
|
|
|
|
|
rating: ⭐
|
|
|
|
|
---
|
|
|
|
|
# GBuffer
|
|
|
|
|
```c#
|
|
|
|
|
OutGBufferA = WorldNormal/PerObjectGBufferData
|
|
|
|
|
OutGBufferB = Metallic/Specular/Roughness/EncodeShadingModelIdAndSelectiveOutputMask(GBuffer.ShadingModelID, GBuffer.SelectiveOutputMask);
|
|
|
|
|
OutGBufferC = BaseColor/GBufferAO
|
|
|
|
|
OutGBufferD = GBuffer.CustomData;
|
|
|
|
|
OutGBufferE = GBuffer.PrecomputedShadowFactors;
|
|
|
|
|
```
|
|
|
|
|
```c#
|
|
|
|
|
GBufferB:Metallic/Specular/Roughness=>ToonHairMask OffsetShadowMask/SpcularMask/SpecularValue
|
|
|
|
|
OutGBufferD = CustomData.xyzw=》ShaderColor.rgb/NoL
|
|
|
|
|
OutGBufferE = GBuffer.PrecomputedShadowFactors.xyzw=》 /RimLightMask/DiffuseOffset/RimLightWidth
|
|
|
|
|
OutGBufferF = velocity => OutlineWidth/OutlineID/OutlinePaint/OutlineZShift
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
| GBuffer | 表头 |
|
|
|
|
|
| -------- | ------------------------------------------------------------------------------------- |
|
|
|
|
|
| GBufferB | OffsetShadowMask SpcularMask SpecularValue EncodeShadingModelIdAndSelectiveOutputMask |
|
|
|
|
|
| GBufferD | ShaderColor.rgb NoL |
|
|
|
|
|
| GBufferE | |
|
|
|
|
|
| GBufferF | ID |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## BaseColor与ShadowColor
|
|
|
|
|
- 原神里ShadowColor还会接收其他物体的阴影投射,没有自投影;蓝色协议可能也没有自投影。
|
|
|
|
|
|
|
|
|
|
BaseColor与ShadowColor的过渡需要Step、Feather、Offset等参数,可以直接制作一个HalfLambert的渐变贴图之后使用View传递。因为有多个贴图所以还需要ID贴图指定。但这样需要考虑一个问题:
|
|
|
|
|
|
|
|
|
|
- 一个物体上的同一个ID区域的BaseColor与ShadowColor是否都是一样的
|
|
|
|
|
- 如果不一样就需要再传递一个ShadowColor.rgb到GBuffer里。
|
|
|
|
|
- 不管如何手绘的补充暗部也是需要加到GBuffer中的
|
|
|
|
|
|
|
|
|
|
这决定传递到View里面的渐变贴图是彩色还是暗色
|
|
|
|
|
|
|
|
|
|
### 预计算贴图方案(构想)
|
|
|
|
|
Toon渲染一般会使用HalfLambda。之后使用Feather、Step等参数对过渡边界进行调整
|
|
|
|
|
使用 渐变贴图查表来实现 渐变、二阶化。以此代替羽化、step等参数。
|
|
|
|
|
使用ID贴图指定,或者通过BaseColor值来查询?
|
|
|
|
|
|
|
|
|
|
## 高光
|
|
|
|
|
- PBR高光(使用Roughness控制是否可行?是否需要传入GBuffer一个Mask贴图)
|
|
|
|
|
- 自定义高光:高光贴图、高光颜色、参数化高光形状、多层高光
|
|
|
|
|
|
|
|
|
|
## 描边
|
|
|
|
|
- 原神的描边好像是后处理
|
|
|
|
|
- 蓝色协议
|
|
|
|
|
![[08-Assets/Images/ImageBag/UrealEngineNPR/原神_描边.png]]
|
|
|
|
|
![[08-Assets/Images/ImageBag/UrealEngineNPR/原神截图_描边.png]]
|
|
|
|
|
|
|
|
|
|
TODO:考虑使用顶点色来控制宽度,使用顶点色G
|
|
|
|
|
|
|
|
|
|
## 顶点色
|
|
|
|
|
用于存储一些低精度数据,插值即可
|
|
|
|
|
- R:
|
|
|
|
|
- G:描边宽度
|
|
|
|
|
- B:
|
|
|
|
|
|
|
|
|
|
蓝色协议的R:阴影区域标记 与 B:Ao,而罪恶装备使用贴图来传递信息。
|
|
|
|
|
|
|
|
|
|
## lightmap
|
|
|
|
|
### 罪恶装备
|
|
|
|
|
,G为阴影控(AO),R为高光强度参数,金属和光滑材质的部分设置的更大一些。B通道:用于照明控制。最大值为高光,反之,值越小高光越淡。
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
https://zhuanlan.zhihu.com/p/360229590一文中介绍了崩坏3与原神的计算方式
|
|
|
|
|
|
|
|
|
|
崩坏3的LightMap计算方式:
|
|
|
|
|
```c++
|
|
|
|
|
half4 baseColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv.xy);
|
|
|
|
|
half4 LightMapColor = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv.xy);
|
|
|
|
|
half3 ShadowColor = baseColor.rgb * _ShadowMultColor.rgb;
|
|
|
|
|
half3 DarkShadowColor = baseColor.rgb * _DarkShadowMultColor.rgb;
|
|
|
|
|
|
|
|
|
|
//如果SFactor = 0,ShallowShadowColor为一级阴影色,否则为BaseColor。
|
|
|
|
|
float SWeight = (LightMapColor.g * input.color.r + input.lambert) * 0.5 + 1.125;
|
|
|
|
|
float SFactor = floor(SWeight - _ShadowArea);
|
|
|
|
|
half3 ShallowShadowColor = SFactor * baseColor.rgb + (1 - SFactor) * ShadowColor.rgb;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
二级阴影计算:
|
|
|
|
|
```c++
|
|
|
|
|
//如果SFactor = 0,DarkShadowColor为二级阴影色,否则为一级阴影色。
|
|
|
|
|
SFactor = floor(SWeight - _DarkShadowArea);
|
|
|
|
|
DarkShadowColor = SFactor * (_FixDarkShadow * ShadowColor + (1 - _FixDarkShadow) * ShallowShadowColor) + (1 - SFactor) * DarkShadowColor;
|
|
|
|
|
|
|
|
|
|
// 平滑阴影边缘
|
|
|
|
|
half rampS = smoothstep(0, _ShadowSmooth, input.lambert - _ShadowArea);
|
|
|
|
|
half rampDS = smoothstep(0, _DarkShadowSmooth, input.lambert - _DarkShadowArea);
|
|
|
|
|
ShallowShadowColor.rgb = lerp(ShadowColor, baseColor.rgb, rampS);
|
|
|
|
|
DarkShadowColor.rgb = lerp(DarkShadowColor.rgb, ShadowColor, rampDS);
|
|
|
|
|
|
|
|
|
|
//如果SFactor = 0,FinalColor为二级阴影,否则为一级阴影。
|
|
|
|
|
SFactor = floor(LightMapColor.g * input.color.r + 0.9f);
|
|
|
|
|
half4 FinalColor;
|
|
|
|
|
FinalColor.rgb = SFactor * ShallowShadowColor + (1 - SFactor) * DarkShadowColor;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**罪恶装备**:
|
|
|
|
|
对阴影判断阈值的偏移。(见前面着色部分,顶点AO+手绘修正)
|
|
|
|
|
G : 轮廓线根据与相机的距离扩大多少的系数
|
|
|
|
|
B : 等高线 Z 轴偏移值
|
|
|
|
|
A : 轮廓厚度系数。0.5为标准,1为最大厚度,0为无等高线
|
|
|
|
|
|
2023-12-16 23:09:19 +08:00
|
|
|
|
### 蓝色协议
|
|
|
|
|
[[蓝色协议的方案]]
|
|
|
|
|
|
2023-12-08 18:00:41 +08:00
|
|
|
|
### 米哈游
|