opengl-es - 为什么必须为片段着色器设置精度?

标签 opengl-es webgl shader precision

我学习WebGL。下一个着色器可以正常工作:

// vertex.shader
// precision mediump float;
attribute vec4 a_Position;
attribute float a_PointSize;

void main(){
  gl_Position = a_Position;
  gl_PointSize = a_PointSize;
}


// fragment.shader
precision mediump float;
uniform vec4 u_FragColor;

void main(){
  gl_FragColor = u_FragColor;
}

为什么需要为片段着色器设置精度?没有此功能,顶点着色器就可以工作,但是没有此代码行,片段着色器就无法工作(如我所见)。为什么存在不同的行为?

我以前读过this,但是对我没有帮助。

最佳答案

OpenGL ES 2.0中的片段着色器中的fp类型不存在默认精度。

在顶点着色器中,如果未显式设置浮点类型的默认精度,则默认为highp。但是,如果片段着色器也默认设置为highp,则将导致问题,因为OpenGL ES 2.0不需要在片段着色器阶段支持高精度浮点类型。

OpenGL ES Shading Language - 4. Variables and Types - pp. 35-36

The fragment language has no default precision qualifier for floating point types. Hence for float, floating point vector and matrix variable declarations, either the declaration must include a precision qualifier or the default float precision must have been previously declared.

4.5.4 Available Precision Qualifiers

The built-in macro GL_FRAGMENT_PRECISION_HIGH is defined to one on systems supporting highp precision in the fragment language

#define GL_FRAGMENT_PRECISION_HIGH 1

and is not defined on systems not supporting highp precision in the fragment language. When defined, this macro is available in both the vertex and fragment languages. The highp qualifier is an optional feature in the fragment language and is not enabled by #extension.

关于opengl-es - 为什么必须为片段着色器设置精度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28540290/

相关文章:

css - CSS 着色器的浏览器?

c# - 将字节数组设置为unity texture2d的快速方法

Android studio NDK 未定义对 GL 函数的引用

android - 渲染索引三角形在 Opengl ES 2.0 的跟踪器中显示模式 GL_MAP_INVALIDATE_RANGE_BIT

iphone - 有没有用于开发 OpenGL ES 2.0 着色器的工具?

javascript 矩阵指数,ala cv::Rodrigues( )?

android - 如何在android Camera上设置Open GLES效果?

javascript - 是否可以使用用户的视频卡在浏览器中计算 sha256 哈希值,例如。通过使用 WebGL 或 Flash?

javascript - 三个 JS 手动编辑几何后无视觉更新

javascript - THREE.js - 如何实现这种效果?