关于Fragment output 数据格式

本文解释了在GLSL片段着色器中如何正确指定输出纹理格式。关键在于理解着色器仅负责生成输出值,而帧缓冲区图像自身决定了所写入值的格式。文章详细介绍了不同GLSL类型(如vec4、ivec4和uvec4)与各种纹理格式之间的对应关系。

Fragment output

Q:

The shader outputs to an 8 bit unsigned integer texture and a half-float RGBA (ie 16 bit) texture.

how do I describe these in the glsl layout command in the fragment shader?

A:

You don’t.

It’s not the shader’s responsibility to say what kind of texture it writes to. All it writes are output values. What decides the format of the values written to the framebuffer images are the framebuffer images themselves.

The only thing you have to decide is what GLSL type you’re writing to. Floating point outputs can be written to either a normalized integer image format or to floating-point formats. Signed integral outputs can be written to signed integral image formats. And unsigned integral outputs can be written to unsigned integral outputs.

If you write a vec4, it could go to an RGB16F texture, an RGBA8 texture, an RGBA16 texture, an RG8_SNORM, or whatever. If you write to an ivec4, then it can go to an RGB8I, RGB16I, an RG8I, an RGBA16I, and so froth, as long as it ends in I. Similarly, if you write to a uvec4, then it can go to an RGB8UI, RG16UI, RGBA8UI, etc.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值