Render-to-texture question (yes, another one!)

Tarik's icon

Dear Jitter people,

When rendering, I'm sending out lots of bangs to lots of jit.gl objects which get rendered on screen. Brilliant. But now I want to add some post processing effects over the end result, using shaders. How do I get the total rendered scene into a texture for further processing?
The @capture attribute doesn't suffice for this case because this will only render single jit.gl objects to a texture, while I want the whole rendered scene.
I'd love to use some kind of glreadpixels command for jit.gl.sketch, but one which works with textures in stead of matrices.

Any clues?

Thanks

Jesse's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I recently made this patch for a friend -- it's a simple example that uses color to demystify the flow a bit. Basically you need to use jit.gl.sketch, setting the @capture attribute, and specifying draw order of your client jit.gl objects with the drawobject message.

Jesse's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Slight edit with @transform_reset set properly on final videoplane.

Tarik's icon

Precisely! That is exactly what I needed. And I think I just proved to the world that I'm not such a good forum-searcher.

...now I know how it's done I can easily find the other examples on the list. But for some reason I found this initially very difficult to find. Anyway, I'll tag this post and try to make this elegant example easy to find.

Cheers!

Tarik's icon

Back again!

So, next problem: my patch has only 2 jit.gl.gridshape objects, but I use each of them as if they were multiple gl objects, with @automatic set to 0.
With every frame I send them many parameters, attach various shaders and bang them multiple times to draw the shapes multiple times on screen.

This does not work with jit.gl.sketch since, on banging it, it shall only draw the shape once, and with the last set of parameters and the last shader that I sent to it.

Basically what I want is quite simple: to copy my fully rendered scene onto a texture. But it seems the solution is anything but simple... 3 questions:

1. Is there an equivalent of 'banging' a jit.gl shape to a jit.gl.sketch (or a texture) like I would bang it to a regular render context?
By this I mean that I'd like jit.gl.sketch to execute drawing of an object (like with "drawobject "), but waiting with sending the end result to the texture (as defined by @capture), until I tell it to.

2. I also see that the jit.gl.texture object may receive begin_capture and an end_capture commands. Perhaps this could be an answer to my problem? If so, can anybody explain me how to use these, cause I can't seem to figure this out.

3. One other solution could be sending all of the parameters formerly sent to the gridshape objects, directly to jit.gl.sketch. But how would I then switch shaders within one rendering of jit.gl.sketch, like I currently do between the multiple 'bangs' of a single gridshape?

Thanks to anyone taking the trouble to think about this!!

Rob Ramirez's icon

although you should be able to do what you want with sketch messages, in this case you might want to try instead the to_texture message to gl.render.
bascially, erase the context, bang all your objects to draw, capture the scene to a texture with to_texture, bang the texture, bang the videoplane, than send the final bang to render.

Max Patch
Copy patch and select New From Clipboard in Max.

this patch should demonstrate:

Tarik's icon

Again, a strange mixture of embarrassment (because yes, it is that easy..!), happiness and gratitude. This works very nicely. Great example.

TremensS's icon

Hey guys,

I just came across this thread and Robert's nice patch about using "to_texture".
I'm facing problems in a current project with one frame delays in my rendering chain using to_texture, and when going back to Rob's patch I noticed there was actually the same.

Basically, if you cut the metro and do it manually, you have to bang the rendering trigger twice to make appear a rotation from the handle on the window.

Attached is the patch with basic directions to reproduce.

Is it the normal behaviour (and/or drawback?) of using to_texture? or is there a way to fix that?

Curious to hear about your thoughts/knowledge on this.

Cheers!
T

Max Patch
Copy patch and select New From Clipboard in Max.

(I'm on a 10.6.8 i7 Mac, in case you cannot reproduce)