码迷,mamicode.com
首页 > 其他好文 > 详细

WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results

时间:2014-05-19 19:49:50      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

GLES2.0:

Some device will give a warning on compling shaders(yet the compling will succeed), and the rendering result is incorrect with blink & artifacts.

 

the problems is gradient calculation(interpolation) relies on the neighbor pixels,

if the neighbor pixels are not in the same conditional branch,  the gradient will be invalid and result may be undifed.

I guess it is an un-defined behavior, so some devices/drivers works good, some don‘t.

bubuko.com,布布扣
1 //like this
2 if( test )
3     color = texture2D(sampler,UV);
4 else
5    color = vec4(0,0,0,0);
bubuko.com,布布扣

 

One workaround is use mix() or step() instead of condition test. 

bubuko.com,布布扣
1 color = mix(vec4(0,0,0,0), texture2D(...), testVal);
bubuko.com,布布扣

When using condition branch, the texture sampling may be not actually executed, which will increase graphics performance.

One draw back on using mix/step is that the sampling is always performed, then interpolated/multiplied.

WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results,布布扣,bubuko.com

WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/crazii/p/3734545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!