Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: zpaolo11x on January 20, 2019, 08:37:54 AM

Title: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 20, 2019, 08:37:54 AM
I've put together a simple layout to demonstrate my drop shadow code, here it works for wheel art but you can use it on any image. I'm not a good programmer but I'm sure someone might like the code and maybe build something useful with that (a class?) so that it can be used and re-used.

The parameters to play with to define the shadow are in the code, they are self explanatory except from shadow_downsample, this is a float parameter < 1.0 so that the shadow surface is built smaller than the original image and then enlarged. Since the shadow is smooth you won't loose detail and gain speed because the shader will be faster on a smaller image.

Have fun!
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: jedione on January 20, 2019, 08:41:09 AM
thankyou....now paying with... ;D
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: jedione on January 20, 2019, 09:13:30 AM
just tryed to cram this code in to the shuffle module,  would be cool..

to no avail...
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 20, 2019, 09:16:31 AM
just tryed to cram this code in to the shuffle module,  would be cool..

to no avail...

LOL don't ask me, it was hard enough to untangle this code from my own Arcadeflow layout :D I promise I'll take a look at how to code classes and all this cool stuff as soon as possible
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: keilmillerjr on January 20, 2019, 09:35:35 AM
Thank you @zapaolo! Will update shader module tonight with this. Working on compiling mame within a virtual console and it’s eating up my resources and even crashed my computer.

@jedione As far as integrating it with shuffle - I assume it would be the no different than styling existing objects. Assume. I could be wrong. Let me add this to the module tonight and then send me what your working on.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: jedione on January 20, 2019, 09:36:37 AM
thanks...alot...
btw does this work text...did not for me.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: jedione on January 20, 2019, 09:39:07 AM
ok in a bit ill send you the shuffle that i have made with animation... ;D ;D ;D ;D
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: keilmillerjr on January 20, 2019, 09:44:04 AM
thanks...alot...
btw does this work text...did not for me.

According to the docs, shader isn’t available for text. It is available for image and surface. I don’t see why you couldn’t place text on a surface and then duplicate the surface for the shadow.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 20, 2019, 09:51:16 AM
thanks...alot...
btw does this work text...did not for me.

According to the docs, shader isn’t available for text. It is available for image and surface. I don’t see why you couldn’t place text on a surface and then duplicate the surface for the shadow.

It can work for text, I use it for drop shadows exactly as you say, putting text on the first surface and applying shader to that surface. I'll check tomorrow and post an update :)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: keilmillerjr on January 20, 2019, 09:55:14 AM
Exactly. Not available directly on text object, but available to surface that can contain objects including text. :)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 20, 2019, 10:01:58 AM
Exactly. Not available directly on text object, but available to surface that can contain objects including text. :)

The problem is that the code does a clone of the artwork to place it in the surface to be shaded, but you can't clone a text object. In my layout I don't need safeguard areas so I just place text on a surface, and clone that surface inside a second surface, and then apply the shaders. This works but shadow is cut when the surface ends. I'll see if I can come up with some clever trick
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 20, 2019, 10:05:24 AM
For text you can do like this: instead of creating a picture called pic0, create a surface and place text on the surface:

local pic0 = fe.add_surface(400,200)
local t0 = pic0.add_text("[Title]",0,0,400,100)

Actually whatever you add to that surface will be "dropshadowed" :D
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 20, 2019, 12:20:50 PM
Looking forward to poking around in this! (Sorry for the banal comment: seems AM forums' don't have a means of bookmarking threads?)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: FrizzleFried on January 20, 2019, 01:08:46 PM
Looking forward to poking around in this! (Sorry for the banal comment: seems AM forums' don't have a means of bookmarking threads?)

NOTIFY button at top right does this.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: calle81 on January 20, 2019, 02:48:24 PM
Would be cool if you could also show how to do a white glow behind wheel art :)

This together with the conveyor module would be gold!  :)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 20, 2019, 03:03:03 PM
Would be cool if you could also show how to do a white glow behind wheel art :)

This together with the conveyor module would be gold!  :)

I think if you change his set_rgb() call to set_rgb(255, 255, 255) and change the offsets for x and y to 0, you can get something like that. Maybe even set the blend_mode to BlendMode.Screen.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 20, 2019, 08:10:20 PM
All right, @zpaolo11x, I took your code and wrapped it in a class (attached). It works for me...the typical way it should, I think, but in the grander scheme of things, it doesn't work for my purposes! I think it has to do with how the first image (a video in my case) doesn't come up on layout start: you have to navigate through the list to trigger things. I think if I can solve this issue (which I still have no idea how to do!), I'd be good to go.

