problem with filter.invert and snapShot

Hi!

The code below works because the filter effect used is “filter.hue”
if you replace “filter.hue” by “filter.invert” it does not draw anything !!!

if ( system.getInfo( "gpuSupportsHighPrecisionFragmentShaders" ) ) then
    print('HighPrecisionFragmentShaders')
end

local snapshot = display.newSnapshot( 200, 200 )

object = display.newCircle(100, 100, 100 )
object.xScale = 10
object.yScale = 10
object.fill.effect = "generator.sunbeams"
object.fill.effect.posX = 0.5
object.fill.effect.posY = 0.5
object.fill.effect.aspectRatio = 1
object.fill.effect.seed = 1
snapshot.group:insert( object )

snapshot.fill.effect = "filter.hue"
snapshot.fill.effect.angle = 200
snapshot.fill.effect.numTiles = 32
snapshot.x = display.contentCenterX
snapshot.y = display.contentCenterY

transition.to( snapshot, { time=1000, rotation=250} )

Need Help !

1 Like

This is likely an issue caused simply by how the invert filter works.

For instance, if we modify your code a bit:

local snapshot = display.newSnapshot( 200, 200 )

object = display.newRect( 0, 0, 256, 256 )
object.fill.effect = "generator.checkerboard"
object.fill.effect.color1 = { 0, 1, 1, 1 }
object.fill.effect.color2 = { 1, 0, 1, 1 }
object.fill.effect.xStep = 8
object.fill.effect.yStep = 8
snapshot.group:insert( object )

snapshot.fill.effect = "filter.invert"
snapshot.x = display.contentCenterX
snapshot.y = display.contentCenterY

Then we can see that the invert filter is indeed working. The teal and pink checkerboard turns to red and green.

I don’t know how the filter works, but it does work. Maybe if there were adjustable properties, the strength of the filter could be changed, but now it just goes all out on whatever it does.

If you run your original code and just set the background to red, i.e. display.setDefault( "background", 1, 0, 0 ) then you’ll get:

image

Which seems like the filter has just turned it all to black and there are some alpha variances, so it doesn’t show at all against the black background.

1 Like

Ok.

So… The filter.invert works but do not invert the picture color as it should :crazy_face:

A better method of achieving this

local texture = graphics.newTexture({ type="canvas", width=400, height=400 })

local object = display.newRect(0, 0, 400, 400 )
object:setFillColor( 1, 0, 0 )
texture:draw( object )
local object = display.newCircle(200, 200, 200 )
object.fill.effect = "generator.sunbeams"
texture:draw( object )
texture:invalidate()

local image = display.newImageRect(texture.filename, texture.baseDir, 400, 400)
image.fill.effect = "filter.invert"  -- toggle this

And you can see it performs perfectly and inverts the picture as it should (From Red/white to blue/black).

Yes :muscle:

This time it’s works !
Thank you SGS !

This code works too now

local snapshot = display.newSnapshot( 400, 400 )
local object = display.newRect(0, 0, 400, 400 )
object:setFillColor( 0, 0, 0 )
snapshot.group:insert( object )

object = display.newCircle(100, 100, 100 )
object.xScale = 10
object.yScale = 10
object.fill.effect = "generator.sunbeams"
object.fill.effect.posX = 0.5
object.fill.effect.posY = 0.5
object.fill.effect.aspectRatio = 1
object.fill.effect.seed = 1
object.alpha = 1
snapshot.group:insert( object )

snapshot.fill.effect = "filter.invert"
snapshot.fill.effect.angle = 200
snapshot.fill.effect.numTiles = 32
snapshot.alpha = 1
snapshot.x = display.contentCenterX
snapshot.y = display.contentCenterY
transition.to( snapshot, { time=2500, rotation=250} )

The difference is due to

local object = display.newRect(0, 0, 400, 400 )
object:setFillColor( 0, 0, 0 )
snapshot.group:insert( object )

In your code SGS or in this code, set the background make the difference !
The reason is probably that generator.sunbeams generate alpha value and filter.invert keep those values !

So. ok, it makes sense in the end!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.