Jump to content



Photo
- - - - -

Alternative Alpha Ramp Scripting for Plunger/Lights/etc.


  • Please log in to reply
32 replies to this topic

#1 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 06 July 2012 - 05:52 PM

Most table authors know that adding alpha ramps to a table incurs a performance penalty, and while just a couple here and there is usually no big deal, after adding many of them, another 12(ish) for the plunger animation just exacerbates the problem... which is where this new scripting comes in. Instead of the performance hit for adding 12 alpha ramps, it reduces the hit as if you were just adding 1 additional ramp...

The great thing is, this can be adapted to any lights or other animation that was created using alpha ramps, as it will reduce the performance hit to only the amount of ramps showing at any one time instead of all of the ramps included in the light/animation. As it is now, they are still drawn, only with a width of 0 to make them appear invisible, but they still causes a drop in performance.

This new method basically 'turns off' the alpha ramp, so when it isn't being used, it isn't seen and it isn't being drawn as an alpha ramp, so no additional drop in performance.

As you can see below, instead of setting .widthtop and .widthbottom to 0 to make it appear invisible, this turns the .alpha property on and off which also causes it to disappear and not be drawn when off. It is scripted below much like drop walls are, except with the necessary light refresh to update the animation.

New Alpha Ramp Plunger Code:
Plunger - Timer Enabled with Interval set at 40, and Enable Mechanical Plunger checked
CODE
Sub Table_KeyDown(ByVal keycode)
If keycode = PlungerKey Then Plunger.Pullback:Pcount = 0:PTime.Enabled = 1:Plunger.TimerEnabled=0
End Sub

Sub Table_KeyUp(ByVal keycode)
If keycode = PlungerKey Then
PTime.Enabled = 0:Pcount = 0:PTime2.Enabled = 1:Plunger.Fire:Plunger.TimerEnabled=1
If(BallinPlunger = 1) then 'the ball is in the plunger lane
PlaySound "Plunger2"
Else
PlaySound "Plunger"
End if
End If
End Sub

'***********************
'Koadic's NewStyle Alpha Ramp Plunger Scripting
'(based heavily on and modified from JP's work)
'***********************

Dim Plungers:Plungers = Array(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p12)
Dim PlNewPos, PlOldPos, PCount, BallinPlunger
ResetPlungers

Sub swPlunger_Hit:BallinPlunger = 1:End Sub 'in this sub you may add a switch, for example Controller.Switch(14) = 1

Sub swPlunger_UnHit:BallinPlunger = 0:End Sub 'in this sub you may add a switch, for example Controller.Switch(14) = 0

Sub ResetPlungers
For x = 1 to 12:Plungers(x).alpha = 0:Next
Plungers(0).alpha = 1
Pcount = 0
PlNewPos = 0
PlOldPos = 0
PRefresh.state = ABS(PRefresh.state - 1)
End Sub

Sub PTime_Timer
If Pcount <12 Then
Plungers(Pcount).alpha = 0
Pcount = Pcount + 1
Plungers(Pcount).alpha = 1
PRefresh.state = ABS(PRefresh.state - 1)
End If
End Sub

Sub PTime2_Timer
Select Case Pcount
Case 0:ResetPlungers
Case 1:Plungers(0).alpha = 0:Plungers(2).alpha = 1:PRefresh.state = ABS(PRefresh.state - 1)
Case 2:ResetPlungers:Me.Enabled = 0
End Select
Pcount = Pcount + 1
End Sub

Sub Plunger_Timer()
Plungers(PlOldPos).alpha = 0
PlNewPos = INT(Plunger.Position/2)
If PlNewPos > 12 Then PlNewPos = 12
Plungers(PlNewPos).alpha = 1
PlOldPos = PlNewPos
PRefresh.state = ABS(PRefresh.state - 1)
End Sub


As you can see, this can easily be adapted to all other ramp lights/animations by changing all 'Ramp.WidthBottom = 0:Ramp.WidthTop = 0' with Ramp.Alpha = 0 and 'Ramp.WidthBottom = 100:Ramp.WidthTop = 100' with Ramp.Alpha = 1, as it changes the ramp state to and from an alpha ramp, thus reducing the performance hit to only the ramps that are showing.

I have also developed a plunger animation using Gates instead of ramps, as they can be switched .visible = true/false (or 1/0), but it has the drawback that if any part of it is off screen, it doesn't get drawn, which is what prompted me to come up with a better solution for alpha ramps. Ramps are still the best solution despite the performance hit, as you can easily move/modify them without having to deal with full table sized images for the dropwall method, the pretty much static image just being shifted of the kicker method, and is more versitile/easier to work with than the reel method.

Thoughts? Questions? Concerns? Ideas? Please chime in.

