vis*_*ran 5 android opengl-es glsl
我正在使用OpenGL es 3.0和我的 GLSL 版本#version 300 es。
我正在尝试计算 GPU 中的发光直方图。我已经确定我的设备支持顶点纹理获取并尝试使用 texelFetch 函数读取顶点着色器中的颜色信息。我使用 texelFetch 是因为我传入每个纹理坐标以便读取每个像素的颜色信息。
附上代码
#version 300 es
uniform sampler2D imageTexture;
in vec2 texturePosition;
const float SCREEN_WIDTH = 1024.0;
in vec4 position;
vec2 texturePos;
out vec3 colorFactor;
const vec3 W = vec3(0.299, 0.587, 0.114);
void main() {
texturePos = texturePosition / SCREEN_WIDTH;
vec3 color = texelFetch(imageTexture, texturePos.xy,0).rgb;
float luminance = dot(color.xyz,W);
colorFactor = vec3(1.0, 1.0, 1.0);
gl_Position = vec4(-1.0 + (luminance * 0.00784313725), 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
};
Run Code Online (Sandbox Code Playgroud)
现在收到错误“texelFetch”:找不到匹配的重载函数。
有人可以帮助解决错误并提供建议来计算 GPU 中的发光直方图。
texturePos 需要是 ivec2,具有整数纹理坐标(即纹理中的像素位置)而不是标准化的 [0.0 1.0] 浮点坐标。
下面的代码应该可以工作:
#version 300 es
uniform sampler2D imageTexture;
in ivec2 texturePosition;
in vec4 position;
out vec3 colorFactor;
const vec3 W = vec3(0.299, 0.587, 0.114);
void main() {
vec3 color = texelFetch(imageTexture, texturePosition, 0).rgb;
float luminance = dot(color, W);
colorFactor = vec3(1.0, 1.0, 1.0);
gl_Position = vec4(-1.0 + (luminance * 0.00784313725), 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
};
Run Code Online (Sandbox Code Playgroud)
但是您需要向“texturePosition”输入数组提供整数,其中包含要作为整数包含在直方图中的所有 (x,y) 像素坐标。(使用 VBO)。
正如评论中指出的,您需要使用 glVertexAttribIPointer() 来提供整数类型。
| 归档时间: |
|
| 查看次数: |
1853 次 |
| 最近记录: |