effects - feed result as input?

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Wed Mar 31, 2010 4:25 am

Is it possible to apply a pixel shader to the foreground texture, and then update that result into the foreground texture of the next rendered frame?

Something like the diagram below:


I want to obtain an iterative shader, but I don't know if that is really possible.
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Wed Mar 31, 2010 9:10 am

Try using a Canvas object with a 'grab layout before/after drawing' setting. If you change the opacity and/or apply a shader, you can get a frame feedback effect, where the previously drawn frames are fed back in to the canvas.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Mar 31, 2010 2:15 pm

Thanks, that worked.
*edit:( but unfortunately it doesn't grab the transparency of the layer, something I need.)

Also it's a little annoying have to setup a canvas object every time you want the effect to work, since the shader only gives you any useful result when it's iterative.

isn't possible to obtain this result just through shader code?
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Wed Mar 31, 2010 2:54 pm

No, the previous frame's final render is not available to shaders I'm afraid - that's what the Canvas does, it acts as the surface that stores the previous frame's texture. What do you mean by it doesn't grab the transparency of the layer?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Mar 31, 2010 3:14 pm

let me explain first:
the shader I'm working was designed to be applied to a layer, not individual objects. In the shader's code i have an IF that checks the alpha of the layer's pixel.

If I use a canvas, it seems to grab the entire layout as an image, that means that I can't check for alpha anymore.
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Wed Mar 31, 2010 3:28 pm

Try checking 'Force own texture' on the layer the canvas is on, and make sure the canvas is on top of everything on that layer. Does that help?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Mar 31, 2010 8:20 pm

helps partially. I can now compare the alpha but I cannot set a pixel's alpha.

Actually I made some tests and it seems that with a canvas object I cannot set the pixel's alpha value anymore. If I set it's alpha to 0 it always stays opaque instead of turn transparent.
But if I apply the effect to a layer it turn the pixel transparent as expected.

here the example (construct version 0.99.84):
[url:1e3jyhqd]http://www.prr-art.com/things/shader_test-01.cap[/url:1e3jyhqd]
[url:1e3jyhqd]http://www.prr-art.com/things/sand.fx[/url:1e3jyhqd]
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Fri Apr 02, 2010 12:54 pm

did you try using it as a layer effect on the foreground layer?

NVM: i just looked at your cap
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests