Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Multiple effects (multi-pass) on snapshot
Started by lukelisi Oct 31 2017 12:38 PM

No replies to this topic
snapshot effects multi-pass
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

lukelisi

[GLOBAL: userInfoPane.html]
lukelisi
  • Observer

  • 1 posts
  • Corona SDK

I'm having an issue where multi-pass effects are only being partially applied to a snapshot.

 

A similar issue was mentioned in an archived post years ago, but still seemingly unanswered.

 

My goal is the apply multiple effects as objects animate. I've managed to get the multi-pass effect to work as intended in one situation but don't understand why it doesn't in another.

 

Attached is a diagram visualizing the various scenarios.

 

Image A: This is a control sample of the graphics as they appear before the effects are applied.

 

Here is the code for my multi-pass effect. It's used in both Image B and Image C:

local effect = {
	language = "glsl",
	category = "filter",
	name = "myEffect",
	graph = 
	{
		nodes = {
			filter1  = { effect = "filter.pixelate",	input1 = "paint1" },
			final	=  { effect = "filter.exposure",	input1 = "filter1" },
		},
		output = "final",
	},
}

---

 

Image B: This is the intended appearance. Here is the code that manages to create it:

local snapshot = display.newSnapshot( 768*2, 1316*2 )
local snapshotGroup = snapshot.group

local background
background = display.newRect( display.contentCenterX, display.contentCenterY, 768, 1316)
background:setFillColor( 20/255, 10/255, 0/255)
background.alpha = .8
snapshotGroup:insert( background )

local options = 
{
	text = "THIS IS JUST A TEST",
	x = 320,
	y = 100,
	width = 0,
	fontSize = 48,			
	align = "left"
}
local variable_text = display.newText( options )
variable_text:setFillColor(255/255,12/255,0/255)
transition.to(variable_text, { time=3000, y=variable_text.y+100, iterations=-1, transition=easing.continuousLoop })
snapshotGroup:insert( variable_text )

-- Update (invalidate) the snapshot each frame
local function onEnterFrame( event )
	snapshot.fill.effect = "filter.custom.myEffect"
	snapshot.fill.effect.filter1.numPixels = 4
	snapshot.fill.effect.final.exposure = 3
        snapshot:invalidate()
end
Runtime:addEventListener( "enterFrame", onEnterFrame )

---

 

Render C: This is the unintended outcome that I'm not understanding. Here is the code:

local snapshot = display.newSnapshot( 768*2, 1316*2 )
local snapshotGroup = snapshot.group

local background
background = display.newRect( display.contentCenterX, display.contentCenterY, 768, 1316)
background:setFillColor( 20/255, 10/255, 0/255 )
background.alpha = .8
snapshotGroup:insert( background )

local options = 
{
	text = "THIS IS JUST A TEST",
	x = 320,
	y = 100,
	width = 0,
	fontSize = 48,
	align = "left"
}
local variable_text = display.newText( options )
variable_text:setFillColor(255/255,12/255,0/255)
transition.to(variable_text, { time=3000, y=variable_text.y+100, iterations=-1, transition=easing.continuousLoop })
snapshotGroup:insert(variable_text)

snapshot.fill.effect = "filter.custom.myEffect"
snapshot.fill.effect.filter1.numPixels = 4
snapshot.fill.effect.final.exposure = 3

-- Update (invalidate) the snapshot each frame
local function onEnterFrame( event )
	snapshot:invalidate()
end
Runtime:addEventListener( "enterFrame", onEnterFrame )

---

 

B and C are nearly identical but when the custom snapshot effect isn't executed within the onEnterFrame function, it loses the pixelate effect but retains the exposure effect. This is what I'm not understanding.

 

Is there anything that I'm overlooking or is this a non-issue since B works as intended? I'm just wondering if there are underlying performance consequences at hand.

 

I'll caveat this by saying that I am at best, a novice in Corona. I'm partnered with a developer that does 99.9% of the code — but being the obsessive designer that I am — I like to get into the code to tweak and enhance graphics. My code is probably inefficient, kludgy and otherwise cringe-worthy, however, I'm just trying to understand the concept.

 

Hopefully, I've provided sufficient information to troubleshoot. Thanks in advance for any help.

 

---

Attached Files




[topic_controls]
[/topic_controls]