Graphics

 View Only
  • 1.  Script Shaders

    Posted 01-21-2014 17:45
    Hello,

    I'm working on a curling graphic that will display the current scores, and icons to indicate which team has the "hammer" as well as 16 little rock icons to indicate remaining rocks.

    I'm working on a script that is driven by a text list widget. It just drives the visibility of two quads with two different materials. This is the script I have, and seems to be working fine.



    dim hammerwidget as xpTextListWidget

    dim hammericonleft as xpBaseObject

    dim hammericonright as xpBaseObject

    engine.GetWidgetByName ("Hammer Position",hammerwidget)

    self.GetObjectByName ("hammericonleft",hammericonleft)

    self.GetObjectByName ("hammericonright",hammericonright)

    if hammerwidget.Value = "left" then

    hammericonleft.visible= true

    hammericonright.visible= false

    else if hammerwidget.Value = "right" then

    hammericonleft.visible = false

    hammericonright.visible = true

    end if



    But then I thought it may be more effecient to just have one object, and just effect shader layers in the material. So the widget would drive the visibility of the the Shaders. I will be using a similar technique to affect the rock icons, so I'd rather not have 16 objects...

    I'm brand new to scripting, and what I have completed has been scraped together based on other posts in the forum, and a few lucky guesses :) Here is the script so far, but it's not working and I'm not sure why.



    dim hammerwidget as xpTextListWidget

    dim hammericon as xpBaseObject

    dim hammermaterial as xpMaterial

    dim hammerleftshader as xpBaseShader

    dim hammerrightshader as xpBaseShader

    engine.GetWidgetByName ("Hammer Position",hammerwidget)

    Self.GetObjectByName("hammericon", hammericon)

    hammericon.GetMaterial(0,hammermaterial)

    hammermaterial.GetShader(0,hammerleftshader)

    hammermaterial.GetShader(0,hammerrightshader)

    if hammerwidget.Value = "left" then

    hammerleftshader.enabled = true

    hammerrightshader.enabled = false

    else if hammerwidget.Value = "right" then

    hammerleftshader.enabled = false

    hammerrightshader.enabled = true

    end if



    Any assistance is appreciated. Thanks!

    Chris


  • 2.  RE: Script Shaders

    Posted 01-21-2014 18:13
    It's really hard to answer without seeing the scene you've build, but the one thing that stands out from your script is this section:



    hammermaterial.GetShader(0,hammerleftshader)

    hammermaterial.GetShader(0,hammerrightshader)


    You are basically getting the same shader (number 0) and assigning it to both the left and right shader..

    I think you intended:



    hammermaterial.GetShader(0,hammerleftshader)

    hammermaterial.GetShader(1,hammerrightshader)



    #XPression


  • 3.  RE: Script Shaders

    Posted 01-21-2014 19:40
    Hi Brian,

    Thanks for the reply. I made the change, but still no success.

    I've upladed the file to dropbox here: if you get a chance to take a peek, but I'll try explain the scene. Here's what I have:

    - Text List widget ("Hammer Location") with the values, "left" and "right"

    - quad ("hammericon")

    - material ("hammermaterial") applied to the quad

    - inside the material, there are two texture shaders: "hammerleftshader" and "hammerrightshader"

    So I just want the script to enable and disable those shaders, depending on which value is loaded in the widget

    Thanks again for your help!

    #XPression


  • 4.  RE: Script Shaders

    Posted 01-21-2014 22:23
    Chris,

    Try this: http://ross.brickftp.com/f/238cc546f

    xpBaseShader doesn't actually have an Enabled property; but xpMaterialLayer does.. So I changed it to use GetLayer instead of GetShader. I had to modify you material to get this to work, as well I created a dummy (0 transparency layer) in the material because you must always have at least 1 material layer enabled, so I just created this incase you want both hammers to be hidden or something..

    The other approach (and more common one) that I've seen used is to use xpBaseShader.FileName to simply change the file that the shader points to. If you just change it between the left and right.png files then your script can get much simpler and you wouldn't need to prebuild all of the different layers in the material.

    #XPression


  • 5.  RE: Script Shaders

    Posted 01-21-2014 22:56
    Thanks again, Brian. The Layers worked really well.

    But I'm curious about the FileName parameter you mentioned. To me, this sounds like the more logical option, especially when it comes time for something more complicated like the remaining rock icons. Can you walk me through the method a bit? I gave it a go on my own here, based on another forum post:



    dim hammerwidget as xpTextListWidget

    dim hammericon as xpBaseObject

    dim hammermaterial as xpMaterial

    dim hammershader as xpBaseShader

    dim Filepath1 as string

    engine.GetWidgetByName ("Hammer Position",hammerwidget)

    Filepath1 = "C:UsersXPressionDesktopImages" & hammerwidget.Value & ".png"

    Self.GetObjectByName("hammericon", hammericon)

    hammericon.GetMaterial(0,hammermaterial)

    hammermaterial.GetShader(0,hammershader)

    hammershader.setFileName(Filepath1)



    And it technically WAS working, but the perf. meter jumped up into the 1000% and then even a simple fade transition wasn't playing back smoothly...

    Again, thanks for your help!

    #XPression


  • 6.  RE: Script Shaders

    Posted 01-21-2014 23:54
    It may not work very well in an OnRender script because it would be reloading the file every frame.. I'll test it out a bit tomorrow and see if I come up with a better option.

    I'm not sure why you're opposed to having 16 rock quad objects in the scene.. That would be the way I would recommend. That way you could even animate and assign keyframes to the rocks (for example to blink each rock as they are throwing it) You would have the same material assigned to all 16 rocks (or better yet two materials, one for each color). Then use a script assigned to the OnSetText script of a text object that would toggle the visibility of each rock. You could have a different animation controller for each rock that gets triggered (just build it once, then copy/paste it to each of the 16 rocks).

    #XPression


  • 7.  RE: Script Shaders

    Posted 01-22-2014 05:47
    Hi Brian,

    I'm right there with you, but I'm not sure I follow the theory. So you mean I can actually script an animation controller to trigger based on the contents of a text object?

    I'm working on an animate-on effect where the pieces of the score bug "grow" into place. In a perfect world, the score bug would animate on and reach a "pause and reverse direction" event, and I could animate off when needed; The rocks meanwhile would be controlled by a widget, and would animate off when the widget is changed (with a blinking animation).

    That way, if the bug is taken offline (during replay, for example), I could bring it back in with the animation, and the correct number of rocks would still be showing.

    I hope I'm making sense here...

    #XPression


  • 8.  RE: Script Shaders

    Posted 01-22-2014 22:57
    Yes, you can do all that..

    I made a sample, although the scripting gets a bit complex but this should do everything you need:

    http://ross.brickftp.com/f/597d3015b

    It has widgets for controlling the rocks remainign, and when you decrement it, it will start an anim controller that blinks the rock. If you increase the widget, it will put the rocks back on.

    You can animate the graphic on and off with a pause/reverse event like you describe and the rocks will come back to their correct state.

    Play my sample back from the sequencer and adjust the widgets to see how it works. There are scripts on two different text objects (RedRocks, GreenRocks) that plays the anim controllers and resets the rocks. There is also a script on OnOnline that makes sure the rocks are in the correct on/off state when animating the graphic on.

    There are 16 different anim controllers (one for each rock), but these aren't on the scene director. You'll find them in the animation controller tab on the right side.

    Let me know if you have any questions.

    Brian

    #XPression


  • 9.  RE: Script Shaders

    Posted 01-23-2014 17:08
    Wow! Thanks a ton, Brian! I've been pouring over this project all morning.

    The script seems very straightforward, definitely learned a lot. Thanks again!

    #XPression