For those with less ridiculous layouts than me, here's how to instantiate the wrapped drop-shadow (there's better "documentation" in the .nut):

Code: [Select]
fe.do_nut( "drop-shadow.nut" );

local myPic = fe.add_artwork( "snap", 100, 100 ); // Arbitrary placement

local myPicDS = DropShadow( myPic, 25, 0, 10, 153 ); // Shadowed object, blur size, x-offset, y-offset, alpha (0~255)

You'll need zpaolo11x's gauss_kernsigma_o.glsl file for any of this to work!

If anyone has any idea why my layout isn't showing a snap when it first loads, I'm all ears! Thanks!
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 21, 2019, 01:15:24 AM
Would be cool if you could also show how to do a white glow behind wheel art :)

This together with the conveyor module would be gold!  :)

I think if you change his set_rgb() call to set_rgb(255, 255, 255) and change the offsets for x and y to 0, you can get something like that. Maybe even set the blend_mode to BlendMode.Screen.

If you do like that you get a sort of "ambi-light" effect where the glow is the same color as the picture, but if your picture is dark, you'll get a dark glow, which is not very nice. The best way to solve the issue is to add a shader to pic1 and change there the color, I'm working on it right now so you can choose the exact color of the shadow :)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 21, 2019, 02:12:36 AM
Changed it a bit so you can actually chose the color of the shadow, and with a white shadow it looks like a glow.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 21, 2019, 02:27:21 AM
All right, @zpaolo11x, I took your code and wrapped it in a class (attached). It works for me...the typical way it should, I think, but in the grander scheme of things, it doesn't work for my purposes! I think it has to do with how the first image (a video in my case) doesn't come up on layout start: you have to navigate through the list to trigger things. I think if I can solve this issue (which I still have no idea how to do!), I'd be good to go.

Yep, I saw your code and here is what to change: in the resizeVideoBox function, add this to the case statement:

Code: [Select]
case Transition.ToNewList:
because you have put there Transition.StartLayout but when StartLayout is triggered there's no artwork yet on the layout. "ToNewList" will solve your issue
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 21, 2019, 06:59:24 AM
All right, @zpaolo11x, I took your code and wrapped it in a class (attached).

I see in the code that the _parent only works if it's set to fe, this is expected because of the way the original drop shadow layout was created. Things are a bit complicated: to avoid frame delays the two surfaces _surfA and _surfB must always be created on the fe, then stacked and repositioned using a "reshuffling" code based on self clones. If you want to place everything on another surface (or better, if the item you want to add drop shadows is on a surface itself, which is probably the "_parent") you should create _surfA and _surfB on fe, then once you have done the "reshuffling":

Code: [Select]
        _surfA.visible = false;
        _surfA = _surfB.add_clone( _surfA );
        _surfA.visible = true;

you should do another suffling like this:


Code: [Select]
        _surfB.visible = false;
        _surfB = _parent.add_clone( _surfB );
        _surfB.visible = true;

This SHOULD work, and place the whole shadow stack on the proper level. But bear in mind this is probably going to break the zorder trick :D
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 21, 2019, 07:05:16 AM
Thanks for the elucidation. Squirrel's display stack is different from what I'm used to (from a prior life). When I have an opportunity, I'll see if I can convince it to work on an arbitrary surface.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 21, 2019, 10:28:16 PM
A simple variation of the previous layout tuned to obtain an "ambilight" effect... now the black shadow is not present and the luminosity is boosted... The perfect evolution would be that parts of the image with black color would bleed white light, but if you want to obtain a "old CRT halo in night room" effect instead of a "modern TV backlighting ambient light" effect this is perfect :D
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: dukpoki on January 26, 2019, 10:28:29 AM
As always thanks Z.  By any chance you can do one for texts?  :)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: calle81 on January 26, 2019, 11:00:01 AM
Awesome stuff zpaolo11x! Can you add the latest updates into the class that Bgoulette wrote? :P
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 26, 2019, 12:27:02 PM
As always thanks Z.  By any chance you can do one for texts?  :)

Sure, I already have the code, just let me clean it up a bit
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 26, 2019, 04:11:24 PM
Awesome stuff zpaolo11x! Can you add the latest updates into the class that Bgoulette wrote? :P

I'm attaching a new module that incorporates the ambilight plus flatcolor stuff. Warning: somehow, I ruined how the drop shadow works, because now it doesn't! Uggh! Gonna have to go back to zpaolo11x's original and see what I did wrong. Unless someone else can spot it more quickly than I. Been looking at it for too long! :(

