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.
...I mean, I feel like I'm using a synthesizer and I don't know how to change the program within a bank, so I store all my timbres in program 1 of each bank and then switch among banks!!
On 06/10/2011 09:20 PM, Matteo Sisti Sette wrote:
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.
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@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 06/10/2011 09:44 PM, cyrille henry wrote:
is pix_buffer_read, or pix_multitexture an option for you?
Thanks for the suggestion. It probably is, but I'll have to make some drastical changes to the overall architecture of the patch which at the moment is using multiple [pix_texture] objects.
If you were obliged to keep using multiple [pix_teture]s, is there a way to "map" the textures "generated" by [pix_texture] objects to the ones used in the shader program? I mean based on the texture id's coming out from the right outlet of [pix_texture]?
How do I tell the shader "your sampler2D variable MyTex is texture 160" where 160 is the id coming out of a [pix_texture] object?
On 06/10/2011 09:20 PM, Matteo Sisti Sette wrote:
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.
Errr....... it seems that's not true. I still don't understand how texunits work but I've tested the abovementioned approach with 9 textures and it worked.
However, curiously enough, if I try the following:
[gemhead] | [pix_image] | [pix_texture] | [square 4]
and I send [pix_texture] a "textunit N" message, it stops showing the image at N=4.
Does anybody know why?