Linking sampler2DRect array to ofShader

Hi,

I am using shader to generate pictures. I would like to use a sampler2DRect array in my shader.

I don’t know how to set that array in openframeworks, so the shader could grab them. How is the correct way to do it? I have tried different options with no success

Some code:

quad.frag

uniform sampler2DRect quadTexture;
uniform sampler2DRect images[12];

ofApp

void ofApp::draw(){
      shader.begin();
        ofParameterGroup params1;
        params1.setName("images");
        for(int i = 0; i < imagesTextures.size(); i++){
            ofParameter<ofTexture> textures_params("images", imagesTextures.at(i));
            params1.add(textures_params);
        }
        shader.setUniforms(params1);    
      quadFbo.draw(0,0);
    shder.end();
}

Any help would be appreciated

Hi there!

There is no sampler2DRectArray, only sampler2DArray. And OF doesn’t have, as in 093, a wrap for it. So, you’ll have to do it yourself.

Basically, you attach the textures do the same object and on the shader you sample the texture with a vec3, instead of vec2, where the vec3.z is the index.

1 Like

I ended up implementing this over the weekend and put it up on gist in case it would be helpful.

It’s still a little rough around the edges …

2 Likes