Home Technical Talk

[MaxScript] Grab Viewport with alpha channel

polycounter lvl 10
Offline / Send Message
miauu polycounter lvl 10
The script that grab the active viewport and include an alpha channel was requested in cgtalk forum.
So, this is my attempt. Note that the script is not very fast. Test it and if you like it - use it. :)


Download from scriptspot

Replies

  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    Just looking at the script, it seems to be rather a save screenshot with monochrome transparency.
    There seems to be a way in dotNet to store a PNG file (as binary dump) in the bitmap clipboard manager of windows and photoshop should be able to paste it as a transparent bitmap but I haven't found a sample source code for it yet. I wish windows and MacOSX would get their acts together and support proper postscript and 32 bit RBA bitmap support.
  • miauu
    Offline / Send Message
    miauu polycounter lvl 10
    What idiot requested that?
    :D!!
    So, is the script useful to you or not? :)

    @renderhjs, may be someone with more dotNet expirience can do that.
  • Bigjohn
    Offline / Send Message
    Bigjohn polycounter lvl 9
    Is it possible to use something like this to get a result similar to Unreal's tiledshot? Meaning, take a screenshot that's larger than the screen resolution?
  • miauu
    Offline / Send Message
    miauu polycounter lvl 10
    Yes, it possible.
    The ver/ 1.1 is available. Now you can take a screenshot that's larger than the screen resolution.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 7
    Nice one, thank you!
  • Funky Bunnies
    Offline / Send Message
    Funky Bunnies polycounter lvl 14
    yeah man variable size would be great :D
    ohhh i guess I'm late, I'll try out the new one :)

    I've never taken a look at the code but this grabViewport does it that way

    I noticed a couple things i didn't expect in my quick playing with it.
    1. the alpha is only saved if you properly set the image save settings to be 32 bit and so on prior to running this script. Is there a way to get the 'Setup' button in this dialog?
    2. the alpha is clamped to 1-bit pixels (why not use 'AR_thepixels_A[j].a = AR_thepixels_B[j].r'? since it's monochromatic)
    3. it doesn't work with realtime shaders like xoliul, since you're using a monochromatic alpha and vertex colored flatshading i think. I'm not sure how you could get around this
    4. this isn't a problem for people who code, but being a macroscript in a maxscript I think some peeps may get confused.

    this would be super useful to include animation saving to an image sequence if you have time also.
  • miauu
    Offline / Send Message
    miauu polycounter lvl 10


    I noticed a couple things i didn't expect in my quick playing with it.
    1. the alpha is only saved if you properly set the image save settings to be 32 bit and so on prior to running this script. Is there a way to get the 'Setup' button in this dialog?
    2. the alpha is clamped to 1-bit pixels (why not use 'AR_thepixels_A[j].a = AR_thepixels_B[j].r'? since it's monochromatic)
    3. it doesn't work with realtime shaders like xoliul, since you're using a monochromatic alpha and vertex colored flatshading i think. I'm not sure how you could get around this
    4. this isn't a problem for people who code, but being a macroscript in a maxscript I think some peeps may get confused.
    this would be super useful to include animation saving to an image sequence if you have time also.

    1 - I will add Setup button tomorow. Or may be is a good idea to force the script to set the image save settings to be 32 bit.

    2 - feel free to change that. :)

    3 - i can't use xoliul shader. My PC is too old.

    this would be super useful to include animation saving to an image sequence if you have time also.
    
    This will kill the script. Creating the alpha channel is too slow now(for big viewport resolution) - imagine animation of 100 frames and you have to wait 20 sec for every frame.

    :)
  • leslievdb
    Offline / Send Message
    leslievdb polycounter lvl 12
    great approach miauu, i always intended to clean that hacky script up a bit and your post made me sit down and start doing it :)

    these will be the options
    grabviewport2.png

    I already made sure that none of the ui stuff shows when you take a screenshot, alphamask data from objects with the xoliul shader also shows in the capturealpha, and it will be having an extra options to save a separate colormask and the Screenspace ambient occlusion pass.

    I could make this possible for the animation but as you already mentioned it would become an enormously slow process to save everything .

    Anyway i hope you don't mind me using your approuch (you're already credited ^^), i'll probably be releasing the script and the source tomorrow or the day after
  • Funky Bunnies
    Offline / Send Message
    Funky Bunnies polycounter lvl 14
    you guys are awesome :)

    I've already gotten a lotta use outta ravenslayer's original script but these new ones will be crazy useful
  • miauu
    Offline / Send Message
    miauu polycounter lvl 10
    Ravenslayer, no problem. Use whatever you want or need. :)
    I have one suggestion - why the height spinner is disabled? If I want to grab the screenshot with height of (for example) 1000px I have to calculate the height/width ratio and then put the xxxx.xxxx value in width spinner. Can you release the script with "active" height spinner. When you post the code I can do it for my self, but may be someone will need this feature too. :)

    And one suggestion from cgtalk thread of Grab Viewport with alpha (post #12)
    [URL="http://forums.cgsociety.org/member.php?u=120378"]tassel[/URL]
    Nice, here's a little idea: Why not send the image to photoshop?
    
     A few interesting links i found:
    
    [URL="http://www.just-joshing.com/2009/06/03/open-bitmaps-in-photoshop/"]http://www.just-joshing.com/2009/06...s-in-photoshop/[/URL]
    [URL="http://area.autodesk.com/forum/autodesk-3ds-max/maxscript/max-last-render-to-photoshop/"]http://area.autodesk.com/forum/auto...r-to-photoshop/[/URL]
    
    And only one thing... I found this thread on cgtalk.
    May be you can use pastebitmap instead of getpixels-setpixels. As far as I know pasteBitmap is much faster, but it not work on max2009, so I can't test the code. :)
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 11
    Man wish there was a tile shot ability in maya. There's a way to get a viewport grab but still havent found a way to do tile shot. Awesome stuff Raven and Miauu
  • leslievdb
    Offline / Send Message
    leslievdb polycounter lvl 12
    no problem guys

    miauu: tnx, i'm going to try the pastebitmap method and if it works then i'll do a check in my script and use that one if the version is 2010 and later.

    i don't know why i disabled the height actually , the first script was a quick trow together of maxscript help scripts that i adjusted to enable bigger screenshots so i guess it was lazyness. I'll make sure it's enabled.

    the straight to photoshop also sounds like a good idea but i'm going to look into that after i released the standard working script.

    i was also playing with the idea to look into zdepth or a faked zdepth mask option so that's also something that might be included in the future.

    more suggestions are welcome :)
  • leslievdb
    Offline / Send Message
    leslievdb polycounter lvl 12
    in the new one it will , it will also do that for the colormasks
Sign In or Register to comment.