Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Multi-pass shader error -- please help
Started by scottabroughton Nov 16 2019 04:16 AM

7 replies to this topic
custom shader
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

scottabroughton

[GLOBAL: userInfoPane.html]
scottabroughton
  • Observer

  • 14 posts
  • Corona SDK

Hello. This is my first time trying to implement two shaders to an object. All I want to do is apply the blur filter and the brightness filter.

 

I followed the tutorial here:

http://www.sdknews.com/cross-platform/corona/tutorial-multi-pass-shaders-in-graphics-2-0

 

Code from main.lua

 

local effect = require( "kernel_filter_myGlow" )
graphics.defineEffect( effect )

 

Code from kernel_filter_myGlow.lua

 

local kernel = {}
kernel.language = "glsl"
kernel.category = "filter"
kernel.name = "myGlow"
kernel.graph =
{
        nodes = {
                blurPass      =       { effect="filter.blur", input1="paint1" },
                brightnessPass        =       { effect="filter.brightness", input1="blurPass" },
        },
        output = "brightnessPass",
}
return kernel

 

Code from level.lua (where the image is displayed)

 

coinGlow[i] = display.newSprite( foregroundGroup, coinSheet, coinSequenceData )
        coinGlow[i]:play()
        coinGlow[i].fill.effect = "filter.myGlow"

 

The object is a sprite, but I've tested the effect on a png with no animation.

 

I get this error: "ERROR: Could not find or load shader (filter.myGlow)."

 

I don't think the error is in the main.lua code. Please help.

 

BTW, I don't know enough to understand Corona's Custom Shader Effects guide here:

https://docs.coronalabs.com/guide/graphics/customEffects.html



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

That looks like a nifty effect if you can get it to work. Unfortunately, that article is from 2013 and all of the links to other examples are dead.  I did notice that you need to add "custom" to your fill.effect.  Maybe that will help.

 

coinGlow[i].fill.effect = "filter.myGlow"
-- should be
coinGlow[i].fill.effect = "filter.custom.myGlow"



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

I was able to get it working using

 "filter.custom.myGlow" 

instead of

 "filter.myGlow" 

 

I wasn't able to get it to work with composite filters yet but I'll keep trying



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

FYI - composites work as well - again using the custom tag

 "composite.custom.myGlow" 



[TOPIC: post.html]
#5

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

I'm having limited success in mixing filter and composite multi-shaders.  This probably has something to do with the kernel.category being set to either composite or filter.



[TOPIC: post.html]
#6

scottabroughton

[GLOBAL: userInfoPane.html]
scottabroughton
  • Observer

  • 14 posts
  • Corona SDK

Thanks for the replies.

 

After posting this, I did some tweeking, and one of them was to add "filters.custom.myGlow". I got it to work. The blur pass is for making it a little bigger than the original image, and the brightness pass is for making the glow white. It might look better if the blur pass came second?

 

If anyone else wants to use this, go for it. Whatever image you want to add a glow to, just create two image objects, with the glow image object behind the real image. Then apply the custom.myGlow filter to the glow image object and a nice glow or halo shows.



[TOPIC: post.html]
#7

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

@scott 

Have you noticed any memory leaks when you change the default filter settings like

object.fill.effect.crystallize.numTiles = 8  -- crystalize being one of the custom nodes

 

I added this to my current custom shader that runs every frame and noticed memory leaks when I change the defaults.  Changing the fill effects of the various nodes every frame for hundreds of objects revealed some significant leaks to me that I didn't notice on a smaller scale.

 

I'm investigating my shader codebase to see if there is something not playing nicely - but I'm also wondering if you have had a similar result when you adjust the multi-shader fill.effects?



[TOPIC: post.html]
#8

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

Never mind, I found the leaks and they were of my own design - I left some garbage around while I was trying to find a hack to get composites and filters to work together. 

 

I'm still trying to find a way to get filters and composites to reliably work together - some filters like "crystalize" and "scatter" work with the composites but most don't.

 

Do any of you OpenGL gurus have suspicions as to why?




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: custom, shader