Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GLSL操作数顺序问题_Glsl - Fatal编程技术网

GLSL操作数顺序问题

GLSL操作数顺序问题,glsl,Glsl,我正在尝试将GIMP divide混合过滤器代码移植到GLSL。我已经能够为各种其他混合模式做到这一点,但出于某种原因,这根本不起作用 以下是C gimp代码(基于SVG): 以下是移植的代码: mediump float r; if (overlay.a == 0.0 || base.r / overlay.r > base.a / overlay.a) r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1

我正在尝试将GIMP divide混合过滤器代码移植到GLSL。我已经能够为各种其他混合模式做到这一点,但出于某种原因,这根本不起作用

以下是C gimp代码(基于SVG):

以下是移植的代码:

mediump float r;
if (overlay.a == 0.0 || base.r / overlay.r > base.a / overlay.a)
  r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
else
  r = base.r * overlay.a * overlay.a / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
我对每个通道都这样做,然后使用vec4合并结果

我的GLSL代码提供了与GIMP C代码完全不同的结果。除非我已经看了2个小时的代码,并且错过了一个错误,否则我认为这一定是操作数顺序错误。或者一些与C不相似的GLSL

有什么想法吗

更新:

它看起来是什么样子:
它应该是什么样子的:

问题出在我的代码中。我将初始值提取为lowp。

问题出在我的代码中。我将初始值提取为lowp。

如果使用
highp float
,你会得到不同的答案吗?图片值千言万语,你能发布预期结果和得到的结果吗?如果使用
highp float
,你会得到不同的答案吗?图片值千言万语,你能把预期的结果和你得到的吗?
mediump float r;
if (overlay.a == 0.0 || base.r / overlay.r > base.a / overlay.a)
  r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
else
  r = base.r * overlay.a * overlay.a / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);