[Closed] Grab Viewport With Alpha
The GrabViewport script linked below is fantastic for game artists because it lets you take high res viewport screen grabs of assets with DX shaders applied. DX shaders don’t render, for those that don’t know.
http://www.laurenscorijn.com/viewportshader
The one thing that script is missing is the option to include an alpha channel, so when you bring it into Photoshop you can throw it on a custom background and make a presentation sheet.
Is this possible? Perhaps there is some viewport equivalent of a render buffer that can be tapped into?
Marmoset Toolbag includes alpha channels with its screen grabs, I’m just looking to do the same out of Max.
it’s possible. usually i share my solutions. but that’s… kinda a treasure…
so, dig and you get it. just know it’s possible.
Wouldn’t you access the framebuffer or Gbuffer or something, I’m guessing… and extract it from there somehow? I thought I read somewhere on this forum how to do that…
One hacky way to do it would be to have a script take the screen shot, then put a white self-illuminated material on everything in your scene, set the viewport background to black, save that as the alpha, then reset everything back the way it was.
Why not just put a pure green on the viewport background, grab that and key it in photoshop? Dunno, might be a silly solution
Thats a good idea too I like those kind of ideas. They are sorta hacky, but prob. just as affective, and alot easier to do if you don’t have the knowledge.
Have you looked at metaSL and QuickSilver? Or DirectX and QuickSilver? That should allow you to get realtime shaders that can render the same as the viewport representation. If you need DirectX Scene Shaders, that is a different story.
-Eric
That’s exactly what I’ve been doing. Not silly at all, but I would like to either find or make a script that saves me the trouble.
Yep, I’m using DX shaders. Xoliul and 3PointShader. Those are the two big ones folks use. Shader FX if you’ve got the money to spend.
My attempt to do the grab viewport script with alpha channel.
Note that the script is not very fast( the creating of the alpha channel is slowing it down)
Credits to Borislav “Bobo” Petrov and Dave Wortley.
--***************************************************************************************************
-- Created: 29-05-2011
-- Last Updated: 29-05-2011
-- Version: 1.0
--
-- Author : Kostadin Kotev / miau_u@yahoo.com /
-- Version: 3ds max 2009 (should work in older versions too!)
--
-- Discription:
-- Grab the active viewport and include an alpha channel.
-- IMPORTANT: The script is not very fast. :)
--***************************************************************************************************
-- MODIFY THIS AT YOUR OWN RISK
macroscript miauuGrabViewport
category:"miauu"
tooltip:"Grab Viewport"
buttonText:"Grab Viewport"
(
local grab_viewpBMP
local defaultVbkgColor
local grab_alphaBMP
local tempBMP
local viewport_name
local mfn
local gct
local bmp_name
--//// credits to Borislav "Bobo" Petrov (MaxScript reference)
-- get viewport name
viewport_name = viewport.GetType() as string
-- cut the string
viewport_name = substring viewport_name 6 (viewport_name.count-5)
if viewport_name == "camera" then -- if the remaining string is "camera"
(
gac = getActiveCamera() -- get the camera
viewport_name = gac.name -- get the name of the camera
)
-- get max file name
mfn = MaxFileName
if mfn == "" then -- if there is no name
mfn = "Untitled" -- use "Untitled"
else
mfn = getFileNameFile mfn -- use the file name without .MAX extension
-- get current frame time
gct = SliderTime as string
-- build the output file name
bmp_name = "VPGRAB_"+ mfn +"_" +viewport_name + "_" + gct
-- Display file save dialog
bmp_name = getSaveFileName caption:"Save Viewport to:" filename:bmp_name \
types:"TGA(*.tga)|*.tga|PNG(*.png)|*.png|TIFF(*.tif)|*.tif|JPG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp|"
--////
if bmp_name != undefined then -- if user has confirmed / entered a valid name
(
forcecompleteredraw dodisabled:true
theHold.begin()
-- grab the viewport
grab_viewpBMP = gw.getViewportDib()
-- make all visible objects white
for o in objects where not o.isHidden do
(
o.displayByLayer = false
o.showVertexColors = true
)
-- save the default viewport color
-- defaultVbkgColor = getVPortBGColor() -- not worked in max2010
defaultVbkgColor = GetUIColor 41
-- set the viewport color to pure black
-- setVPortBGColor ((color 0 0 0) as Point4) -- not worked in max2010
SetUIColor 41 ((color 0 0 0) as Point4)
colorMan.repaintUI #repaintAll
-- grab the bitmap that will be used as alpha channel
grab_alphaBMP = gw.getViewportDib()
theHold.cancel()
-- setVPortBGColor defaultVbkgColor -- not worked in max2010
SetUIColor 41 defaultVbkgColor
colorMan.repaintUI #repaintAll
--//// credits to DaveWortley.
--create new temporary bitmap
tempBMP = bitmap grab_viewpBMP.width grab_viewpBMP.height
for i = 1 to grab_viewpBMP.height do
(
AR_thepixels_A = Getpixels grab_viewpBMP [0,i] grab_viewpBMP.width
AR_thepixels_B = Getpixels grab_alphaBMP [0,i] grab_alphaBMP.width
for j = 1 to AR_thepixels_A.count do
(
alfaVal = 0.0
if AR_thepixels_B[j] == (color 0 0 0) do
(
swap AR_thepixels_A[j].a alfaVal
)
)
setpixels tempBMP [0,i] AR_thepixels_A
)
--close the original images so we can overwrite them
close grab_viewpBMP
close grab_alphaBMP
--////
tempBMP.filename = bmp_name -- set output name to the one entered in the save file dialog
save tempBMP
Close tempBMP
grab_viewpBMP = undefined
grab_alphaBMP = undefined
tempBMP = undefined
)
freeSceneBitmaps()
gc()
)
ha – just stumbled over that thread …
as i’m writing a preview creation script myself right now, this “make all obj’s temporary white on black background and grab for alpha” idea might call up my efforts to implement alpha channel support again…
thanks for this idea …