为什么需要为片段着色器设置精度? [英] Why it is necessary to set precision for the fragment shader?

查看:30
本文介绍了为什么需要为片段着色器设置精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习 WebGL.下一个着色器工作正常:

I learn WebGL. Next shaders work fine:

// 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;
}

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

Why it is necessary to set precission for the fragment shader? Vertex shader works without this, but fragment shader doesn't work without this code row (as I see). Why the different behaviour exist?

我之前读过 this,但这对我没有帮助.

I read this before, but it didn't help me.

推荐答案

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

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

No default precision exists for fp types in fragment shaders in OpenGL ES 2.0.

In vertex shaders, if you do not explicitly set the default precision for floating-point types, it defaults to highp. However, if the fragment shader were to default to highp as well, that would cause issues since OpenGL ES 2.0 does not require support for high precision floating-point types in the fragment shader stage.

片段语言没有浮点类型的默认精度限定符.因此对于浮动,浮动点向量和矩阵变量声明,声明必须包含精度限定符或必须事先声明默认的浮点精度.

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.

内置宏GL_FRAGMENT_PRECISION_HIGH在支持highp片段语言精度的系统上定义为一个

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

并且未在片段语言中不支持 highp 精度的系统上定义.定义后,此宏可用于顶点语言和片段语言.highp 限定符是片段语言中的可选功能,#extension 未启用.

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.

这篇关于为什么需要为片段着色器设置精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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