Just include fe.load_module("shadow-glow") in your layouts (after placing the contents of the attached zip in your modules folder!), then call 'em like this:

Code: [Select]
// Drop shadow:
local ds = DropShadow( pic, radius, offset_x, offset_y, alpha ) // Broken for now. Grr! Also, alpha is insane...

// Flat color:
local fc = FlatColor( pic, radius, offset_x, offset_y, alpha )
fc.set_fc_rgb( r, g, b );

// Ambi-glow:
local ag = AmbiGlow( pic, radius, offset_x, offset_y, alpha ) // I renamed it AmbiGlow. Sorry!

The included layout-shadow-glow.zip had examples. There's no config, so to change what displays, open the layout.nut and change the "show" value to 1, 2, or 3.

You have no idea how much it's bugging me that DropShadow doesn't work anymore! Why?! It's the same code! Arglebarglesnarflarfglubbernugz...
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 28, 2019, 06:26:58 AM
I looked a little more closely at the actual shaders zpaolo11x used for his effects and discovered differences in how the alpha was applied with his background glow versus his drop shadow. I've made what I believe to be the requisite changes in the shader-glow module, and I think DropShadow should work like it used to. I'd check first, but I can't, because I'm at work on a machine without AM installed. I'll check when I get home, though!

Usage should be the same as above: the change(s) are minor and should be transparent to the user. Just update modules/shader-glow with the attached code (delete the old code first).

Edit: zip moved to this post (http://forum.attractmode.org/index.php?topic=2725.msg19030#msg19030).
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 28, 2019, 08:40:45 AM
I looked a little more closely at the actual shaders zpaolo11x used for his effects and discovered differences in how the alpha was applied with his background glow versus his drop shadow.

Ops, sorry I forgot to rename the shader to stress the difference :D It's the way alpha channel is recalculated which is more fit for glow effects.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 28, 2019, 09:02:20 AM
Ops, sorry I forgot to rename the shader to stress the difference :D It's the way alpha channel is recalculated which is more fit for glow effects.

Ha! Not your fault. I shouldn't have assumed! In the zip I posted above, I renamed the glsl files: gauss_kernsigma_ds.glsl for the drop shadow, and gauss_kernsigma_ag.glsl for the ambient glow (or flat color glow) effect.

I'm looking forward to testing them out tonight when I get home! Thanks for making your stuff available to the masses! It's my hope that my module-ized files will be of benefit to others as well.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: calle81 on January 28, 2019, 09:12:46 AM
I have no clue how this works so excuse the probably stupid question. Performance wise. When adding a drop shadow to a video snap, does that mean i play two videos at the same time just for the dropshadow or is the dropshadow a "static" image?
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 28, 2019, 02:49:14 PM
Just noticed something. Probably not specific to the classes I've added to this thread (but maybe?), but it seems the undocumented (?) fe.module_dir variable returns the path of the last loaded module! Attempting to set it internally doesn't seem to make a difference, though I could be doing it wrong.

Wanted to put this out there in case anyone else a) runs into the issue I did, or b) knows a better workaround than just moving your next fe.load_module() call further down in your code!
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: keilmillerjr on January 28, 2019, 02:59:44 PM
Just noticed something. Probably not specific to the classes I've added to this thread (but maybe?), but it seems the undocumented (?) fe.module_dir variable returns the path of the last loaded module! Attempting to set it internally doesn't seem to make a difference, though I could be doing it wrong.

Wanted to put this out there in case anyone else a) runs into the issue I did, or b) knows a better workaround than just moving your next fe.load_module() call further down in your code!

Yes. If you need access to that path outside the scope of that file, store it in another variable. That’s how on my shader module I make the path available from any scope.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 29, 2019, 01:15:52 AM
I have no clue how this works so excuse the probably stupid question. Performance wise. When adding a drop shadow to a video snap, does that mean i play two videos at the same time just for the dropshadow or is the dropshadow a "static" image?

The drop shadow is not a static image, but it's a clone of the original image that is then blurred and turned black. So you are not actually "playing" two videos, but cloning the texture where the video is displayed and this should have not a great impact. Performance wise adding the drop shadows has some impact because there is a nested surface stack and the shader has to do texture fetches and computation.
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 29, 2019, 03:12:24 AM
One last (?!) iteration of the shader-glow module, based wholly on zpaolo11x's drop shadow and ambient glow shaders and code:
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: dukpoki on January 29, 2019, 11:01:51 AM
One last (?!) iteration of the shader-glow module, based wholly on zpaolo11x's drop shadow and ambient glow shaders and code:

