Home Technical Talk

[MAXSCRIPT] Grabviewport 2.0 (alpha, color, AO, wire support )

1
polycounter lvl 15
Offline / Send Message
leslievdb polycounter lvl 15
Grabviewport 2.1

gv2.png

2.1 Changes:
- Now properly includes alpha masks from Xoliul, 3point
shaders and standard material into the Alpha and all other passes
- Hides the World Axis icon from the viewport (max 2008 and higher only)
- Added directory selection and filename in the UI
- Saves settings to ini file and loads them the next time the script opens

Save High Resolution Viewport Captures


Passes:
Alpha: Saves alphas from the viewport to the alpha channel of the baseimage
Color: Assigns random colors to all objects and saves the separate pass
SSAO: Saves a separate Screen Space Ambient Occlusion Pass
Wire : Saves a separate Wire Pass
Z-Depth: Control the Zdepth range and save it as a separate pass (first increase the end untill all is visible and then tweak the begin parameter)


Color, SSAO, Wire, z-depth: save a separate image or avi file to the same directory as the basefile (filename_passname.ext)
Alpha : includes an alphamask in the viewportcapture alpha channel or saves out a separate avi file for the animation.

Tested in 3ds max 9, 2010 , 2011, 2012 (DIRECT3D)

Install:
Drag Grabviewport2.mcr into your viewport or go to maxscript ->Run Script.
Now go to Customize->Customize User Interface.
Toolbars->Category->Grabviewport2 and drag the Grabviewport button into your UI or bind a key to it.


Special thanks to : Borislav Petrov (MaxScript reference), Kostadin Kotev (
miauu )for the Alpha Masking technique :)

passes.png

