首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GLSL中TexelFetch和标量Swizzle的几个问题

GLSL中TexelFetch和标量Swizzle的几个问题
EN

Stack Overflow用户
提问于 2016-04-08 23:50:46
回答 1查看 1.2K关注 0票数 0

我以前做过一些关于着色器的工作,但我认为自己对GLSL比较缺乏经验。我正在试图写一个液体解决器,模拟烟雾使用一系列碎片着色器。其中大部分涉及从纹理中提取离散样本,然后对它们进行一些操作,因此它们都具有相似的编译错误。每个像素,只有每个像素,必须得到评估,所以我使用的是texelFetch而不是texture2D作为我的采样。以下是这样一个片段着色器的示例:

代码语言:javascript
复制
uniform sampler2D velocity;
uniform sampler2D pressure;
uniform sampler2D solid;
uniform float numCellsX;
uniform float numCellsY;

void main(void) {
    ivec2 pos = ivec2(gl_FragCoord.xy);
    if (texelFetch(solid, pos.xy, 0).x > 0.0)
        discard;

    float c = texelFetch(pressure, pos.xy, 0).x;
    float up = texelFetchOffset(pressure, pos.xy, 0, ivec2(0, 1)).x;
    float down = texelFetchOffset(pressure, pos.xy, 0, ivec2(0, -1)).x;
    float left = texelFetchOffset(pressure, pos.xy, 0, ivec2(-1, 0)).x;
    float right = texelFetchOffset(pressure, pos.xy, 0, ivec2(1, 0)).x;

    float upS = texelFetchOffset(solid, pos.xy, 0, ivec2(0, 1)).x;
    float downS = texelFetchOffset(solid, pos.xy, 0, ivec2(0, -1)).x;
    float leftS = texelFetchOffset(solid, pos.xy, 0, ivec2(-1, 0)).x;
    float rightS = texelFetchOffset(solid, pos.xy, 0, ivec2(1, 0)).x;

    if (upS > 0.0) up = c;
    if (downS > 0.0) down = c;
    if (leftS > 0.0) left = c;
    if (rightS > 0.0) right = c;

    gl_FragColor = texelFetch(velocity, pos.xy, 0) - vec2(0.5 * numCellsX * (right - left), 0.5 * numCellsY * (up - down));
}

当我通过glSlangValidator运行这个程序时,我会得到以下错误:

代码语言:javascript
复制
ERROR: 0:14: 'texelFetch' : no matching overloaded function found
ERROR: 0:14: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:17: 'texelFetch' : no matching overloaded function found
ERROR: 0:17: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:18: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:18: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:19: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:19: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:20: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:20: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:21: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:21: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:23: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:23: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:24: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:24: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:25: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:25: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:26: 'texelFetchOffset' : no matching overloaded function found
ERROR: 0:26: 'scalar swizzle' : not supported with this profile: es
ERROR: 0:33: 'texelFetch' : no matching overloaded function found
ERROR: 0:33: 'assign' :  cannot convert from 'temp 2-component vector of float'
to 'fragColor mediump 4-component vector of float FragColor'
ERROR: 23 compilation errors.  No code generated.

几乎每一行都有一个错误,我在网上几乎没有发现关于这些东西的信息。根据GLSL参考手册:

代码语言:javascript
复制
gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod);

我不太明白它为什么不接我的texelFetch电话。我也不知道标量swizzle是什么(在网上任何地方都找不到),也不知道为什么会出现这样的问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-09 00:12:34

此配置文件不支持: es

也许您应该用桌面版本的GLSL来编译它,而不是GLSL ES (大概是2.0)。您应该始终在GLSL着色器中使用#version声明。

另外,如果您使用的是texelFetch,为什么仍然要写入gl_FragColor这样的不推荐输出?

然而:

无法从“temp 2-浮动的分量向量”转换

不管这行的版本是什么,都是这样的:

代码语言:javascript
复制
texelFetch(velocity, pos.xy, 0) - vec2(0.5 * numCellsX * (right - left), 0.5 * numCellsY * (up - down))

texelFetch返回一个4元素向量.不能从4元素向量中减去2元素向量.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36511089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档