Hi

Is there a way to pass a list of images to a shader as individual images?

For instance, if I enqueue live video, how would I go about addressing the individual images(or frames) from the list as texture2ds in the shader? I suspect I would I have to convert the list to images before passing them to the shader, but is there a way to make the shader itself populate the uniform inputImageTexture[numOfImages] in the shader?

Comments

In your fragment shader, you

jstrecker's picture
Submitted by

In your fragment shader, you can declare it like this:

uniform sampler2D t[4];

and access it like this:

vec4 c = texture2D(t[0], fragmentTextureCoordinate.xy);

In the node(Instance)Event function, you can assign a VuoImage like this:

VuoShader_setUniform_VuoImage((*instance)->shader, "t[0]", image);

OpenGL makes you refer to each element in a uniform array by using a string constant, so to dynamically fill in multiple, you need to concatenate the string. For example, if you have:

VuoInputData(VuoList_VuoImage) images

you can feed it to the shader like this:

unsigned long count = VuoListGetCount_VuoImage(images);
for (unsigned long i = 1; i <= count; ++i)
{
    char *identifier = VuoText_format("t[%d]", i-1);
    VuoShader_setUniform_VuoImage((*instance)->shader, identifier, VuoListGetValue_VuoImage(images, i));
    free(identifier);
}

OpenGL hardware tends to have low limits on the number of images that can be accessed from a shader — 16 is typical among current macOS hardware (GL_MAX_TEXTURE_IMAGE_UNITS). So if you have more images than that, you'll have to combine them using multiple rendering passes.