snapshot:invalidate() ignores horizontal blur?

I’m struggling with applying a blur effect on a snapshot. I’ve got a multiple moving items that are inserted into a snapshot. Blur is applied to it and then gets updated at each frame so that those items can be seen moving.

But here’s the issue: as soon as I invalidate the snapshot, it ignores the horizontal blur and only applies the vertical one.

Here’s a simplified code so you can reproduce it:

	-- Loading the image
	image = display.newRect(0,0,50,50)

	-- Creating the snapshot
	snapshot = display.newSnapshot(display.contentWidth, display.contentHeight)
	snapshot.group:insert(image)

	-- Applying the blurGaussion effect
	snapshot.fill.effect = "filter.blurGaussian"

	-- Unblur transition
	local testA, testB
	function unblur()
		print("unblur")
		snapshot.transitionA = transition.to(snapshot.fill.effect.horizontal, {time=2500, blurSize=8, sigma=8, onComplete=blur})
		snapshot.transitionB = transition.to(snapshot.fill.effect.vertical, {time=2500, blurSize=8, sigma=8})
	end

	-- Blur transition
	function blur()
		print("blur")
		snapshot.transitionA = transition.to(snapshot.fill.effect.horizontal, {time=2500, blurSize=128, sigma=512, onComplete=unblur})
		snapshot.transitionB = transition.to(snapshot.fill.effect.vertical, {time=2500, blurSize=128, sigma=512})
	end
	-- Starts the blur/unblur loop transition
	blur()
	
	-- invalidate
	function invalidateSnapshot()

		print("invalidateSnapshot() - h : " .. math.floor(snapshot.fill.effect.horizontal.blurSize) .. " - " .. math.floor(snapshot.fill.effect.horizontal.sigma) .. " - v : " .. math.floor(snapshot.fill.effect.vertical.blurSize) .. " - " .. math.floor(snapshot.fill.effect.vertical.sigma))
		snapshot:invalidate()

	end
	Runtime:addEventListener("enterFrame",invalidateSnapshot)

If the line “snapshot:invalidate()” is disabled, horizontal and vertical visual blur are properly applied. Once it’s enabled, only the vertical visual blur seems to be applied.

I’ve also made an other test, trying to see if the way I was applying the updated blur value were part of the issue:

After applying the blur effect, I’m initializing values that will be used to apply the blur effect:

	-- Applying the blurGaussion effect
	snapshot.fill.effect = "filter.blurGaussian"
	snapshot.hBlurSize = 0
	snapshot.hSigma = 0
	snapshot.vBlurSize = 0
	snapshot.vSigma = 0

The blur/unblur function now do the transition on those values instead of changing the blur values directly:

	-- Unblur transition
	local testA, testB
	function unblur()
		print("unblur")
		snapshot.transitionA = transition.to(snapshot, {time=2500, hBlurSize=8, hSigma=8, onComplete=blur})
		snapshot.transitionB = transition.to(snapshot, {time=2500, vBlurSize=8, vSigma=8})
	end

	-- Blur transition
	function blur()
		print("blur")
		snapshot.transitionA = transition.to(snapshot, {time=2500, hBlurSize=128, hSigma=512, onComplete=unblur})
		snapshot.transitionB = transition.to(snapshot, {time=2500, vBlurSize=128, vSigma=512})
	end
	-- Starts the blur/unblur loop transition
	blur()

And then, it’s only once I call the invalidateSnapshot() that I actually apply those values to the actual blur values.

	-- invalidate
	function invalidateSnapshot()

		print("invalidateSnapshot() - h : " .. math.floor(snapshot.hBlurSize) .. " - " .. math.floor(snapshot.hSigma) .. " - v : " .. math.floor(snapshot.vBlurSize) .. " - " .. math.floor(snapshot.vBlurSize))
		snapshot.fill.effect.horizontal.blurSize = snapshot.hBlurSize
		snapshot.fill.effect.horizontal.sigma = snapshot.hSigma
		snapshot.fill.effect.vertical.blurSize = snapshot.vBlurSize
		snapshot.fill.effect.vertical.sigma = snapshot.vBlurSize
		snapshot:invalidate()

	end
	Runtime:addEventListener("enterFrame",invalidateSnapshot)

It behaves exactly like the previous code: only the vertical blur seems to be taken in account. Commenting the “vertical” lines disables the vertical blur. Horizontal doesn’t seem to have any effect.

Not sure why but it seems like snapshot:invalidate ignores horizontalBlur.

You can see the final output of Gaussian blur is Vertical.

I usually use this render module for post-processing effects.

It’s very easy to setup, just require it and change the shaders inside it.

setup was very quick.


It works fine in your case.

Kinda reassured by your reply to be honest: I thought i was going crazy with this bug.

The link you provided for the render module doesn’t seem to work or is missing though.

Once again thank you for your replies and your time! :slight_smile:

ex.zip (72.1 KB)
I send you a sample, of course you need to modify it to suit your project.

Thank you so much!

image
This block code no need

Just for test, need to change like this:
image