Bgoulette, we need to rename "module.nut" to "drop-shadow.nut" right?  And then place all of those files (1 nut file + 3 glsl files) into "attract/modules/"?  I did that and added these 2 lines into my existing layout and i'm not getting anything.

Code: [Select]
fe.do_nut( "drop-shadow.nut" );

local ds = DropShadow( "snap", 10, 100, 100, 10 );


I've also tried dropping those glsl files into the layout folder but no dice.  I feel like i'm missing something very obvious.  Lol


Title: Re: Drop shadow layout, may be turned into something useful?
Post by: Bgoulette on January 29, 2019, 11:16:43 AM
All you should have to do is unzip the archive in your modules folder (attract/modules/shadow-glow). Nothing needs to be renamed. In fact, renaming anything will probably break things!

Once that's done, in your layout, before you want to apply the drop shadow, use this line: fe.load_module("shadow-glow")

Once those things are done, you'll need to create an instance of your snap first, then apply the drop shadow, maybe something like this:

Code: [Select]
// Load module so we can instantiate DropShadow:
fe.load_module("shadow-glow")

// Create a quick and dirty background (drop shadow won't show up against black!):
local bg = fe.add_text("", 0, 0, fe.layout.width, fe.layout.height);
bg.set_rgb(127, 127, 127);

// Create our artwork and apply a drop shadow to it:
local mySnap = fe.add_artwork("snap", 0, 0, 320, 240)
local myDropShadow = DropShadow(mySnap, 50, 10, 10, 153)

// If we want something other than pure black, we can tweak the drop shadow color:
myDropShadow.set_ds_rgb(0, 0, 51);

The values in that example are arbitrary, but should give you an idea of what's going on. Let me know if that doesn't work. I assume you're using the most recent files (from the post you quoted)? The others had some flaws!

(Edited to include comments and stuff.)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: dukpoki on January 29, 2019, 09:18:55 PM
@Bgoulette

Thanks.  Works perfectly now!
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: jedione on January 29, 2019, 10:19:49 PM
cant seem to get text shadow with the module...
any help ;)
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on January 30, 2019, 01:13:46 AM
cant seem to get text shadow with the module...
any help ;)

I can't check it right now but you can try adding the text to a surface, then applying the shadow to that surface. That way it should work, I had issues using text objects directly but through a surface it should work with little or no overhead
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: qqplayer on May 06, 2019, 08:39:22 AM
Anyone is having msvcrt.dll and ntdll.dll errors randomly using tis drop shadow feature.
I made som changes to the hyperpie layout from carls and when I move inside my gamelist, attract mode crashes and is returning me those two dll errors.
Tested on three diferent computers with w8.1 and attrackt 2.5.1
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: arthurvalenca on May 01, 2020, 04:58:36 PM
A simple variation of the previous layout tuned to obtain an "ambilight" effect... now the black shadow is not present and the luminosity is boosted... The perfect evolution would be that parts of the image with black color would bleed white light, but if you want to obtain a "old CRT halo in night room" effect instead of a "modern TV backlighting ambient light" effect this is perfect :D

hello Paolo, could you help me with this code that you provided? i don't get the snap image just a black screen something has to be modified to work?
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on May 04, 2020, 01:05:56 AM
hello Paolo, could you help me with this code that you provided? i don't get the snap image just a black screen something has to be modified to work?

I checked that layout and I get a black screen too... let me do some checks, it's a pretty old code and probably something needs to be changed...
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: zpaolo11x on May 04, 2020, 01:26:03 AM
hello Paolo, could you help me with this code that you provided? i don't get the snap image just a black screen something has to be modified to work?

There's a line in the code:

Code: [Select]
pic0.video_flags = Vid.ImagesOnly
so if you don't have static snaps but only videos you won't see anything. I think if you remove that line it will work for videos too, or you'll have to add snaps to your artworks
Title: Re: Drop shadow layout, may be turned into something useful?
Post by: arthurvalenca on May 05, 2020, 11:34:08 AM
hello Paolo, could you help me with this code that you provided? i don't get the snap image just a black screen something has to be modified to work?

There's a line in the code:

Code: [Select]
pic0.video_flags = Vid.ImagesOnly
so if you don't have static snaps but only videos you won't see anything. I think if you remove that line it will work for videos too, or you'll have to add snaps to your artworks

Thanks Paolo solve my problem.