GLSL Half(浮点)属性类型 [英] GLSL Half (floating point) attribute type

查看:553
本文介绍了GLSL Half(浮点)属性类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将16位浮点数(半浮点数)作为属性添加到我的GLSL顶点着色器中.它不会让我编译说:

I have been trying to get a 16bit float (half-floating point) as an attribute into my GLSL vertex shader. It won't let me compile saying:

error C7506: OpenGL does not define the global type half

但是我的#version410,因此它应该支持一半?我缺少明显的东西吗?

but my #version is 410 and so it should support half? Am I missing something obvious?

推荐答案

OpenGL和OpenGL ES定义了两种并发的精度类型.

OpenGL and OpenGL ES define two concurrent types of precision.

  • 缓冲区中的存储精度
  • 着色器中使用的最低计算精度.

存储精度由您的顶点属性上传定义,例如GL_FLOATGL_HALF_FLOAT.这将是用于将数据存储在内存中的精度.

Storage precision is defined by your vertex attribute upload, such as GL_FLOAT or GL_HALF_FLOAT. This will be the precision used to store the data in memory.

使用精度在着色器中定义为highp(至少32位),mediump(至少16位)和lowp(至少9位).这是最低精度;着色器将变量指定为mediump以及着色器编译器生成fp32数据类型是完全合法的.台式机GPU往往仅支持fp32计算,因此使用highpmediumplowp都映射到fp32数据类型(仅包含精度限定符以保持与OpenGL ES着色器的兼容性,因此可以合法地忽略.由编译器).实现OpenGL ES的移动GPU倾向于将highp映射到fp32,将mediumplowp映射到fp16. 有关详细信息,请参见 GLSL ES 3.0规范,第4.5.1节

Usage precision is defined in the shader as highp (at least 32-bit), mediump (at least 16-bit), and lowp (at least 9-bit). These are minimum precisions; it is perfectly legal for a shader to specify a variable as mediump and for the shader compiler to generate fp32 data types. Desktop GPUs tend to only support fp32 computation, so the use of highp, mediump and lowp all map to fp32 data types (the precision qualifiers are only included to keep compatibility with OpenGL ES shaders, and can legally be ignored by the compiler). Mobile GPUs implementing OpenGL ES tend to map highp to fp32, and mediump and lowp to fp16. Detailed information can be found in the GLSL ES 3.0 Specification, Section 4.5.1

将内存中的顶点属性绑定到输入着色器变量时,不需要匹配存储精度和使用精度;该API将包括透明属性精度转换.用户上传例如GL_FLOAT然后将其用作着色器中的mediump fp16变量,尽管这样做会浪费内存带宽.

When binding a vertex attribute in memory to an input shader variable the storage and usage precisions are not required to match; the API will include transparent attribute precision conversion. It is perfectly legal for a user to upload e.g. a GL_FLOAT and then use it in a shader as a mediump fp16 variable, although it would be a waste of memory bandwidth to do so.

这篇关于GLSL Half(浮点)属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