Gbuffer的法向量的压缩

BTW: 自己看到了记录一下,大家随意。

原文链接:https://aras-p.info/texts/CompactNormalStorage.html

1.直接存在RGB通道上。

half4 encode(half3 n){return half4(n.xyz*0.5+0.5,0);}
half3 decode(half4 c){return c.rgb*2-1;}


2.存储法线的XY在颜色通道上,计算Z

half4 encode(half3 n){return half4(n.xy*0.5+0.5,0.0);}
half3 decode(half2 c)
{
    half3 n;
    n.xy = c*2-1;
    n.z = sqrt(1-dot(n.xy,n.xy));
    return n;
}

优点:容易实现

缺点:误差较大。


3.球面坐标(Spherical Coordinates)

#define kPI 3.1415926536f
half4 encode (half3 n)
{
    return half4((half2(atan2(n.y,n.x)/kPI, n.z)+1.0)*0.5,0,0);
}
half3 decode (half2 enc)
{
    half2 ang = enc*2-1;
    half2 scth;
    sincos(ang.x * kPI, scth.x, scth.y);
    half2 scphi = half2(sqrt(1.0 - ang.y*ang.y), ang.y);
    return half3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
}

优点:适合大部分法线,不一定需要view space

缺点:使用了三角函数,计算量比较大。


4.Spheremap Transform 

half2 encode (half3 n)
{
    half2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5));
    enc = enc*0.5+0.5;
    return enc;
}
half3 decode (half4 enc)
{
    half4 nn = enc*half4(2,2,0,0) + half4(-1,-1,1,-1);
    half l = dot(nn.xyz,-nn.xyw);
    nn.z = l;
    nn.xy *= sqrt(l);
    return nn.xyz * 2 + half3(0,0,-1);
}

优点:效果还不错,计算量小。CryEngine 3使用的方案。 presented by Martin Mittring in "A bit more Deferred" presentation


5.Lambert Azimuthal Equal-Area projection

half2 encode (half3 n)
{
    half f = sqrt(8*n.z+8);
    return n.xy / f + 0.5;
}
half3 decode (half4 enc)
{
    half2 fenc = enc*4-2;
    half f = dot(fenc,fenc);
    half g = sqrt(1-f/4);
    half3 n;
    n.xy = fenc*g;
    n.z = 1-f/2;
    return n;
}

优点:效果还不错,计算量小。 by Sean Barrett


6.Stereographic Projection 

half4 encode (half3 n)
{
    half scale = 1.7777;
    half2 enc = n.xy / (n.z+1);
    enc /= scale;
    enc = enc*0.5+0.5;
    return half4(enc,0,0);
}

half3 decode (half4 enc)
{
    half scale = 1.7777;
    half3 nn =
        enc.xyz*half3(2*scale,2*scale,0) +
        half3(-scale,-scale,1);
    half g = 2.0 / dot(nn.xyz,nn.xyz);
    half3 n;
    n.xy = g*nn.xy;
    n.z = g-1;
    return n;
}

优点:效果还不错,计算量小。


8. Per-pixel View Space

float3x3 make_view_mat (float3 view)
{
    view = normalize(view);
    float3 x,y,z;
    z = -view;
    x = normalize (float3(z.z, 0, -z.x));
    y = cross (z,x);
    return float3x3 (x,y,z);
}

half4 encode (half3 n, float3 view)
{
    return half4(mul (make_view_mat(view), n).xy*0.5+0.5,0,0);
}

half3 decode (half4 enc, float3 view)
{
    half3 n;
    n.xy = enc*2-1;
    n.z = sqrt(1+dot(n.xy,-n.xy));
    n = mul(n, make_view_mat(view));
    return n;
}

优点:效果还不错,计算量小。

性能对比:

GPU performance comparison in a single table:

#1: X & Y#3: Spherical#4: Spheremap#7: Stereo#8: PPView
Encoding, GPU cycles
Radeon HD24001.0017.003.004.0011.00
Radeon HD58700.500.950.500.500.80
GeForce 62001.0012.004.002.0012.00
GeForce 88007.0043.0012.0012.0024.00
Decoding, GPU cycles
Radeon HD24001.0017.003.004.0011.00
Radeon HD58700.500.950.501.000.80
GeForce 62004.007.006.004.0012.00
GeForce 880015.0023.0015.0012.0029.00
Encoding, D3D ALU+TEX instruction slots
SM3.01264517
Decoding, D3D ALU+TEX instruction slots
SM3.08189822

质量对比

Quality comparison in a single table. PSNR based, higher numbers are better.

MethodPSNR, dB
#1: X & Y18.629
#3: Spherical42.042
#4: Spheremap48.071
#7: Stereographic44.147
#8: Per pixel view38.730

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
《Gpu Pro6》Real-Time Lighting via Light Linked List:常规Deferred Lighting需要深度,因而半透一般是通过后续的Forward Lighting实现,文中通过自定义Software Depth Test,影响当前屏幕像素点的Light Link List实现对半透对象的Deferred Lighting效果。 《Gpu Pro7》Clustered Shading: Assigning Lights Using Conservative Rasterization in DirectX 12:使用Compute Shader以及DX12保守光栅化,实现优化的分簇渲染,三维空间划分光,存储到Light-Linklist中,降低光与物体映射的消耗。 《Gpu Pro7》Fine Pruned Tiled Light Lists:一种优化的Tiled Shading,与传统的不同,通过两个pass,首先计算light在全屏的AABB进行粗略判断,然后逐Tiled精确判断,可以实现不规则光源的Tiled Shading,而且利用Compute Shader生成,再利用AMD的GCN架构上,将这个计算和ShadowMap并行,降低计算时间。用于《古墓丽影·崛起》。 《Gpu Pro7》Deferred Attribute Interpolation Shading:传统GBuffer内存太高,以至于MSAA基本不敢开,文中给出了一种方,不保存GBuffer信息,而是保存三角形信息,再通过插值进行计算,降低Deferred的内存消耗。还可以把GI等低频光照单独计算降低着色消耗。 《Gpu Pro7》[Mobile] Physically Based Deferred Shading on Mobile:移动平台实现延迟物理渲染,利用Frame Buffer Fetch整合G-Buffer,Lighting,Tonemapping,降低带宽消耗。 《Gpu Pro7》Deferred Coarse Pixel Shading:延迟渲染最后全屏着色pixel瓶颈较高,文中给出了一种生成Gbuffer时额外生成ddx,ddy然后通过Compute Shader对NxN大小块计算找到变化不明显区域,使用低频着色,即几个像素计算一次,该方式同样适用于后处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值