Edited by koadic, 07 July 2012 - 10:37 AM.


#2 fahq

fahq

    Neophyte

  • Members
  • Pip
  • 9 posts

  • Flag: United States of America

  • Favorite Pinball: silver ball mania

Posted 06 July 2012 - 06:18 PM

so the alpha = 0 makes the ramp not visible.
it would have been nice to have some documentation on the alpha ramps so we could have used this from the get go rather than now having to go back and update all the plungers and lights in our tables.



#3 unclewilly

unclewilly

    sofa king.....

  • VIP
  • 5,170 posts
  • Location:Baltimore, Maryland

  • Flag: United States of America

  • Favorite Pinball: tz, tom, big hurt, who dunnit



Posted 06 July 2012 - 06:21 PM

+1 on that.
this should be added to the vp9.12 users guid

"it will all be ok in the end, if it's not ok, it's not the end"
 
Monster Bash VP10 WIP https://dl.dropboxus... (vpx)WIP15.vpx

uw2.gif


#4 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 06 July 2012 - 06:34 PM

I hear ya, all this has only come about because I looked at all the possible properties in the source code and started messing around with stuff smile.gif

#5 unclewilly

unclewilly

    sofa king.....

  • VIP
  • 5,170 posts
  • Location:Baltimore, Maryland

  • Flag: United States of America

  • Favorite Pinball: tz, tom, big hurt, who dunnit



Posted 06 July 2012 - 06:38 PM

appreciate you looking at that.
the source makes no sence to me.

now maybe i can make freddy playable for everyone

"it will all be ok in the end, if it's not ok, it's not the end"
 
Monster Bash VP10 WIP https://dl.dropboxus... (vpx)WIP15.vpx

uw2.gif


#6 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 06 July 2012 - 06:51 PM

Nice found! This can also be used with many of the flasher effects made with alpha ramps. smile.gif

Edited by jpsalas, 06 July 2012 - 06:52 PM.

If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#7 Wizards_Hat

Wizards_Hat

    Pinball Fan

  • VP Dev Team
  • PipPipPipPip
  • 1,258 posts
  • Location:Manchester, UK

  • Flag: United Kingdom

  • Favorite Pinball: STTNG




  • Trophies:

Posted 06 July 2012 - 06:56 PM

QUOTE (unclewilly @ Jul 6 2012, 07:21 PM) <{POST_SNAPBACK}>
+1 on that.
this should be added to the vp9.12 users guid

If anyone wants to write a paragraph explaining this & let me know where in the guide you think this should go, please do - if it fits, I'll include it in the next update of the guide.

Currently the guide purely documents all of the available settings, options, codes, objects & properties - it makes no comment on how any of these can be used.
My only concern about including "work arounds" or "tricks" in the guide is where do you stop with that?
e.g. if you include a description of this way of using alpha ramps, do you then also include a description of how balls can be used for animation etc, etc, etc...

