hello,
i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl?
thanks Cyrille
Use a texture sampler in your shader. GLSL has a sampler for 2D and RECT texutres, so make sure you have the right one for the texture type (OSX defaults to RECT while Win/Linux are probably 2D).
uniform sampler2D MyTex;
void main (void) { vec4 color = texture2D(MyTex, gl_TexCoord[0].st); color = color * 0.5; gl_FragColor = color; }
That is untested but it should result in something.
cgc
On 8/25/06, cyrille henry cyrille.henry@la-kitchen.fr wrote:
hello,
i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl?
thanks Cyrille
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
i still don't understand how to load a jpg file to MyTex.
attachement is my test patch. it does not render any texture.
thanks Cyrille
chris clepper a écrit :
Use a texture sampler in your shader. GLSL has a sampler for 2D and RECT texutres, so make sure you have the right one for the texture type (OSX defaults to RECT while Win/Linux are probably 2D).
uniform sampler2D MyTex;
void main (void) { vec4 color = texture2D(MyTex, gl_TexCoord[0].st); color = color * 0.5; gl_FragColor = color; }
That is untested but it should result in something.
cgc
On 8/25/06, *cyrille henry* <cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
hello, i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl? thanks Cyrille _______________________________________________ GEM-dev mailing list GEM-dev@iem.at <mailto:GEM-dev@iem.at> http://lists.puredata.info/listinfo/gem-dev
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
void main() { // perform standard transform on vertex gl_Position = ftransform();
}
uniform sampler2D MyTex;
void main (void) { vec4 color = texture2D(MyTex, gl_TexCoord[0].st); color = color * 0.5; gl_FragColor = color; }
#N canvas 756 30 630 784 10; #X obj 75 22 gemhead; #X obj 87 173 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #N canvas 0 22 450 300 open 0; #X obj 75 103 openpanel; #X obj 75 173 outlet; #X obj 75 127 t b s; #X msg 105 152 set open $1; #X obj 75 80 inlet; #X connect 0 0 2 0; #X connect 2 0 1 0; #X connect 2 1 3 0; #X connect 3 0 1 0; #X connect 4 0 0 0; #X restore 87 193 pd open; #X msg 28 212 print; #X obj 73 623 glsl_program; #X obj 146 443 pack 0 0; #X obj 84 290 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #N canvas 0 22 450 300 open 0; #X obj 75 103 openpanel; #X obj 75 173 outlet; #X obj 75 127 t b s; #X msg 105 152 set open $1; #X obj 75 80 inlet; #X connect 0 0 2 0; #X connect 2 0 1 0; #X connect 2 1 3 0; #X connect 3 0 1 0; #X connect 4 0 0 0; #X restore 84 308 pd open; #X msg 30 324 print; #X obj 167 423 t b f; #X obj 167 378 change; #X obj 145 253 change; #X msg 146 483 link $1 $2; #X msg 29 549 print; #X text 187 361 the fragment shader; #X floatatom 167 404 2 0 0 0 ID - -; #X floatatom 145 276 2 0 0 0 ID - -; #X obj 164 504 print linking; #X obj 73 667 rotateXYZ; #X floatatom 92 645 5 0 0 0 - - -; #X obj 73 149 colorRGB; #X floatatom 185 112 5 0 0 0 - - -; #X floatatom 231 110 5 0 0 0 - - -; #X floatatom 136 645 5 0 0 0 - - -; #X floatatom 178 643 5 0 0 0 - - -; #X obj 73 358 glsl_fragment; #X obj 73 234 glsl_vertex; #X obj 75 82 pix_image; #X msg 102 53 open test.jpg; #X obj 75 115 pix_texture; #X msg 453 62 color 1 0 0; #X floatatom 278 110 5 0 0 0 - - -; #X obj 430 156 gemwin; #X msg 466 95 create , 1; #X msg 486 122 destroy; #X obj 74 700 square; #X msg 87 212 open test.vert; #X msg 83 328 open test.frag; #X connect 0 0 27 0; #X connect 1 0 2 0; #X connect 2 0 36 0; #X connect 3 0 26 0; #X connect 4 0 18 0; #X connect 5 0 12 0; #X connect 6 0 7 0; #X connect 7 0 37 0; #X connect 8 0 25 0; #X connect 9 0 5 0; #X connect 9 1 5 1; #X connect 10 0 15 0; #X connect 11 0 16 0; #X connect 12 0 4 0; #X connect 12 0 17 0; #X connect 13 0 4 0; #X connect 15 0 9 0; #X connect 16 0 5 0; #X connect 18 0 35 0; #X connect 19 0 18 1; #X connect 20 0 26 0; #X connect 21 0 20 1; #X connect 21 0 20 2; #X connect 22 0 20 3; #X connect 23 0 18 2; #X connect 24 0 18 3; #X connect 25 0 4 0; #X connect 25 1 10 0; #X connect 26 0 25 0; #X connect 26 1 11 0; #X connect 27 0 29 0; #X connect 28 0 27 0; #X connect 29 0 20 0; #X connect 30 0 32 0; #X connect 31 0 20 4; #X connect 33 0 32 0; #X connect 34 0 32 0; #X connect 36 0 26 0; #X connect 37 0 25 0;
hi,
On Aug 25, 2006, at 12:00 PM, cyrille henry wrote:
i still don't understand how to load a jpg file to MyTex.
attachement is my test patch. it does not render any texture.
...I've attached a modified version of your patch that works here, just reduces the brightness by half...
chris clepper a écrit :
Use a texture sampler in your shader. GLSL has a sampler for 2D and RECT texutres, so make sure you have the right one for the texture type (OSX defaults to RECT while Win/Linux are probably 2D).
...in other words, when using sampler2D, your texture needs to be dimensionally square (ie. 256x256)...also, [pix_texture] usually defaults to loading in "mode 1", which means rectangle textures: make sure you send [mode 0< to it before loading the texture...
...you'll also notice that I rearranged the ordering of operations within the gemchain: this is because we want the program to affect the entire operation of drawing...
...I'll definitely try to work up some other examples while I'm still in hospital, but feeling well...
jamie
hello, it's working!
moreover, i'm happy to see you're felling well.
it was a pix_image / pix_texture position problem.
i think i'll have some examples to share in a few day...
just a question : is it possible to use 2 textures? (using 2 pix_image / pix_texture in the same gemchain?)
thanks a lot
Cyrille
james tittle a écrit :
hi,
On Aug 25, 2006, at 12:00 PM, cyrille henry wrote:
i still don't understand how to load a jpg file to MyTex.
attachement is my test patch. it does not render any texture.
...I've attached a modified version of your patch that works here, just reduces the brightness by half...
chris clepper a écrit :
Use a texture sampler in your shader. GLSL has a sampler for 2D and RECT texutres, so make sure you have the right one for the texture type (OSX defaults to RECT while Win/Linux are probably 2D).
...in other words, when using sampler2D, your texture needs to be dimensionally square (ie. 256x256)...also, [pix_texture] usually defaults to loading in "mode 1", which means rectangle textures: make sure you send [mode 0< to it before loading the texture...
...you'll also notice that I rearranged the ordering of operations within the gemchain: this is because we want the program to affect the entire operation of drawing...
...I'll definitely try to work up some other examples while I'm still in hospital, but feeling well...
jamie
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
On Aug 26, 2006, at 1:40 PM, cyrille henry wrote:
hello, it's working!
...cool...
moreover, i'm happy to see you're felling well.
...I wouldn't yet say "well", but I'm on the mend ;-)
it was a pix_image / pix_texture position problem.
i think i'll have some examples to share in a few day...
just a question : is it possible to use 2 textures? (using 2 pix_image / pix_texture in the same gemchain?)
...yes, but you have to have loaded them previously with [pix_texture], then use [pix_multitexture], and assign the texID's to the particular multitexture (up to 8)...this works, but is not as straight forward patching-wise as I'd like, so [pix_multitexture] should definitely be viewed as a work in progress...
...you can also use [gemframebuffer] at the top of a chain to do "offscreen" rendering, then use the results in a later gemchain with [pix_multitexture]...
more l8r, jamie
hello,
james tittle a écrit :
On Aug 26, 2006, at 1:40 PM, cyrille henry wrote:
hello, it's working!
...cool...
moreover, i'm happy to see you're felling well.
...I wouldn't yet say "well", but I'm on the mend ;-)
i wish you the best in your recovery
it was a pix_image / pix_texture position problem.
i think i'll have some examples to share in a few day...
just a question : is it possible to use 2 textures? (using 2 pix_image / pix_texture in the same gemchain?)
...yes, but you have to have loaded them previously with [pix_texture], then use [pix_multitexture], and assign the texID's to the particular multitexture (up to 8)...this works, but is not as straight forward patching-wise as I'd like, so [pix_multitexture] should definitely be viewed as a work in progress...
hum. i can't make it work. attachement is the patch i try. it's certanly stupid, like last time, but can't find why.
...you can also use [gemframebuffer] at the top of a chain to do "offscreen" rendering, then use the results in a later gemchain with [pix_multitexture]...
wow, that could be cool. but can't make it work to. example would be nice.
thanks Cyrille
more l8r, jamie
uniform sampler2D MyTex1; uniform sampler2D MyTex2;
void main() { gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
uniform sampler2D MyTex1; uniform sampler2D MyTex2;
void main (void) { vec4 color1 = texture2D(MyTex1, gl_TexCoord[0].st); vec4 color2 = texture2D(MyTex2, gl_TexCoord[0].st); gl_FragColor = mix(color1,color2,0.5) ;
}
#N canvas 823 30 699 763 10; #X obj 82 61 gemhead; #X obj 95 80 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #N canvas 0 22 450 300 open 0; #X obj 75 103 openpanel; #X obj 75 173 outlet; #X obj 75 127 t b s; #X msg 105 152 set open $1; #X obj 75 80 inlet; #X connect 0 0 2 0; #X connect 2 0 1 0; #X connect 2 1 3 0; #X connect 3 0 1 0; #X connect 4 0 0 0; #X restore 95 100 pd open; #X msg 36 119 print; #X obj 82 428 glsl_program; #X obj 154 350 pack 0 0; #X obj 92 197 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #N canvas 0 22 450 300 open 0; #X obj 75 103 openpanel; #X obj 75 173 outlet; #X obj 75 127 t b s; #X msg 105 152 set open $1; #X obj 75 80 inlet; #X connect 0 0 2 0; #X connect 2 0 1 0; #X connect 2 1 3 0; #X connect 3 0 1 0; #X connect 4 0 0 0; #X restore 92 215 pd open; #X msg 38 231 print; #X obj 175 330 t b f; #X obj 175 285 change; #X obj 153 160 change; #X msg 154 390 link $1 $2; #X msg 36 397 print; #X floatatom 175 311 2 0 0 0 ID - -; #X floatatom 153 183 2 0 0 0 ID - -; #X obj 172 411 print linking; #X obj 82 647 rotateXYZ; #X floatatom 101 625 5 0 0 0 - - -; #X floatatom 145 625 5 0 0 0 - - -; #X floatatom 187 625 5 0 0 0 - - -; #X obj 81 265 glsl_fragment; #X obj 81 141 glsl_vertex; #X msg 414 45 color 1 0 0; #X msg 503 45 create , 1; #X msg 579 45 destroy; #X obj 82 676 scaleXYZ 2 2 2; #X msg 468 307 mode $1; #X obj 468 287 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 468 241 loadbang; #X msg 468 265 0; #X msg 397 307 quality 0; #X obj 82 699 square; #X obj 243 68 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X msg 134 478 mode $1; #X obj 134 458 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 82 598 pix_multitexture 2; #X obj 384 182 gemhead 1; #X msg 398 209 open multitexture.jpg; #X obj 384 241 pix_image; #X obj 384 342 pix_texture; #X floatatom 456 367 5 0 0 0 - - -; #X msg 472 569 mode $1; #X obj 472 549 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 472 503 loadbang; #X msg 472 527 0; #X msg 400 567 quality 0; #X msg 404 469 open deplace.jpg; #X obj 387 498 pix_image; #X obj 387 627 pix_texture; #X floatatom 459 650 5 0 0 0 - - -; #X obj 387 435 gemhead 2; #X obj 388 658 cube; #X floatatom 459 605 5 0 0 0 - - -; #X obj 385 375 cube 0.3; #X obj 443 412 s id1; #X obj 442 699 s id2; #X obj 144 502 r id1; #X msg 144 524 texUnit $1 0; #X msg 161 568 texUnit $1 1; #X obj 397 75 gemwin 45; #X msg 95 119 open test_multit.vert; #X msg 92 235 open test_multit.frag; #X obj 161 548 r id2; #X obj 442 671 change; #X obj 443 391 change; #X msg 577 171 open $1; #X obj 577 148 openpanel; #X obj 577 128 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X msg 563 425 open $1; #X obj 563 402 openpanel; #X obj 563 382 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X connect 0 0 22 0; #X connect 1 0 2 0; #X connect 2 0 61 0; #X connect 3 0 22 0; #X connect 4 0 36 0; #X connect 5 0 12 0; #X connect 6 0 7 0; #X connect 7 0 62 0; #X connect 8 0 21 0; #X connect 9 0 5 0; #X connect 9 1 5 1; #X connect 10 0 14 0; #X connect 11 0 15 0; #X connect 12 0 4 0; #X connect 12 0 16 0; #X connect 13 0 4 0; #X connect 14 0 9 0; #X connect 15 0 5 0; #X connect 17 0 26 0; #X connect 18 0 17 1; #X connect 19 0 17 2; #X connect 20 0 17 3; #X connect 21 0 4 0; #X connect 21 1 10 0; #X connect 22 0 21 0; #X connect 22 1 11 0; #X connect 23 0 60 0; #X connect 24 0 60 0; #X connect 25 0 60 0; #X connect 26 0 32 0; #X connect 27 0 40 0; #X connect 28 0 27 0; #X connect 29 0 30 0; #X connect 29 0 31 0; #X connect 30 0 28 0; #X connect 31 0 40 0; #X connect 33 0 61 0; #X connect 33 0 62 0; #X connect 34 0 36 0; #X connect 35 0 34 0; #X connect 36 0 17 0; #X connect 37 0 39 0; #X connect 38 0 39 0; #X connect 39 0 40 0; #X connect 40 1 41 0; #X connect 40 1 65 0; #X connect 42 0 49 0; #X connect 43 0 42 0; #X connect 44 0 45 0; #X connect 44 0 46 0; #X connect 45 0 43 0; #X connect 46 0 49 0; #X connect 47 0 48 0; #X connect 48 0 49 0; #X connect 49 1 50 0; #X connect 49 1 64 0; #X connect 51 0 48 0; #X connect 53 0 49 1; #X connect 57 0 58 0; #X connect 58 0 36 0; #X connect 59 0 36 0; #X connect 61 0 22 0; #X connect 62 0 21 0; #X connect 63 0 59 0; #X connect 64 0 56 0; #X connect 65 0 55 0; #X connect 66 0 39 0; #X connect 67 0 66 0; #X connect 68 0 67 0; #X connect 69 0 48 0; #X connect 70 0 69 0; #X connect 71 0 70 0;
On 8/29/06, cyrille henry cyrille.henry@la-kitchen.fr wrote:
void main() { gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Try adding this:
gl_TexCoord[1] = gl_MultiTexCoord1;
Also, you might want to check out the GL 'OrangeBook' which covers GLSL. The imaging section is truly awful though - don't use any of those shaders - but it does go over the general spec. It mentions MultiTexCoords on two pages out of nearly 600.
There might be some better shader examples from ATI, Apple or a game tutorial site.
cgc
hello Chris,
chris clepper a écrit :
On 8/29/06, *cyrille henry* <cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
Try adding this:
gl_TexCoord[1] = gl_MultiTexCoord1;
yes, i forget this. but that's not the only problem, my square is still black.
Also, you might want to check out the GL 'OrangeBook' which covers GLSL. The imaging section is truly awful though - don't use any of those shaders - but it does go over the general spec. It mentions MultiTexCoords on two pages out of nearly 600.
i ordered the orange book. waiting for it.
There might be some better shader examples from ATI, Apple or a game tutorial site.
i also have problem with gem, as there is no help for gemframebuffer or pix_multitexture.
thanks for your help
Cyrille
cgc
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
cyrille
I got multiple texture sources working with ARB_fragment shaders here. The problem is that we need to do some more work on the GEM code to make it useful for everyone.
cgc
On 8/29/06, cyrille henry cyrille.henry@la-kitchen.fr wrote:
hello Chris,
chris clepper a écrit :
On 8/29/06, *cyrille henry* <cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
Try adding this:
gl_TexCoord[1] = gl_MultiTexCoord1;
yes, i forget this. but that's not the only problem, my square is still black.
Also, you might want to check out the GL 'OrangeBook' which covers GLSL. The imaging section is truly awful though - don't use any of those shaders - but it does go over the general spec. It mentions MultiTexCoords on two pages out of nearly 600.
i ordered the orange book. waiting for it.
There might be some better shader examples from ATI, Apple or a game tutorial site.
i also have problem with gem, as there is no help for gemframebuffer or pix_multitexture.
thanks for your help
Cyrille
cgc
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
Add
gl_TexCoord[0] = gl_MultiTexCoord0;
To your vertex program.
On 8/25/06, cyrille henry cyrille.henry@la-kitchen.fr wrote:
hello,
i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl?
thanks Cyrille
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
This does not change anything : my primitive is still black. thanks Cyrille
chris clepper a écrit :
Add
gl_TexCoord[0] = gl_MultiTexCoord0;
To your vertex program.
On 8/25/06, *cyrille henry* < cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
hello, i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl? thanks Cyrille _______________________________________________ GEM-dev mailing list GEM-dev@iem.at <mailto:GEM-dev@iem.at> http://lists.puredata.info/listinfo/gem-dev
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
uniform sampler2DRect MyTex;
void main (void) { vec4 color = texture2DRect(MyTex, gl_TexCoord[0].st); color = color* 0.5; gl_FragColor = color; }
Works on OSX.
Change use sampler2D and texture2D for non-rectangle textures. Or use arb_fragment program which is more straightforward and performs better.
cgc
On 8/25/06, cyrille henry cyrille.henry@la-kitchen.fr wrote:
This does not change anything : my primitive is still black. thanks Cyrille
chris clepper a écrit :
Add
gl_TexCoord[0] = gl_MultiTexCoord0;
To your vertex program.
On 8/25/06, *cyrille henry* < cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
hello, i'm trying to learn glsl. I can't find how to use texture in the fragment shader. does anyone have an exemple how to load texture with GEM glsl? thanks Cyrille _______________________________________________ GEM-dev mailing list GEM-dev@iem.at <mailto:GEM-dev@iem.at> http://lists.puredata.info/listinfo/gem-dev
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
chris clepper a écrit :
void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
uniform sampler2DRect MyTex;
void main (void) { vec4 color = texture2DRect(MyTex, gl_TexCoord[0].st); color = color* 0.5; gl_FragColor = color; }
Works on OSX.
with the pd patch i send to the list?
it does not work on my computer. did anyone tested this on linux?
i forget to say : when i send print to glsl_program, i have :
glsl_Program Hardware Info ============================
[glsl_program]: uvar#0: "MyTex": unknown (0x8B5E) [glsl_program]: uvar#1: "gl_ModelViewProjectionMatrixTranspose": GL_FLOAT_MAT4_ARB
with sampler2DRect and texture2DRect : the shader does not compile. I use sampler2D and texture2D.
anyway, i'll have to find informations about arb_fragments.
thanks Cyrille
Change use sampler2D and texture2D for non-rectangle textures. Or use arb_fragment program which is more straightforward and performs better.
cgc
On 8/25/06, *cyrille henry* <cyrille.henry@la-kitchen.fr mailto:cyrille.henry@la-kitchen.fr> wrote:
This does not change anything : my primitive is still black. thanks Cyrille chris clepper a écrit : > Add > > gl_TexCoord[0] = gl_MultiTexCoord0; > > To your vertex program. > > > On 8/25/06, *cyrille henry* < cyrille.henry@la-kitchen.fr <mailto:cyrille.henry@la-kitchen.fr> > <mailto:cyrille.henry@la-kitchen.fr <mailto:cyrille.henry@la-kitchen.fr>>> wrote: > > hello, > > i'm trying to learn glsl. > I can't find how to use texture in the fragment shader. > does anyone have an exemple how to load texture with GEM glsl? > > thanks > Cyrille > > _______________________________________________ > GEM-dev mailing list > GEM-dev@iem.at <mailto:GEM-dev@iem.at> <mailto: GEM-dev@iem.at <mailto:GEM-dev@iem.at>> > http://lists.puredata.info/listinfo/gem-dev > > > > ------------------------------------------------------------------------ > > _______________________________________________ > GEM-dev mailing list > GEM-dev@iem.at <mailto:GEM-dev@iem.at> > http://lists.puredata.info/listinfo/gem-dev <http://lists.puredata.info/listinfo/gem-dev>