Multi-pass shader effects (virtually unlimited effects!)

I thought it would be useful to surface the recent blog post we published on multi-pass shaders. In the blog post we cover how to define a chain of shaders to apply to display objects.
 
The post: http://www.coronalabs.com/blog/2013/10/17/tutorial-multi-pass-shaders-in-graphics-2-0/
 
The sample code: https://bitbucket.org/coronalabs/tachyon-samples/src/f954e168fb1ea06dcf058a2b407c16b301d08f63/FilterGraphDemo?at=default
 
A snippet of code to show how the blurGaussian filter works.
 
[lua]
local kernel = {}
kernel.category = “filter”
kernel.name = “exampleBlurGaussian”
kernel.graph = 
{
        nodes = {
                horizontal      =       { effect=“filter.blurHorizontal”, input1=“paint1” },
                vertical        =       { effect=“filter.blurVertical”, input1=“horizontal” },
        },
        output = “vertical”,
}
return kernel
[/lua]

The only problem is finding the time to play with all these goodies :slight_smile:

Yeah but this feature really kick ass. 

The only problem is finding the time to play with all these goodies :slight_smile:

Yeah but this feature really kick ass. 

Is there a way to specify own effects using GLSL or HLSL ?

Still needs more inputs and options :slight_smile:

I did try this a while back but it didn’t work (I *think* I filed a bug report - not sure).

Guys, is this working now?  I get a strange error message when i run this exact code.  

@paolo  This feature has been working for some time - what is the error you’re seeing?

Brian, the error turns out to be in my hurry to get it up and running.  I forgot to write “return kernel” and could not make sense of the error.  Double checking your tutorial it is probably missing from there as well (although it is rather obvious that you need to return kernel and I should have spotted it myself):

https://coronalabs.com/blog/2013/10/17/tutorial-multi-pass-shaders-in-graphics-2-0/

I did verify it’s in the sample code, but we will add it into the blog post per your suggestion!  Thanks.

Bryan, I will expose myself to a second dumb of the week prize here, with two related questions.

(1) - Is there a way to use a display object as input1 (and input2) for filters?  More generally.  Using files is not necessarily a good idea in apps where I may want to use the output from a filter into another filter (or an output from the user).  Say that the user wants to modify a foto before saving (i.e. apply an unknown sequence of filters or edit the photo in other ways).

(2) - I want to overlap a 0.5 transparent photo onto a filtered version of itself and combine them into one (and filter the output again and again with non-composite standard filters).  Workflow: filter input1 several times, make input2 semitransparent (although matrix transformation does not seem to adjust alpha properly), overlap the results, merge into one photo.  It is not clear to me how a multi pass shader combines the two pictures.  Incidentally, the matrix filter does not seem to control transparency the way I would expect (i.e. is I set 0.5 as a lower right corner value I do not seem to get a 0.5 alpha object).  In other words I am trying to a achieve a high pass filtering.

Thanks in advance for your suggestions.

@paolo

You can’t directly use a display object as two different inputs to a filter.  You could potentially use a snapshot object to render a display object into it, then apply a filter, save that, apply a filter etc…   However, based on what I think you are interested in doing it may be similar to what we do in the bloom filter for example, which is in itself a multipass shader, it applies a levels pass filter, a blur filter, and combines the two together using the composite filter.

Is there a way to specify own effects using GLSL or HLSL ?

Still needs more inputs and options :slight_smile:

I did try this a while back but it didn’t work (I *think* I filed a bug report - not sure).

Guys, is this working now?  I get a strange error message when i run this exact code.  

@paolo  This feature has been working for some time - what is the error you’re seeing?

Brian, the error turns out to be in my hurry to get it up and running.  I forgot to write “return kernel” and could not make sense of the error.  Double checking your tutorial it is probably missing from there as well (although it is rather obvious that you need to return kernel and I should have spotted it myself):

https://coronalabs.com/blog/2013/10/17/tutorial-multi-pass-shaders-in-graphics-2-0/

I did verify it’s in the sample code, but we will add it into the blog post per your suggestion!  Thanks.

Bryan, I will expose myself to a second dumb of the week prize here, with two related questions.

(1) - Is there a way to use a display object as input1 (and input2) for filters?  More generally.  Using files is not necessarily a good idea in apps where I may want to use the output from a filter into another filter (or an output from the user).  Say that the user wants to modify a foto before saving (i.e. apply an unknown sequence of filters or edit the photo in other ways).

(2) - I want to overlap a 0.5 transparent photo onto a filtered version of itself and combine them into one (and filter the output again and again with non-composite standard filters).  Workflow: filter input1 several times, make input2 semitransparent (although matrix transformation does not seem to adjust alpha properly), overlap the results, merge into one photo.  It is not clear to me how a multi pass shader combines the two pictures.  Incidentally, the matrix filter does not seem to control transparency the way I would expect (i.e. is I set 0.5 as a lower right corner value I do not seem to get a 0.5 alpha object).  In other words I am trying to a achieve a high pass filtering.

Thanks in advance for your suggestions.