Not trying to be negative here - just trying to keep the user guide concise yet useful - suggestions welcome.
(for anyone that's never seen it the guide is here: http://www.vpforums....d_Help_v1.0.pdf)

Regards,
Dan.
A wizard only needs one ball...but can handle six.

#8 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 06 July 2012 - 07:17 PM

QUOTE (jpsalas @ Jul 6 2012, 01:51 PM) <{POST_SNAPBACK}>
Nice found! This can also be used with many of the flasher effects made with alpha ramps. smile.gif


As well as flipper decals like such that are used in Haunted House... anything using ramps that need to made visible/invisible.

This also lends itself to batch replacement in current scripts as I described in the first post, all instances of .widthtop/.widthbottom can be replaced with either .alpha = 1 or 0, and you will get the performance improvements without any additional table editing trying to implement a new method.

Edit: LOL I don't even know if this property was meant to be used in this manner, or if this is just a side effect/bug. Either way though, it appears a better method than shrinking alpha ramps to a width of 0. I just don't know if there are any downfalls that I haven't come across yet, which is why I am sharing this so it can be field tested.

Edited by koadic, 06 July 2012 - 07:35 PM.


#9 destruk

destruk

    VPF Veteran

  • VPF Staff
  • 6,338 posts
  • Location:Colorado Springs, CO

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 06 July 2012 - 07:55 PM

Probably include the property in the guide, as that's what the guide is to cover, and then someone could make a 'tricks and techniques guide' for general usage/efficiency routines?

Build a fire, vipers love the heat.


#10 rob046

rob046

    Often Emulated, Never Duplicated

  • Members
  • PipPipPipPipPip
  • 2,023 posts
  • Location:Central PA

  • Flag: United States of America

  • Favorite Pinball: 8 Ball Deluxe, ToM, & Funhouse



Posted 06 July 2012 - 08:12 PM

I was about to come on here & say that koadic helped me optimize CFTBL mod with this trick, & I hope all authors catch wind of this & also see the other uses for this. Yes this is a great find for optimization of tables that run a little rough. Thanks to him for deciding to experiment & find this on something I was working on. Sweet!

Edited by rob046, 06 July 2012 - 09:12 PM.


#11 rob046

rob046

    Often Emulated, Never Duplicated

  • Members
  • PipPipPipPipPip
  • 2,023 posts
  • Location:Central PA

  • Flag: United States of America

  • Favorite Pinball: 8 Ball Deluxe, ToM, & Funhouse



Posted 06 July 2012 - 09:30 PM

QUOTE (destruk @ Jul 6 2012, 03:55 PM) <{POST_SNAPBACK}>
Probably include the property in the guide, as that's what the guide is to cover, and then someone could make a 'tricks and techniques guide' for general usage/efficiency routines?


Not a bad idea. Again with cftbl mod, I had to learn some optimization. If I had just made all clear plastics into alpha ramps, the table would be an absolute hog & unplayable for many. I'm sure guys like JP already know many of the tricks but there are some tables out there not optimized. I know I had to just figure out some things on my own, trial & error. & all I know is just a couple basic things in regards to alpha ramps. Such as for better performance, limit the number of control points, but don't use too few or else they will look like ass for those needing to keep the slider all the way left. Find a good compromise there. Then of course there is setting alpha's to solid in whatever areas you can, such as ramp borders or maybe areas where the ball doesn't pass under. However, 1 downside to this is that for some reason the alpha's appear darker when doing this. Also when doing this, draw these ramps to front or else some funky things can happen.
So as far as building in the editor there is a few things, then of course from a coding perspective we now have this idea from koadic.

Edited by rob046, 06 July 2012 - 09:32 PM.


#12 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 06 July 2012 - 09:52 PM

QUOTE (rob046 @ Jul 6 2012, 04:30 PM) <{POST_SNAPBACK}>
However, 1 downside to this is that for some reason the alpha's appear darker when doing this.


This is because it doesn't use the alpha channel when doing it this way, so the image is completely opaque instead of translucent.

#13 rob046

rob046

    Often Emulated, Never Duplicated

  • Members
  • PipPipPipPipPip
  • 2,023 posts
  • Location:Central PA

  • Flag: United States of America

  • Favorite Pinball: 8 Ball Deluxe, ToM, & Funhouse



Posted 06 July 2012 - 10:01 PM

QUOTE (koadic @ Jul 6 2012, 05:52 PM) <{POST_SNAPBACK}>
QUOTE (rob046 @ Jul 6 2012, 04:30 PM) <{POST_SNAPBACK}>
However, 1 downside to this is that for some reason the alpha's appear darker when doing this.


This is because it doesn't use the alpha channel when doing it this way, so the image is completely opaque instead of translucent.


Yeah I figured the reason had something to do with that. Something I was going to try out was using more transparent textures for solid ramps like that, to compensate for the darker appearance. Actually I think I did briefly try it & the results weren't what I wanted, but I'll revisit it.

#14 jimmyfingers

jimmyfingers

    Pinball Fan

  • VIP
  • 832 posts

  • Flag: Canada

  • Favorite Pinball: Comet



Posted 06 July 2012 - 10:49 PM

This is a HUGE find! I just applied some basic changes to my BSD MOD for the alpha lighting and the frame rate increased by about 30-40%. Really useful for improving performance where we can now and getting more tables even smoother (or simply playable for some people).

Thanks for all your work on this dblthumb.gif

#15 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 06 July 2012 - 10:58 PM

QUOTE (jimmyfingers @ Jul 6 2012, 05:49 PM) <{POST_SNAPBACK}>
This is a HUGE find! I just applied some basic changes to my BSD MOD for the alpha lighting and the frame rate increased by about 30-40%. Really useful for improving performance where we can now and getting more tables even smoother (or simply playable for some people).

Thanks for all your work on this dblthumb.gif


My pleasure biggrin.gif and the greatest thing about this is there is very little to change to achieve the results, just some basic scripting replacements..

Next thing I am attempting to work on is a companion to your flipper mod, to allow for tap passes from when the flipper is at a rest position, instead of needing a flipper in a downward swing to get a softer touch, I'm just trying to iron out a few wrinkles before grabbing a larger base of testers.

#16 jimmyfingers

jimmyfingers

    Pinball Fan

  • VIP
  • 832 posts

  • Flag: Canada

  • Favorite Pinball: Comet



Posted 07 July 2012 - 04:06 AM

Hey Koadic, would you be able to post the script for this enhancement on the Alpha Ramp plunger but also with the "either or" approach to the PBWplunger or a key being pressed. You had one earlier that drew correctly regardless of whether or not the analog plunger was used vs. the key being pressed. Hope this rings a bell as I'd like to use this script verbatim (I have a motion sensor but not a plunger which throws it off as it detects the "PBW" even though I don't have a plunger and use a key assignment).

