顶点着色器中的纹理查找在

顶点着色器中的纹理查找在

本文介绍了顶点着色器中的纹理查找在 iPad 设备与 iPad 模拟器上的行为不同 - OpenGL ES 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个顶点着色器,我在其中进行纹理查找以确定 gl_Position.我将其用作 GPU 粒子模拟系统的一部分,其中粒子位置存储在纹理中.

I have a vertex shader in which I do a texture lookup to determine gl_Position. I am using this as part of a GPU particle simulation system, where particle positions are stored in a texture.

似乎: vec4 textureValue = texture2D(dataTexture, vec2(1.0, 1.0)); 在模拟器上的行为与在 iPad 设备上的行为不同.在模拟器上,纹理查找成功(该位置的值是 0.5、0.5)并且我的粒子出现在那里.但是,在 iPad 本身上,纹理查找不断返回 0.0、0.0.

It seems that: vec4 textureValue = texture2D(dataTexture, vec2(1.0, 1.0)); behaves differently on the simulator than the iPad device. On the simulator, the texture lookup succeeds (the value at that location is 0.5, 0.5) and my particle appears there. However, on the iPad itself the texture lookup is constantly returning 0.0, 0.0.

我已经尝试过 GL_FLOAT 和 GL_UNSIGNED_BYTE 格式的两种纹理.

I have tried both textures of the format GL_FLOAT and GL_UNSIGNED_BYTE.

有其他人经历过吗?GLSL ES 规范说纹理查找可以在顶点和片段着色器中完成,所以我看不出问题出在哪里.

Has anyone else experienced this? The GLSL ES spec says that texture lookups can be done in both the vertex and fragment shaders, so I don't see what the problem is.

我正在使用 iOS SDK 4.2 的最新 GM Beta

I am using the latest GM Beta of iOS SDK 4.2

推荐答案

我也刚刚测试了这个.使用 iOS 4.3,您可以在设备和模拟器上的顶点着色器上进行纹理查找.虽然有一点奇怪(这可能就是为什么它不像 szu 提到的那样官方").在实际设备上(我在 iPad 2 上测试过),您必须在片段着色器和顶点着色器上进行查找.也就是说,如果您实际上并没有在片段着色器上使用它,您仍然必须以某种方式引用它.这是一个简单的例子,我传入一个纹理并使用红色像素将顶点的 y 值重新定位一点:

I just tested this as well. Using iOS 4.3, you can do a texture lookup on the vertex shader on both the device and the simulator. There is a bit of strangeness though (which is maybe why it's not "official" as szu mentioned). On the actual device (I tested on the iPad 2) you have to do a lookup on the fragment shader as well as on the vertex shader. That is, if you are not actually using it on the fragment shader, you'll still have to reference it in some way. Here's a trivial example where I'm passing in a texture and using the red pixel to reposition the y value of the vertex by a little bit:

/////fragment shader
uniform sampler2D tex; //necessary even though not actually used

void main() {
  vec4 notUsed = texture2D(tex, vec2(0.0,0.0)); //necessary even though not actually used
  gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}

/////vertex shader
attribute vec4 position;
attribute vec2 texCoord;
uniform sampler2D tex;

void main() {
  float offset = texture2D(tex, texCoord).x;
  offset = (offset - 0.5) * 2.0; //map 0->1 to -1 to +1
  float posx = position.x;
  float posy = position.y + offset/8.0;

  gl_Position = vec4(posx, posy, 0.0, 1.0);
}

我在 http://www.mat.ucsb.edu/a.forbes/blog/?p=453

这篇关于顶点着色器中的纹理查找在 iPad 设备与 iPad 模拟器上的行为不同 - OpenGL ES 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:22