【问题标题】:texture atlas tiling纹理图集平铺
【发布时间】:2019-08-30 05:25:13
【问题描述】:

我正在 ios opengl es 2.0 (ipad) 上尝试简单的纹理飞溅。我在 pvrt 压缩图集(2x2 瓷砖)中有 4 个平铺纹理。 4 个纹理单元上的 4 个单一纹理非常慢。

顶点着色器:

attribute lowp vec4 position;
attribute lowp vec2 tex0;
varying lowp vec2 surfCoord;
uniform mat4 projection_modelview;
uniform lowp float uv_coef;

varying lowp vec2 texCoord1;
varying lowp vec2 texCoord2;
varying lowp vec2 texCoord3;
varying lowp vec2 texCoord4;

void main()
{
  gl_Position = projection_modelview * position;
  vec2 texCoord = fract(vec2(position.x / uv_coef, position.y / uv_coef));
  texCoord1 = texCoord * 0.5;
  texCoord2 = texCoord1 + vec2(0.5, 0);
  texCoord3 = texCoord1 + vec2(0, 0.5);
  texCoord4 = texCoord1 + vec2(0.5, 0.5);
  surfCoord = tex0;
}

片段着色器:

uniform sampler2D texture0;    // surface alpha map
uniform sampler2D texture1;    // atlas
varying lowp vec2 surfCoord;
varying lowp vec2 texCoord1;
varying lowp vec2 texCoord2;
varying lowp vec2 texCoord3;
varying lowp vec2 texCoord4;

void main()
{
  lowp vec4 surfTexel = texture2D(texture0, surfCoord);
  lowp vec4 texel1 = texture2D(texture1, texCoord1);
  lowp vec4 texel2 = texture2D(texture1, texCoord2);
  lowp vec4 texel3 = texture2D(texture1, texCoord3);
  lowp vec4 texel4 = texture2D(texture1, texCoord4);

  texel1 *= surfTexel.r;
  texel2 = mix(texel1, texel2, surfTexel.g);
  texel3 = mix(texel2, texel3, surfTexel.b);
  gl_FragColor = mix(texel3, texel4, surfTexel.a);
}

显示这个:


(来源:inputwish.com

我的问题可能是纹理单元插值器,但我不知道如何解决。我没有在我的着色器中看到错误。请问有什么建议吗?

【问题讨论】:

    标签: opengl-es glsl texture-mapping tiling glsles


    【解决方案1】:

    错误是在顶点着色器中使用分数。太早了。它应该在片段着色器中:

    lowp vec4 texel1 = texture2D(texture1, fract(texCoord) * 0.5);
    lowp vec4 texel2 = texture2D(texture1, fract(texCoord) * 0.5 + vec2(0.5, 0.0));
    lowp vec4 texel3 = texture2D(texture1, fract(texCoord) * 0.5 + vec2(0.0, 0.5));
    lowp vec4 texel4 = texture2D(texture1, fract(texCoord) * 0.5 + vec2(0.5, 0.5));
    ... and mix them together..
    

    无论如何它很慢,因为依赖纹理在 ipad ios 上读取。

    【讨论】:

      猜你喜欢
      • 2020-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多