I imagine I could analyze the two and work it out so no big deal if you can't just thought it might save some time for others in the same boat or who want the same functionality but might not be as into script modification / splicing.

#17 thewool

thewool

    Pinball Fan

  • VIP
  • 1,068 posts
  • Location:North Yorkshire, UK

  • Flag: England

  • Favorite Pinball: WOZ



Posted 07 July 2012 - 08:30 AM

Great work chaps! good.gif

I've tried, but I won't pretend to understand the coding aspects... but really appreciate the + effect it will have on how tables run.

Cheers! :drinks

#18 unclewilly

unclewilly

    sofa king.....

  • VIP
  • 5,170 posts
  • Location:Baltimore, Maryland

  • Flag: United States of America

  • Favorite Pinball: tz, tom, big hurt, who dunnit



Posted 07 July 2012 - 08:42 AM

hey jimmy just open the script and do edit replace
search and replace all .widthtop and .widthbottom with .alpha
then change the numbers 0 stays as 0 and any widths say 200 change those to 1

you can use the pinwizard code from bbb.
i just did this for freddy and it makes a world of difference

"it will all be ok in the end, if it's not ok, it's not the end"
 
Monster Bash VP10 WIP https://dl.dropboxus... (vpx)WIP15.vpx

uw2.gif


#19 koadic

koadic

    Pinball Fan

  • VIP
  • 1,363 posts
  • Location:Omaha, NE, USA

  • Flag: United States of America

  • Favorite Pinball: Addams Family/Fish Tales/Medieval Madness



Contributor

Posted 07 July 2012 - 09:57 AM

QUOTE (jimmyfingers @ Jul 6 2012, 11:06 PM) <{POST_SNAPBACK}>
Hey Koadic, would you be able to post the script for this enhancement on the Alpha Ramp plunger but also with the "either or" approach to the PBWplunger or a key being pressed. You had one earlier that drew correctly regardless of whether or not the analog plunger was used vs. the key being pressed. Hope this rings a bell as I'd like to use this script verbatim (I have a motion sensor but not a plunger which throws it off as it detects the "PBW" even though I don't have a plunger and use a key assignment).

I imagine I could analyze the two and work it out so no big deal if you can't just thought it might save some time for others in the same boat or who want the same functionality but might not be as into script modification / splicing.


You can use the script verbatim, as this is what I included above... You enable the Plunger timer by default with an interval of 40, then use the KeyDown and KeyUp parts for the plungerkey included above, that way whenever the plunger button is pushed, the timer is disabled, then reenabled when it is released. That way the animation works correctly regardless.

#20 jimmyfingers

jimmyfingers

    Pinball Fan

  • VIP
  • 832 posts

  • Flag: Canada

  • Favorite Pinball: Comet



Posted 07 July 2012 - 09:59 AM

QUOTE (unclewilly @ Jul 7 2012, 04:42 AM) <{POST_SNAPBACK}>
hey jimmy just open the script and do edit replace
search and replace all .widthtop and .widthbottom with .alpha
then change the numbers 0 stays as 0 and any widths say 200 change those to 1

you can use the pinwizard code from bbb.
i just did this for freddy and it makes a world of difference

Thanks UW, but I got that part and actually have been up most of the night editing / enjoying some tables that I hadn't played as much because of stutter. It's real easy to replace and I've been re-writing some alpha ramp routines on some tables as they had some nuances / uniqueness to get the full performance boost (LW3 now runs super smooth and I more than doubled the FPS but it had some extra quirks to really get smooth - had to change how the refresh was happening as well).

What I was looking for was this new plunger code but also with the addition of the logic that had something like when the plunger key is pressed, the PBW or PBW plunger animation portion is disabled so that one can use either the key or the analog plunger and the animation still works.

In general and so far while editing / assessing some tables for this performance improvement, I noticed that if the ramps are set smaller / narrower in the editor than what they'll be when they are "expanded" as part ot the alpha ramp routine, then those will need to be fixed and set to the width in the editor that they have as parameters for the routine calls or I've been writing a routine to initialize the size (widthtop / widthbottom) that runs in the script so that I don't have to go around all the editor and find the ramps and for which I can copy and paste the current alpha ramp routine calls with the sizes in them, re-format / replace, and place back in as init calls at the top of the table.

This find is massive for performance improvement and the magnitude for which it can help, thanks again Koadic! clapping.gif