[PD] How to dynamically choose which image to use as texture in a shader (or, understanding tex units and texture id's)

cyrille henry ch at chnry.net
Fri Jun 10 21:44:02 CEST 2011


hello,

is pix_buffer_read, or pix_multitexture an option for you?
c

Le 10/06/2011 21:20, Matteo Sisti Sette a écrit :
> Hi,
>
> Let's first consider an example that does not involve shaders to explain what's the thing that I can already do with images and that I would like to apply to shaders.
>
> Say I have M images and N squares, and I want to dynamically reassign which image to use as a texture on which square. It may be M>N or M<N but let's suppose M>N. At any time I want to say: rectangle m uses image n. Multiple rectangles may be using the same image at a given time.
>
> For a series of reasons I can't afford using "open" messages because I want all the images to be preloaded. So one approach is to use [pix_texture]'s right inlets and outlets.
>
> I have M:
> [pix_image]
> |
> [pix_texture]
>
> and N:
> [pix_texture]
> |
> [square]
>
> By using [pix_texture]'s right outlets and inlets (with sends and receives) I can "map" the texture I want to the square I want.
>
>
> Now suppose that for each rectangle I want to use a shader that somewhat mixes two (or may be even more) of the M textures, and I want to select which ones dinamically.
>
>
> How do I accomplish that? How do I "pass" texture id's (those coming from the right outlets of textures) to the shader and have it correspond to a sampler2D variable in the shader?
>
>
> So far the only way to work with multiple textures in a shader and dynamically set which textures to use from the patch, is to use texunits. I send a [pix_texture] a "texunit K" message, and I send the same number K to a uniform sampler2D variable of the shader.
> However, there can only be up to 4 texunits available (maybe 8 on some platform)!!!!! So this would only work for M and N <4 which is not my case.
>
> There must be a way to use those texture id's that [pix_texture] uses, isn't there?
>
>
> Thanks
> m.
>
> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>



More information about the Pd-list mailing list