BlueRoseNote/03-UnrealEngine/Rendering/Material/使用Curve进行深度适配的Outline.md

55 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 使用Curve进行深度适配的Outline
date: 2023-07-18 14:47:24
excerpt:
tags:
rating: ⭐
---
# 前言
在UE5.1发现了若干新节点感觉对后处理描边有很大的作用。
![[MultiDraw_OutlineMaterial.png]]
## ControlCurve
<iframe src="https://www.desmos.com/calculator/z9o3k0luyb?embed" width="500" height="500" style="border: 1px solid #ccc" frameborder=0></iframe>
UE单位为cm理论上描边宽度控制范围为10cm~10000cm1000m。假设标准的角色身高为180cm110~200cm变化比较轻微并以此定义一个标准数StandardCharacterHeight经过观察`10~ ControlWidthRangeMax`范围适合使用CurveTexture。而超过ControlWidthRangeMax = StandardCharacterHeight * 2的区域基本是一个线性区间所以可以使用一个线性函数来控制。
以下为原始数据:
| | | | | | | | |
| --- | --- | --- | ---- | --- | ---- | --- | ---- |
| x轴 | 15 | 20 | 25 | 30 | 40 | 60 | 100 |
| y轴 | -12 | -9 | -7.2 | -6 | -4.5 | -3 | -1.8 |
经过重映射后:
| | | | | | | | |
| --- | ----- | ---- | ---- | ------ | ----- | ------- | ---- |
| x轴 | 0.15 | 0.2 | 0.25 | 0.3 | 0.4 | 0.6 | 1 |
| y轴 | 0.667 | 0.75 | 0.8 | 0.8333 | 0.875 | 0.91666 | 0.95 |
考虑需要让描边变得平滑以及让效果更好的考虑,所以以此为基础数据进行了调节(平移曲线并且调整了几个点),以下去本人设置的曲线:![[MultiDraw_OutlineCurve.png|800]]
### 线性函数斜率k的计算
取得ControlWidthRangeMax上一点(360 0.5)与最大范围x=10000的一点(10000 0.018),即可取得斜率 k = 0.0005/1cm。
实际使用0.0005的效果不佳经过调整最终斜率使用0.002。
### Remap
```c++
half invLerp(half from, half to, half value)
{
return (value - from) / (to - from);
}
half invLerpClamp(half from, half to, half value)
{
return saturate(invLerp(from,to,value));
}
// full control remap, but slower
half remap(half origFrom, half origTo, half targetFrom, half targetTo, half value)
{
half rel = invLerp(origFrom, origTo, value);
return lerp(targetFrom, targetTo, rel);
}
```