Replies

  • Sean VanGorder
    Options
    Offline / Send Message
    Awesome, the alpha mask feature will definitely save some time. Thanks for making this dude :)
  • Slipstream
    Options
    Offline / Send Message
    Slipstream polycounter lvl 19
    Holy cow, that's awesome! Ever since I started using HLSL I wanted this. Thanks for sharing!
  • Funky Bunnies
    Options
    Offline / Send Message
    Funky Bunnies polycounter lvl 17
    sweet, I'm definitely gonna have to give this a spin :)
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Nice one, question, is Color mask essentially the color of the whole geometry? Or is it something else? (By that, I don't mean the material, but the geometric pure color such as green and red made as a primitive).
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    currently it does that for objects that don't have any directxmaterial with alpha enabled assigned to them. If it does have an alpha it will only show the non transparant areas of the object as a color. I could add the option to not take the transparency of the material into account.

    i just noticed that the OA pass isn't doing what it should do when i tested it here at work so i'll try to fix that lateron
  • Mio
    Options
    Offline / Send Message
    Mio polycounter lvl 13
    awesome!! thanks for sharing!

    download and try it now!!
  • Racer445
    Options
    Offline / Send Message
    Racer445 polycounter lvl 12
  • [HP]
    Options
    Offline / Send Message
    [HP] polycounter lvl 13
    Thank you for the share!
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    np guys

    I got to test it some more today and i found some bugs that i'll have to fix tonight, if you already downloaded the script make sure to update it when i post the update
  • Pedro Amorim
    Options
    Offline / Send Message
    could you post a comparison pic of what each pass does?
  • obliviboy
    Options
    Offline / Send Message
    obliviboy polycounter lvl 12
    it looks great, thanks!
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    The script not worked on max2009. The main reason is maxops.getViewportShadingSettings() and ViewportButtonMgr wich is for max2010 +. Commented the problematic lines will solve the problem and script will run properly on max2009. Only AOMask don't work.

    Thank you for the credit and for the script. :)
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    odd. yesterday on a computer at school i was able to just drag and drop the script into the viewport and it opened. today at home i do the same and nothing happens. is there another way to launch the script? (also going to MAXScript > Run Script does not work either)

    EDIT: nvm, should've read the first post. XD

    on a different note, howcome rendering an animation cannot be exported as a .tga sequence anymore?

    and 1 other thing: howcome the aspect ratio is no longer locked? by that i mean, before, i could go into expert mode to maximize the amount of viewport i am initially capturing from, and now if i do that the image gets stretched.
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    ABOVE LINK HAS BEEN UPDATED WITH FIXED SCRIPT

    tnx guys

    miauu: no thank you for getting me scripting again :P, i added some version checks . Since the AO pass uses the viewportshading i disabled it if the maxversion is lower than 2010. I also tried the pastebitmap function btw but it requires a bmp with an alpha channel and that would mean i have to do setpixel operations any way so i left it out.

    Oniram: both issues should be fixed

    Pedro: added one above :)

    -The videopasses get saved properly now too
    -If you open another scene with the script opened it won't screw up the materials anymore

    I'm still a bit confused with the AO saving, on my max versions @ home it does this properly but on my max 2011 @ work it doesn't . But on my colleques max @ work it does it the right way too so i'm not sure whats the deal. Do some of you get wrong AO results out of the script?
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Ravenslayer, the script not worked in max2009. :)
    There is little error in GetOriginalState function.

    fn GetOriginalState =
    (
    --print "Creating Original State"
    m_originalwidth = gw.getWinSizeX()
    m_originalheight= gw.getWinSizeY()
    if (((maxVersion())[1] / 1000) > 11) then
    (
    m_originalbgcolor = GetUIColor 41
    m_bviewcube = ViewCubeOps.Visibility
    m_bviewportshadingstate = m_viewportshading.ActivateViewportShading
    m_bviewportshadows = m_viewportshading.ShadowsActive
    m_viewportAO = m_viewportshading.AmbientOcclusionMode
    )
    sceneStateMgr.CaptureAllParts "GrabViewportOriginalState"

    for obj in objects do
    (
    if classof(obj.material) == DirectX_9_Shader then
    (
    append m_tempmats obj.material
    )
    )

    )
    You get the original background color only if the max version is 2010 or up, and in the SetOriginalState I get the error "Unable to convert: undefined to type Point3"on line:

    SetUIColor 41 m_originalbgcolor

    You know the reason for the error. :)


    And one suggestion - hidding the view cube work in max2009. You can put the code that do that out of the max version check. :)

    Best Regards!
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    urgh that's what you get when you bugfix when you're half asleep :D
    tnx for checking , i updated the link again :)

    edit: oh and now i updated the viewcube so it doesn't show in 2009 but still is ignored when the version is lower then 2009 since it didn't have a viewcube yet
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    :)
    I see that you don't read my suggestion. Edditing my post and your post are in 10:30 so, I will quoted myself
    And one suggestion - hidding the view cube work in max2009. You can put the code that do that out of the max version check. :)
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    haha already updated now :D i did miss the suggestion when i posted it, should work fine now
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    haha that companion cube is so awesome :D

    Max is extremely unreliable with every action you try to perform, realtime materials just fail at random , maps getting previewed on wrong models etc... Max 2011 for example loaded the materials properly after a scenestate load but max 2010 and max2012 didn't so i had to implement a "copy" of all dxmaterials before switching states and reassigning them afterwards.

    or the viewport ui hiding requires me too first minimize and then maximize views for it to update 0_p.

    Anyway as much as murphy's law lurks in every action i still love you max :p
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    great , i just tried it in 3ds max 9 and it works so 2008 shouldn't have to give any trouble either
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    awesome. works like a charm. im wondering if you're up for suggestion.. but it would be really neat if you could implement some sort of DOF feature, or maybe rendering a zdepth pass similar to the "GrabDoc" feature in zbrush. makes it nice n easy to composite DOF in photoshop. :D
  • Charlottje
    Options
    Offline / Send Message
    Lovin the AO and Alpha mask feature!
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    tnx ^^

    Oniram: yeah i was thinking of how i could do this

    one way would be to create a gradient material , apply it to all objects in the scene, then apply a uvwmap to all of the objects, align the gizmo to the camera and fit it. You get a nice fake z-depth out of that.

    zdepth.jpg

    The limitations to this are
    -Animation would be refitted every frame so the range of the gradient would change
    - it's only depth in one axis, so if an object is lower it would still be as bright

    ideas are always welcome :)

    Edit nvm i found a cheaper and effective way to do this (bottom post)
    i'm going to implement this and give the option to set the range before capturing so you can visually tweak it to your liking :)

    zdepth_omni.jpg
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    ^^


    CHECK FIRST POST FOR NEW UPDATE
    Z-DEPTH ADDE
    D
  • Poribo
    Options
    Offline / Send Message
    Poribo polycounter lvl 13
    Wow this is great! I've always wanted something like this instead of print-screening or using the default viewport grab.
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    glad you like it

    for future updates i'm planning on having the option to make the script automatically load the screenshots and all passes into photoshop with the right blending modes etc...

    and maybe also the option to tweak the SSAO setting like you do with the zdepth now

    other suggestions are always welcome
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    yeah ofcourse it will optional, i wouldn't save the file and close it btw i'd just open it up in photoshop and have it ready to be composited by the artist

    I could add the option to save separate passes like diffuse, spec, gloss but i wonder at what point you can still call it realtime for model presentation. For bloom i usually use xoliuls post shaders for example (which reminds me now that i don't turn them off when capturing the passes so i'll need to fix that too).

    compositing the SSAO afterwards for example in my book isn't cheating since max doesn't scale this properly when you try to capture it

    then again i'm not the realtime police either , people can use the script for whatever purpose
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    that is awesome! i started to tell a friend of mine about this script just now and he looked it up on scriptspot. didnt expect it already to have the Z-Depth feature but there it was. :D absolutely amazing work.
  • Racer445
    Options
    Offline / Send Message
    Racer445 polycounter lvl 12
    would it be possible to output single passes to the clipboard for easy pasting in photoshop using a "save to clipboard" button?
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    Oniram:
    haha yeah that's a featured i really wanted to have in there right away ^^


    Racer:
    yeah it isn't that hard from what i've read but i was wondering what i would do when users do select multiple passes

    have the script wait and ask the user to paste it each step with a continue button for the next step or only have the base screenshot copied to the clipboard
    or i could have the option to paste it into the currently opened photoshop document. It all depends on what you want to do with it
  • Racer445
    Options
    Offline / Send Message
    Racer445 polycounter lvl 12
    have the script wait and ask the user to paste it each step with a continue button for the next step

    is probably the most elegant solution imo.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Hey Raven,

    I'm using Max 2009, and whenever I try starting the Script, it sends up an error alongside the Script with the message:

    -- Unknown property: "visibility" in undefined

    It also higlights the following part:

    if (((maxVersion())[1] / 1000) > 10) then
    m_bviewcube = ViewCubeOps.Visibility
    if (((maxVersion())[1] / 1000) > 11) then
    (

    I'm assuming I need the Viewport Cube open to work? Because I have it disabled, so I'm curious as if that is the issue.
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    how exactly did you turn it of ? there was someone on scriptspot with the same problem but it turns out he deleted AutoCamMax for some reason. If you did that i'd suggest undoing it and just typing ViewCubeOps.Visibility = false in the listener
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    how exactly did you turn it of ? there was someone on scriptspot with the same problem but it turns out he deleted AutoCamMax for some reason. If you did that i'd suggest undoing it and just typing ViewCubeOps.Visibility = false in the listener

    Thanks, I used 3DS Clean from Perna and crew, which moved those files away, so that explains it.

    Also, I assume Z-Depth and SSAO aren't going to be in Max 2009, correct?
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    nope because they use the viewportshading to create those states

    oh and since more people will be using the 3ds clean script i added an extra check so it won't crash any more. If you want to you can remove the file again and update the script
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Nice stuff Raven. Made me want to research/get a viewport grab for realtime shaders for maya. LLoving the loading of screenshots into photoshop.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    nope because they use the viewportshading to create those states

    oh and since more people will be using the 3ds clean script i added an extra check so it won't crash any more. If you want to you can remove the file again and update the script

    Much appreciated, although I'm curious, I never knew Max 2010+ could (inside the viewport shadings) do a Z-Depth pass, how is that possible if you don't mind me asking (is there a setting option to enable it?).
  • megalmn2000
    Options
    Offline / Send Message
    megalmn2000 polycounter lvl 13
    A bit slow but it works well! Thanks for sharing! :)
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    haiddasalami: haha great :) , hope you get it to work

    dustin: yeah that's totally true, i wasn't judging either just thinking out loud of what the script should be for.

    Ace-Angel: It doesn't , i'm faking it with an omni light linked to the camera. But for that i need smooth viewportshading.

    megalmn: tnx, yeah i know it isn't the fastest but it does the trick. Perhaps i could speed it up at some places so i'll also look into that :)
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    Script updated in first post :)

    2.1 Changes:
    - Now properly includes alpha masks from Xoliul, 3point
    shaders and standard material into the Alpha and all other passes
    - Hides the World Axis icon from the viewport (max 2008 and higher only)
    - Added directory selection and filename in the UI
    - Saves settings to ini file and loads them the next time the script opens


    no photoshop stuff yet but i wanted it doing what it's supposed to do first
  • BadgerBaiter
    Options
    Offline / Send Message
    Many thanks :D

    Had a slight issue, accidently clicked on the undefined button to destination of images and clicked off of it, and then it came up with undefined string error. It wouldn't let me go back and define the folder for some reason.
    Just re-ran the script and made sure I entered the correct destination the first time around though...
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    oh i thought i added a check for that already :s
    script is updated so if that happens it will save to the sceneassets/images folder instead untill you set it properly
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    I noticed at work that there are some odd issues with some max installs.

    It seems to be something non version specific and it's always something else that seems to go wrong. Are other people having trouble? Here at home i tested with 4 versions of max and they work without any trouble.

    For example, does the alpha show correctly ? do you get to see white objects while it is capturing that state or do they turn black ?

    Would be great if people could test this for me and tell me the right issue (check the example image in the first post of what the passes would look like ) + what max version and bit version they are using

    tnx :)
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    so far everything works except the Zdepth pass. no matter what settings i choose for the begin/end.. it makes no difference.. i still just see the object as if it has the original shader on it

    also i have a camera thats tilted a bit on an axis, and when i use the script it resets the camera tilt before grabbing the image.
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    sorry for the late response. Could you tell me what version of max you are using and what shader?
    I'll check that camera bug. It probably still creates a new one instead of using the existing camera
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Hey guys, small question, my images get 'skewed' when I take the capture using a Camera, is this normal?

    EDIT: Also, have to mention, the Animation is a no-go, it keeps on deleting the final animation and replacing my 1 min render with a 4 second black screen. I would say a direct render of the image files is a better solution since I need to pop in my Max scene every few minutes to make sure I copy or stop manually the capture before it's finishes.
  • mLichy
    Options
    Offline / Send Message
    Awesome dude, thanks alot :D
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    tnx guys

    Ace: i'm going to take a look at that this weekend! added to the list tnx :)
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    sry raven. missed your comment. i am using 2012, and i was using the 3pointshader. i think the shader is why zdepth wasnt working
1
Sign In or Register to comment.