Forums > Jitter

shaders in jit.gl.sketch?

February 14, 2006 | 10:33 pm

Hi there,

Can someone help me out with a quick example of how to use a
jit.gl.shader in a jit.gl.sketch cmdlist?
Is that possible?

Thanks,
Evan


February 14, 2006 | 10:39 pm

Works here. All I did was add this:

#P window setfont "Sans Serif" 9.;
#P flonum 117 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 103 134 104 196617 param edgefalloff $1;
#P message 100 154 93 196617 read mat.xray.jxs;
#P newex 61 177 125 196617 jit.gl.shader foo @name x;
#P connect 2 0 0 0;
#P connect 3 0 2 0;
#P connect 1 0 0 0;
#P window clipboard copycount 4;

to the sketch help file along with a message "shader x" connected to
jit.gl.sketch. Adjust the shader parameter to see if it’s working.

wes


February 14, 2006 | 10:57 pm

True, that’s one way. I was thinking more of applying shaders to
different objects in a sketch cmdlist, like (in psuedo-code):

1. enable texture
2. use texture
3. use shader (from jit.gl.shader)
4. draw sphere or other shape

Just curious – I have a jit.gl.sketch drawing lots of concentric
spheres, and it would be great to apply shaders to some of those
spheres but not all.

thanks,
-evan


February 14, 2006 | 11:05 pm

> Just curious – I have a jit.gl.sketch drawing lots of concentric
> spheres, and it would be great to apply shaders to some of those
> spheres but not all.
>

In this case, I would be includes to use a gridshape with @automatic 0
and multiple draws. If you have 2+ gridshapes, you can assign them
differenct shaders or none at all. You just need to manage scale and
positioning. I posted some JS stuff in javscript-dev that outlined
how to do this.

good luck,
wes


February 15, 2006 | 12:41 am

On Feb 14, 2006, at 2:57 PM, evan.raskob wrote:

> True, that’s one way. I was thinking more of applying shaders to
> different objects in a sketch cmdlist, like (in psuedo-code):
>
> 1. enable texture
> 2. use texture
> 3. use shader (from jit.gl.shader)
> 4. draw sphere or other shape

Actually there’s (undocumented) code in place for binding shader
programs in jit.gl.sketch. The commands are glbindprogram
, and glunbindprogram (which is equivalent
to glbindprogram with no argument). So, assuming you have an instance
of [jit.gl.shader @name shady] in your patch, something like the
following should work. At bottom is a simple example with a similar
program, plus some extra bells and whistles to make it look better.

reset,
glbindprogram shady,
sphere 0.5,
glunbindprogram shady,
moveto -0.5 0. 0.,
glcolor 1. 0.7 0.5,
sphere 0.5

Note that you can also bind/unbind textures in a similar fashion with
glbindtexture . To unbind, you would
provide no argument. In fact you can actually implement
something like slab with these commands if you set up the modelview
transform and geometry properly. FWIW, before we made a C object for
jit.gl.slab, we prototyped it with jit.gl.sketch.

Let us know if you encounter any problems.

-Joshua

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 220 256 157 196617 jit.gl.handle foo @blend_enable 1;
#P window linecount 4;
#P message 228 148 320 196617 reset , shapeslice 80 80 , glenable
cull_face , glcullface 1 , glenable depth_test , glcolor 0.4 0.6
0.7 , sphere 0.5 , glblendfunc 6 1 , moveto -0.5 0. 0. ,
gldisable cull_face , gldisable depth_test , glcolor 0.5 0.2 0.1 ,
glbindprogram shady , sphere 0.5 , glunbindprogram shady;
#P window linecount 1;
#P newex 294 328 234 196617 jit.gl.shader foo @name shady @file
mat.xray.jxs;
#B color 5;
#P toggle 241 452 15 0;
#P message 241 470 55 196617 floating $1;
#P hidden message 48 413 68 196617 camera 0 0 4;
#P toggle 168 452 15 0;
#P newex 129 451 35 196617 sel 27;
#P message 168 470 68 196617 fullscreen $1;
#P newex 86 494 186 196617 jit.window foo @depthbuffer 1 @fsaa 1;
#P newex 84 451 40 196617 key;
#P user jit.fpsgui 59 234 60 196617 0;
#P newex 136 412 43 196617 s shady;
#P toggle 136 362 15 0;
#P message 136 385 94 196617 smooth_shading $1;
#P toggle 235 362 15 0;
#P message 235 385 90 196617 lighting_enable $1;
#P hidden newex 176 319 50 196617 loadbang;
#P number 60 105 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 15 105 15 0;
#P newex 15 131 55 196617 qmetro 20;
#P newex 15 208 55 196617 t b erase b;
#P newex 144 297 158 196617 jit.gl.sketch foo @blend_enable 1;
#P newex 15 585 213 196617 jit.gl.render foo @erase_color 0.7 0.7 0.7
1.;
#P hidden message 176 341 14 196617 1;
#P newex 144 227 43 196617 r shady;
#P connect 6 0 5 0;
#P connect 5 0 4 0;
#P fasten 3 0 2 0 149 328 20 328;
#P hidden fasten 20 0 2 0 53 506 20 506;
#P connect 4 0 2 0;
#P fasten 4 1 2 0 42 234 20 234;
#P hidden connect 8 0 20 0;
#P connect 4 2 14 0;
#P connect 7 0 5 1;
#P fasten 21 0 16 0 246 489 91 489;
#P fasten 17 0 16 0 173 489 91 489;
#P fasten 15 0 18 0 89 470 126 470 126 449 134 449;
#P hidden fasten 1 0 12 0 181 359 141 359;
#P connect 12 0 11 0;
#P fasten 9 0 13 0 240 407 141 407;
#P fasten 11 0 13 0 141 407 141 407;
#P connect 25 0 3 0;
#P fasten 0 0 3 0 149 265 149 265;
#P connect 24 0 3 0;
#P fasten 18 0 19 0 134 469 165 469 165 449 173 449;
#P connect 19 0 17 0;
#P hidden connect 8 0 1 0;
#P hidden connect 8 0 24 0;
#P hidden fasten 1 0 10 0 181 359 240 359;
#P connect 10 0 9 0;
#P connect 22 0 21 0;
#P window clipboard copycount 26;


