Can someone explain to me why the following shader works with Sampler2DRect but not with Sampler2D and ofDisableArbTex():
Working shader I can use with normal textures/fbos:
Vertex Shader
void main() {
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Fragment Shader
#extension GL_ARB_texture_rectangle : enable
uniform vec2 tcOffset[25]; // offsets
uniform sampler2DRect inputTexture; // texture
void main() {
vec4 sample[25];
vec4 minValue = vec4(1.0);
for (int i = 0; i < 25; i++) {
sample[i] = texture2DRect(inputTexture, gl_TexCoord[0].xy + tcOffset[i]);
minValue = min(sample[i], minValue);
}
gl_FragColor = minValue;
}
But even with ofDisableArbTex() this doesn’t work:
uniform vec2 tcOffset[25]; // offsets
uniform sampler2D inputTexture; // texture
void main() {
vec4 sample[25];
vec4 minValue = vec4(1.0);
for (int i = 0; i < 25; i++) {
sample[i] = texture2D(inputTexture, gl_TexCoord[0].xy + tcOffset[i]);
minValue = min(sample[i], minValue);
}
gl_FragColor = minValue;
}
I’m sure this is something mind numbingly simple but I have a bunch of shader examples (more complex than this) I’m trying to get working and they all use Sampler2D…and for the life of me I can’t see why this shouldn’t work.
BTW tcOffsets are calculated with:
// Set up texture sampling offset storage
const GLint tcOffsetColumns = 5;
const GLint tcOffsetRows = 5;
GLfloat texCoordOffsets[tcOffsetColumns * tcOffsetRows * 2];
//--------------------------------------------------------------
void genTexCoordOffsets(GLuint width, GLuint height, GLfloat step = 1.0f){
// Calculate texture coordinate offsets for kernel convolution effects
// Note: You can multiply the step to displace the samples further.
float xInc = step / (GLfloat)(width);
float yInc = step / (GLfloat)(height);
for (int i = 0; i < tcOffsetColumns; i++)
{
for (int j = 0; j < tcOffsetRows; j++)
{
texCoordOffsets[(((i*5)+j)*2)+0] = ((-2.0f * xInc) + ((GLfloat)i * xInc)) * width;
texCoordOffsets[(((i*5)+j)*2)+1] = ((-2.0f * yInc) + ((GLfloat)j * yInc)) * height;
}
}
}