webgl uniform 片元和顶点传值差异

2020-03-07  本文已影响0人  aibinMr

1:片元着色器和顶点着色器可以同时接收到相同名字的变量值,就是下面代码可以同时包含在片元和顶点着色器中

uniform int u_aaaa;

,但是这里有个坑,可能会导致编译错误,这个坑就是精度,由于顶点着色器和片元着色器的精度不同,所以当只是声明了变量名但是没有处理精度的时候就有可能报错,所以需要添加统一的精度解决这个问题。

precision highp int;

注:这个是群里人给的一些说明

When the vertex and fragment shaders are linked together, then they will share a single 
global uniform name space. Hence, types and precisions of uniforms with the same name
 must match across all shaders that are linked into a single executable.
The vertex language has the following predeclared globally scoped default precision
 statements:
          precision highp float;
          precision highp int;
          precision lowp sampler2D;
          precision lowp samplerCube;
The fragment language has the following predeclared globally scoped default precision 
statements:
          precision mediump int;
          precision lowp sampler2D;
          precision lowp samplerCube;

再附一张大神给的文档名


QQ图片20200307221029.png
上一篇下一篇

猜你喜欢

热点阅读