February 15, 2006 | 3:59 pm

that’s awesome joshua, that’s just what i was hoping for.

and to answer wesley (and anyone else who is interested), i’m using
jit.gl.sketch because it allows you to draw and texture multiple shapes
at once, and then with the capture attribute, you can render it to a
texture and then put it through a series of slabs and such. since you
can’t render only a group of jit.gl.gridshapes together and have them
capture to a single texture (as far as i can figure out), you need
sketch. i have a massive patch that uses this to create a series of
versions of a single sketch rendering, and then i use a crossfader slab
to fade between each for seamless fx blending between each rendering,
plus other layers of gridshapes mixed into the final scene. very hot.
even at 640×480 for each texture (explicitly set using @dim 640 480),
it runs incredibly well on my 2 year old powerbook.

best,
evan


February 15, 2006 | 4:23 pm

one odd thing – in the example patch in your email, changing the X,Y,Z
values in the "moveto X Y Z" line makes no difference on my machine,
jitter 1.5.2 in OS X 10.3.9. is that because of my admittedly
incomplete understanding of OpenGL? it’d be great of you could explain
why it works like that, or if it’s not supposed to work like that…

thanks,
evan


February 15, 2006 | 4:24 pm

Hey Evan,

>since you can’t render only a group of jit.gl.gridshapes together >and have them capture to a single texture (as far as i can figure >out)

This is not entirely true. Please see:

http://cycling74.com/story/2006/2/14/161736/108
Recipe 24: GLFeedBack.

This gives a technique for using the "to_texture" message for capturing a scene to texture. I would imagine that using jit.gl.sketch is probably your most efficient option anyway, so it sounds like you are doing fine. I would love to see the results.

AB


February 15, 2006 | 5:08 pm

and one question about coordinates:
which is the best jitter-object for tracking movement, if the
movement is supposed to be sent as coordinates (x,y) to another
programme like flash ?
im looking something similar to what eyesweb has for tracking ,….

thanks a lot in advance,
m.


February 15, 2006 | 5:08 pm

dear all,

i have a friend who is programming c++, how could his code be
translated into an jitter-object ?
or something that works with jitter patch ?

best,
m.


February 15, 2006 | 5:14 pm

Have a look at http://www.mat.ucsb.edu/~whsmith/jool.html . There you
fill find a Codewarrior project for doing C++ in jitter. If you’re
working on Windows, check out the jit.atari2600 posts. Kyle, who
wrote the external, has bee doing C++ in Jitter in Visual Studio. If
you ask, I bet he’ll send you the project and you can use it as a
starting point for doing C++ in Jitter on windows.

wes


February 16, 2006 | 5:34 am

Sounds interesting.

I am working with "to_texture" by the moment, does the "capture" keyword
also copy the current rendered scene in the front buffer into the using
texture or it does other tricks ? It would be great if it can capture an
off-screen buffer.

I have been looking into the documentation and seems there is alot hidden
command I can cast on the jit.gl.sketch object. Anyone know if there is a
compete list of usable commands ?

^_^,
William


Viewing 12 posts - 1 through 12 (of 12 total)