Persona-esque UI effects and wipes

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
RaycatRakittra
Prole
Posts: 22
Joined: Fri Sep 30, 2016 12:40 am
Location: Chicago, IL
Contact:

Persona-esque UI effects and wipes

Post by RaycatRakittra »

Sorry for the large image. I tried to use [spoiler] tags and failed. D:
Image
So, Persona 5 is going in on these color-changing wipes and effects they have on all of their menus. It's a very stylized (and borderline distracting) effect that I was trying to emulate using LÖVE. I apologize in advance; I'm both new, and lacking a .love file. Kinda just spit-balling ideas on this one. After spending some time with the wiki, I thought of a few ways to do this:

1) Use a custom Shader to replace the color with the background or a different color.

2) Make the first draw operation per image a Stencil.

3) BlendMode trickery? (I don't know too much about this.)

I'd like to hear your opinions on this. Is there a faster way? Will doubling my draw ops be inefficient? Mind you, this isn't pre-optimization; I just know if I do this, I'll be using this effect a lot. Thanks and cheers.
Sometimes, I can code things.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Persona-esque UI effects and wipes

Post by raidho36 »

If you want this one specifically, I can see it implemented fairly easily. All layers only use 2 colors and transparency, so first you compose each layer graphics and then you render it onto scene with a color replace shader. Basic stencil effect is achieved via rendering solid color with additive mode over blank canvas. In this particular case, i.e. if there's only two levels of overlap, you can render 50% white solid graphics for each object on the layer. Then shader replace picks the difference between pixel color and pre-defined threshold (50%) and mixes color A and color B by it.

Code: Select all

gl_FragColor = texture2D ( texture, position );
gl_FragColor.rgb = mix ( color1, color2, ( gl_FragColor.r - 0.5f ) * 2.0f ) );
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Persona-esque UI effects and wipes

Post by zorg »

I actually see 3 colours given as a whole (white, blue, black) with various "layers" have either white or blue as a background color, and blue or black as the "overlap" tint.
Speaking of overlap, i'd use 100% and 0% opacity only, and a shader to combine one color with another... or, if this was the 00's, i'd say xor or xor-like blendmode... that isn't accessible from löve sadly... unless using a shader.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
RaycatRakittra
Prole
Posts: 22
Joined: Fri Sep 30, 2016 12:40 am
Location: Chicago, IL
Contact:

Re: Persona-esque UI effects and wipes

Post by RaycatRakittra »

@raidho36, thanks for the quick reply! Trying to build a demo using that right now. :)

@zorg, what do you mean by 'XOR-like blendmode'? Exactly what it says on the tin? If one color, overlap this; else, overlap that?
Sometimes, I can code things.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Persona-esque UI effects and wipes

Post by raidho36 »

XOR is codespeak for "exclusive or". It's a boolean operation, combines regions of both overlapping shapes (OR operation), except the region that directly overlaps. But that's not the case here, since a) boolean operations only work with 2 states but not with 3 much less arbitrarily many, and b) you can see that multiple shapes overlapping result in same color as with only 2 shapes so that's not relevant. It's an additive mode where each pass adds 1 stage of color, clamped to 2 stages, with color replace based on current stage.

To think of it, you could actually do it using XOR operation. You produce a stencil buffer using XOR stencil accumulation mode, starting with blank buffer of course, and then you render everything again, first with background color, then with foreground color with stencil-testing against the buffer. But that no doubt will result in sharp pixellated edges. Also pretty sure only geometry goes to stencil buffer, you can't put a texture to it.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Persona-esque UI effects and wipes

Post by zorg »

I'm pretty sure that stencils are pixel-maps though... they have got nothing to do with vertices, which i assume you mean under "geometry".
And i only brought up the xor thing as an old example, naturally, one should either use stencils (with tinting, perhaps), or shaders.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Persona-esque UI effects and wipes

Post by raidho36 »

No I mean that you can't render a texture to it, and the whole rendered geometry will go in there. But apparently you can do that? And also there's no such thing as XOR stencil mode either. So yeah that not gonna work.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Persona-esque UI effects and wipes

Post by zorg »

Note that i never said there was a xor stencil mode, again, that was an example how some REALLY ANCIENT games could do "stencils". That said, one, a bit more recent, example would be touhou using multiple overlapping and expanding circles when the player character dies on their last life, (if i remember correctly, anyway); the parity of the overlaps determine whether the colors are inverted or not.
Edit: As pgimeno said below, i also never said anything about xor being 1-bit only; one can neatly (bitwise) xor a whole byte as well (as in C for example), and his codeblock demonstrates the result.

Anyway, back to Löve, [wiki]love.graphics.stencil[/wiki] says that it has a "stencilfunction" that draws "geometry". The second example shows how it's possible to use an image (mask) as stencil. it uses love.graphics.draw, which accepts both images and canvases too... so, textures.

But i digress, back to the original question and image, more importantly:
My own naive way would be to have a canvas for all the overlay stuff, define the order of the layers i'd want to draw, then send number triplets to a shader, denoting what color i'd want to change, and to what, based on transparency. E.g. white->blue, white->black, blue->black. Looking at the image, i don't ever see more than two things overlapping though, so at least one doesn't have to set up multiple stages of these.
Last edited by zorg on Sun Oct 02, 2016 5:58 pm, edited 2 times in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3688
Joined: Sun Oct 18, 2015 2:58 pm

Re: Persona-esque UI effects and wipes

Post by pgimeno »

What was XOR in two-color displays is usually extended to 0-255 ranges as absolute value difference:

Code: Select all

 a    b   abs(a-b)
---  ---  --------
 0    0      0
255   0     255
 0   255    255
255  255     0
As for how to do it, I agree that shaders seems like the way to go. And it seems it won't be pretty.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Persona-esque UI effects and wipes

Post by Davidobot »

I don't think you need shaders - you can use LOVE's built-in stencils and it will work pretty well. The only downside to this is that you have to draw your images twice and have a specialised stencil drawing function, but you can definitely make it work.
Attachments
StencilsMan.love
Use "a" and "d" to move image
(19.98 KiB) Downloaded 81 times
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests