【问题标题】:Buggy texture coordinate mappingBuggy 纹理坐标映射
【发布时间】:2018-08-16 16:17:08
【问题描述】:

我找不到与我的偏移量进行协调的问题,反之亦然映射,但是一旦尺寸稍微变大,就会出现一个反复出现的问题。这在 Chrome 上运行。

我正在尝试 55x56 纹理,我使用以下例程将逻辑整数偏移映射到 TexCoords 的 uv (st) 并返回。某个地方累积了一些错误,导致两个后续偏移量(例如 54 和 55)映射到同一个纹素。

在 StackOverflow 的一篇文章中找到了下面添加 halfTexel 的行(这很有意义)。在我的着色器的开头我也有这行:

// const vec2 halfTexel = vec2(${1.0 / (2.0 * xScale)}, ${1.0 / (2.0 * yScale)});
// xscale is the width (55)
// yscale is the height (56)

precision highp float;
...
vec2 offsetToCoords_A(int offset) {
  const vec2 halfTexel = vec2(0.00909090909090909, 0.008928571428571428);
  const float xScale = 55.0;
  const float yScale = 56.0;
  float offsetF = float(offset);
  float s = mod(offsetF, 55.0);
  float t = floor(offsetF / 55.0);
  vec2 coords = vec2(s/xScale, t/yScale) + halfTexel;
  return coords;
}

int coordsToOffset_A(vec2 coords) {
  const float xScale = 55.0;
  const float yScale = 56.0;
  float s = coords.s * xScale;
  float t = coords.t * yScale;
  int offset = int(t) * 55 + int(s);
  return offset;
}

样本结果:

49,50,51,52,53,54,54,56,57,58,59,
...
106,107,108,109,109,111,112,113

【问题讨论】:

  • 样本结果究竟是如何得到的?它看起来像coordsToOffset_A 的输出,但它的输入是什么?函数offsetToCoords_A 是否以任何方式使用?
  • 如果我取一个偏移量 55 并将其传递给 offsetToCoords_A 我会得到可以用来传递给 texture2D(A,coords). What I'm also showing is the other function which is I use to map from the varying (TexCoords) to an offset. I think that function coordsToOffset 的坐标``` 是可以的。在这两个调用之间当然有一些处理。但是,我已将问题范围缩小到这两个。
  • 我刚刚打印了.s 调用offsetToCoords_A 的结果。在第 55 次调用中,生成的 vec2 将 1.0090909004211426 作为其 x 坐标。这表明mod 函数存在问题

标签: glsl glsles


【解决方案1】:

移除模组并将offsetToCoords更改为以下内容:

vec2 offsetToCoords_A(int offset) {
  const vec2 halfTexel = vec2(0.00909090909090909, 0.008928571428571428);
  const float xScale = 55.0;
  const float yScale = 56.0;
  int t = offset / int(xScale);
  int s = offset - t*int(xScale);
  vec2 coords = vec2(s,t)/vec2(xScale, yScale) + halfTexel;
  return coords;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    相关资源
    最近更新 更多