mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
消除Anime4K里因压缩的噪声
This commit is contained in:
parent
0a04ffc89d
commit
85ca9f8b5b
2 changed files with 12 additions and 6 deletions
|
|
@ -1,11 +1,11 @@
|
|||
#include "common.hlsli"
|
||||
|
||||
// 纹理会自动将值切割到 0~1,为了使值在着色器之间传递需要进行压缩
|
||||
// 假设所有值在 -2~2 之间,深度学习的中间值一般很小,所以几乎没有损失
|
||||
// 使用 tan 函数压缩会因为精度损失产生噪声
|
||||
#define Compress(value) ((value + 2) / 4) // (atan(value) / PI + 0.5);
|
||||
// 假设所有值在 -1.5~1.5 之间,深度学习的中间值一般很小,所以几乎没有截断损失
|
||||
// 但精度损失不可避免,最终会产生噪声
|
||||
#define Compress(value) ((value + 1.5) / 3) // (atan(value) / PI + 0.5);
|
||||
|
||||
#define Uncompress(value) (value * 4 - 2) // tan((value - 0.5) * PI)
|
||||
#define Uncompress(value) (value * 3 - 1.5) // tan((value - 0.5) * PI)
|
||||
|
||||
// Anime4K 中使用的是亮度分量
|
||||
#define GetLuma(rgb) (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ D2D_PS_ENTRY(main) {
|
|||
int2 i = int2(f * 2);
|
||||
float l = Uncompress(D2DSampleInput(1, coord1.xy + (float2(0.5, 0.5) - f) * coord1.zw))[i.y * 2 + i.x];
|
||||
|
||||
float3 yuv = RGB2YUV(D2DSampleInput(0, coord0.xy).xyz);
|
||||
return float4(YUV2RGB(yuv.x+l, yuv.y, yuv.z), 1);
|
||||
// 消除因压缩产生的噪声
|
||||
if (abs(l) > 0.01) {
|
||||
float3 yuv = RGB2YUV(D2DSampleInput(0, coord0.xy).xyz);
|
||||
return float4(YUV2RGB(yuv.x + l, yuv.y, yuv.z), 1);
|
||||
} else {
|
||||
return D2DSampleInput(0, coord0.xy);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue