ios - GLSL ES precision errors and overflows -


i have following fragment shader:

precision highp float;  varying highp vec2 vtexcoord;  uniform sampler2d ucolortexture;  void main () {    highp vec4 tmp;    tmp = ((texture2d (ucolortexture, vtexcoord) + texture2d (ucolortexture, vtexcoord)) / 2.0);        gl_fragcolor = tmp;  } 

i know shader not make sense should still run correct , try reproduce problem it. when analyze shader xcode opengl-es analyzer shows error:

overflow in implicit conversion, minimum range lowp float (-2,2)

and not shows error, rendering output broken overflows. it's not false positive analyzer overflows.

can explain me why dis produces overflow although chose highp everywhere?

you didn't really choose highp everywhere; glsl es spec chapter 8 (built-in functions):

precision qualifiers parameters , return values not shown. texture functions, precision of return type matches precision of sampler type.

and 4.5.3 (default precision qualifiers):

the fragment language has following predeclared globally scoped default precision statements: ... precision lowp sampler2d; ...

which means in code texture2d (ucolortexture, vtexcoord) return lowp, adding 2 of them, potentially resulting in value of 2.0.

from 4.5.2 (precision qualifiers):

the required minimum ranges , precisions precision qualifiers are: ... lowp (−2,2) ...

the parentheses in (-2,2) indicate open range, meaning includes values (but not including) 2.

so think fact you're adding 2 lowp's means you're overflowing. try changing line to:

tmp = texture2d(ucolortexture, vtexcoord)/2.0 + texture2d(ucolortexture, vtexcoord)/2.0; 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -