Forums > Beta

erase_color help

October 23, 2011 | 11:53 am

Hello
i love the new max, but I have a problem and it is this
I’m trying to use jit.node with jit.camera and erase_color so the background does not get redraw, i have look at the camera.direct.feedback example but the workaround is not ideal for what i am doing.

here an example of what i mean, any help would be great

best
Ben

– Pasted Max Patch, click to expand. –

October 23, 2011 | 5:59 pm

Here’s a way to get the feedback you’re looking for with nodes and cameras:

When capturing with cameras and nodes, the alpha component doesn’t do the smear-o-vision like it does when rendering to the window. I’ll log this as a feature request. What you can do is use slabs to produce the background trails. You’ll also have more control this way. Here I’ve used jit.gl.slab @co.accum.jxs which simulates jit.gl.render’s erase_color smearing.

– Pasted Max Patch, click to expand. –

October 23, 2011 | 10:19 pm

Yes, I really hope that Cycling will provide an actual replacement for jit.gl.render alpha effects when doing render to texture capturing!

This example, similar to those that have been given at various times on the forum over the years, clearly illustrates the limitations of co.accum.jxs — it is not possible to have a black background because the accumulation color eventually clips at white, even though the erase_color is explicitly set to 0 0 0 .


October 23, 2011 | 10:25 pm

Hi Jesse.

"This example, similar to those that have been given at various times on the forum over the years, clearly illustrates the limitations of co.accum.jxs — it is not possible to have a black background because the accumulation color eventually clips at white, even though the erase_color is explicitly set to 0 0 0 ."

I’m sorry, but I really don’t follow. The accum shader does exactly the same that as render’s erase_color. Do you have a simple patch that shows the limitation you’re talking about?


October 24, 2011 | 12:39 am

Opening the patch you posted on my computer, the background clips to white even though it is explicitly set to black. Looking more closely, this is probably due to the use of co.average.jxs?

Perhaps I’ve not understood something about how to use co.accum.jxs.

I’ve attached a patcher that hopefully illustrates what I’m talking about.
It has two examples, one using the built-in erase_color and one using co.accum.jxs. On my computer, the second window shows the ball clipping to white, while the first window shows the expected behavior.

The capture method relies on jit.gl.sketch, as I’ve not yet spent time looking at the new Max6 methods. Incidentally, in Max6 the first window (alpha1) displays strange motion artifacts. The same patcher in Max5 animates smoothly.

I’m on a new MacBook Pro 17", AMD Radeon HD 6750M 1024 MB.

– Pasted Max Patch, click to expand. –

October 25, 2011 | 5:44 pm

Hi Wesley. Curious if you have any response?


October 25, 2011 | 11:10 pm

thanks for the response-) it is Jesse patch that illustrates the problem perfectly, it the freezing of the background witch i like with erase_color, but i am having fun with co.accum.jxs too now

thanks


October 26, 2011 | 5:47 am

Hi,
thanks for the patch. I see what’s happening. I’ll look into this and get back later. I’ve been preoccupied with dev work, so your recent posts just slipped me by. The motion artifacts you’ve seen in the Beta have been fixed. If you see them for some reason in the release, please let us know.


October 26, 2011 | 7:30 am

ok, so I figured it out. I didn’t quite have the entire drawing/erasing process down correctly in the shader. Fortunately in Max6, jit.gl.texture has an @erase_color attribute, which is needed. To get this all to work, the texture needs to have an alpha of 0 when capturing starts. When you draw, the alpha component is then used to mix the new image with the previous one. If alpha is 1, it fully takes the new image. If 0, it fully takes the previous. This masking effect prevents saturation to white.

– Pasted Max Patch, click to expand. –

And the shader:

Accumulator

fade amount

// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

// accum amount
uniform vec4 erase_color;

void main() {
vec4 current = texture2DRect(tex0, texcoord0);
vec4 previous = texture2DRect(tex1, texcoord1);

previous = mix(previous, erase_color, erase_color.a);
vec4 res = mix(previous, current, current.a);

gl_FragColor = res;
}

]]>


October 26, 2011 | 7:33 am

One more thing, I’ve added this to Max6 as co.accum.erase.jxs. I didn’t want to change co.accum.jxs because it will break existing patches. Besides the name still works. Use accum.erase with a jit.gl.texture @erase_color 0 0 0 0 for capturing to get jit.gl.render style erasure.


October 26, 2011 | 9:14 am

Thanks Wes, this is great. Very cool to see this working!

So in my reading of this, setting jit.gl.texture’s @erase_color to 0 0 0 0 allows the alpha of the incoming captured raster to be passed through? In that case I gather this means that I no longer have to set glclearcolor in jit.gl.sketch?

One possible bug to report: I added a @color control to the patch so I could test the effects of manipulating the gridshape’s alpha. This behaves as expected in the case of the @capture technique running through co.accum.erase.jxs. Interestingly, it does not work in the first case, using a straight ahead jit.gl.render path.

– Pasted Max Patch, click to expand. –

October 26, 2011 | 5:16 pm

It doesn’t work in the patch you just posted because jit.gl.gridshape @blend_enable is 0. The reason it works in the accum.erase shader I posted is that the shader explicitly makes use of the gridshape’s alpha while in your patch, the gl commands that take place ignore it.

Setting jit.gl.textures’s @erase_color will cause the texture to be cleared to that color value when it starts capturing. In the specific case of the patch I posted, a value of 0 is used by the accum.erase shader to pass the previous frame. If your patch as setup differently, something else would happen.


October 28, 2011 | 3:34 pm

thank you!! i can get on converting my patches over now, i am happy about jit.gl.camera!!

thanks Ben


March 27, 2012 | 2:11 pm

Wes,

I’ve read the above several times, yet I’m not grasping how to apply it to a simple processing of two textures via an accum.erase.jxs slab into a videoplane. I have exactly the same construct working with accum.jxs, just not accum.erase.jxs. Please see attached patcher.

Thanks!

Jeff

– Pasted Max Patch, click to expand. –


dtr
June 17, 2014 | 9:12 am

I’ve struggled for a while trying to make this work with jit.gl.node in capture mode. Finally managed. Perhaps it will help someone else.

– Pasted Max Patch, click to expand. –

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