下麵是使用方法和步驟:
一、創建幾何體、光源。如圖。
點擊放大
二、選擇幾何體,為其指定一個純白色材質(一定不要有顏色)。如圖。
點擊放大
三、選擇幾何體,在utilities麵板點擊more按鈕,選擇 Assign Vertex Colors組件,確認channel組選擇的是vertex color,按“指定到選擇”(assign to selected)按鈕。
點擊放大
[page]
四、現在可以刪除光源了(或把它關閉)。然後點選幾何體,這是會彈出vertexPaint對話框,選擇左上的vertex color display -unshaded ,這時可以看見即使場景中沒有燈光幾何體也會被照亮。
點擊放大
五、試著渲染一下,卻沒有變化,這時,需要給Diffuse一個vertex color材質。渲染一下,差不多了。還要給它一個100的自發光值。這時可以了。
點擊放大
六、塌陷成網格物體。然後運行腳本。點選“轉變為max6幾何體”按鈕。然後簡單設置如圖:最後按下"Collapse + Generate Trans."按鈕,等待結果。
點擊放大
完成如圖,基本思想是將燈光的光照信息通過擇 Assign Vertex Colors組件變成幾何體的頂點的顏色值,然後通過公式計算各頂點顏色的混合程度。原腳本對max6不支持是因為max6網格物體增加了c-p-v vertex屬性,導致著色錯誤。為了對比將原腳本,練習場景上傳。
[page]
-- 版本 0.56 for max6
-- 作者 grant adam ghra@optushome.com.au
-- 修改 於浩 yuhao_dudu@163.com
-- 模擬半透明物體的效果
-- v0.56 修改了該腳本不能在max6環境下運行的毛病。主要是對頂點著色的機製作了調整
-- 為了尊重作者,所以隻對修改的部分做了漢化。
-- 典型工作流程:
-- 1. 創建幾何體、光源。
-- 2. 選擇幾何體, 為它指定一個白色材質, 使用 'assign vertex colors' 功能
-- 3. 塌陷幾何體為網格物體, 運行腳本, 點擊"轉變為max6幾何體"。
-- 4. 選擇那些不應該被照亮的頂點 然後使用'Assign selected verts as black'。
-- 5. 調整參數, 點擊 'collapse + generate trans.' 按鈕然後等待計算完成。
-- 6. assign a material with a vertex map in the self illum slot, render.
-- 7. if you don't like result hit the 'restore vertex colors' play with params and rebuild trans.
-- 8. when happy with trans, play with material until desired result.
-- note the vertex color map can be made sub to an output map and curve/multiplier/etc. changed there.
-- try the vertex color map as the input for a Mapped Gradient Ramp.
-- use a larger 'nth vertex' param until you are happy, then set to 1 or 2 and wait much longer (depending on mesh density).
-- more than likely you can get away with calculating on a lighter mesh and then meshsmoothing.
-------------------------------------------------------------
global orig_clr_array
rollout trlncy "Translucency 0.56 for max 6"
(
spinner srchrad "Search Radius" range:[0,1000000,100] type:#float fieldwidth:50
spinner vskip "nth Vertex (skip verts)" range:[1,100000,4] type:#integer fieldwidth:50
spinner vflf "Trans. Falloff" range:[0.1,25, 1] fieldwidth:50
--spinner vmult "Trans. multiplier" range:[0.1,100,1.5] fieldwidth:50
button doit "Collapse + Generate Trans." width:170
checkbox solonly "Transluc. component only" checked:false
checkbox ussel "Selected Vertices"
label a1 "You must have vertex colors"
label a2 "assigned with the vert colors"
label a3 "utility, using the 'mix' type."
button und "Restore vertex colors to base" width:170 offset:[-8,0]
button set_und "Set vertex color base to current" width:170 offset:[-3,0]
button crblk "Assign selected verts as black" width:170 offset:[-6,0]
button crwt "Assign selected verts as white" width:170 offset:[-6,0]
button crSS "Assign Sel.verts>Soft Selection:" width:170 offset:[-2,0]
label a5 "if cancel = no screen redraw:"
button fxsc "Enable ScreenRedraw" width:170
button btn_cvtmax6 "轉變為max6幾何體" pos:[4,320] width:170 height:16
on fxsc pressed do
(
enablesceneredraw()
)
on btn_cvtmax6 pressed do
(
c=#()
for i=0 to 255 do
(
c[i+1]=meshop.getVertsByColor $ (color i i i) 1 1 1
----將cpv頂點數和幾何體頂點數對應
defaultVCFaces $
-----給每個頂點著色
for j=0 to 255 do
(
select $.verts[c[j+1]]
a=$.selectedverts
for k=1 to a.count do
(
setVertColor $ a[k].index (color j j j)
)
on set_und pressed do
(
orig_clr_array = #()
for i in 1 to (getnumcpvverts $) do --------------
(
append orig_clr_array (getvertcolor $ i) -- store original vertex colors
und.enabled = true
)
on crSS pressed do
(
try(getvertcolor $ 1)
catch(defaultVCFaces $)
try
(
--orig_clr_array = #() -- store original color vertex array
if orig_clr_array[1] == undefined then
(
for i in 1 to (getnumcpvverts $) do
(
append orig_clr_array (getvertcolor $ i) -- store original vertex colors
und.enabled = true
SS_clr_array = #() -- to store the new data
if $.modifiers.count != 0 then collapseStack $
subObjectLevel = 1
--sel_array = getvertselection $
for i in 1 to (getnumcpvverts $) do
(
if btow.checked then (append SS_clr_array ((color 255 255 255) * (pointSelection $ i)))
else (append SS_clr_array ((color 255 255 255) * (1 - (pointSelection $ i))))
-- else (setvertcolor $ i ((color 255 255 255) * (1 - (pointSelection $ i))))
-- now composite the color data
clrstor_array_mod = #()
for i in 1 to (getnumcpvverts $) do
(
if btow.checked then
(
append clrstor_array_mod (orig_clr_array[i] * ((color 255 255 255) - SS_clr_array[i]) + SS_clr_array[i]) -- screens value
else
(
append clrstor_array_mod (orig_clr_array[i] * SS_clr_array[i] ) -- multiplies value
for i in 1 to (getnumcpvverts $) do
(
setvertcolor $ i clrstor_array_mod[i]
update $
und.enabled = true
catch(messagebox "Failure - no object selected?")
)
on crblk pressed do
(
try(getvertcolor $ 1)
catch(defaultVCFaces $)
try
(
if orig_clr_array[1] == undefined then
(
for i in 1 to (getnumcpvverts $) do
(
append orig_clr_array (getvertcolor $ i) -- store original vertex colors
if $.modifiers.count != 0 then collapseStack $
subObjectLevel = 1
sel_array = getvertselection $
for i in sel_array do
(
setvertcolor $ i (color 0 0 0)
update $
und.enabled = true
catch(messagebox "Failure - no object selected?")
)
on crwt pressed do
(
try(getvertcolor $ 1)
catch(defaultVCFaces $)
try
(
if orig_clr_array[1] == undefined then
(
for i in 1 to (getnumcpvverts $) do
(
append orig_clr_array (getvertcolor $ i) -- store original vertex colors
if $.modifiers.count != 0 then collapseStack $
subObjectLevel = 1
sel_array = getvertselection $
for i in sel_array do
(
setvertcolor $ i (color 255 255 255)
update $
und.enabled = true
catch(messagebox "Failure - no object selected?")
)
on doit pressed do
(
k=#()
r_val = #()
g_val = #()
b_val = #()
rgb_val = #()
clrstor_array = #()
start = timeStamp()
disableSceneRedraw()
try
(
wht = (color 255 255 255)
collapseStack $
-- store original color vertex array
orig_clr_array = #()
for i in 1 to (getnumcpvverts $) do
(
append orig_clr_array (getvertcolor $ i) -- store original vertex colors
setProgressCancel true
progressStart "Generating Translucency"
d = 0
if ussel.checked then
(
sv = for i in $.selectedVerts collect i.index
for i in 1 to (getnumcpvverts $) do
(
if (finditem sv i) != 0 then
(
if getprogresscancel() then exit
clr_array = #()
dist_array = #() -- array to store distances
for j in 1 to (getnumcpvverts $) by vskip.value do
(
f = (distance (getvert $ i) (getvert $ j))
if (f < srchrad.value) and (f != 0) then
(
append clr_array orig_clr_array[j]
append dist_array f
a = getvertcolor $ i
b = clr_array.count
c = (color 0 0 0)
for g in 1 to b do
(
c += ((clr_array[g]/b) * (1 - (dist_array[g]^vflf.value/srchrad.value^vflf.value)))
append clrstor_array c
--setvertcolor $ i (a * (wht - c) + c) -- this 'screens' the new values onto the initial vrtx value
d += 1
if mod d 20 == 0 then (progressUpdate (i*100/$.numverts)) -- don't want to update progressbar too often
else append clrstor_array (color 0 0 0)
else
(
for i in 1 to (getnumcpvverts $) do
(
if getprogresscancel() then exit
clr_array = #()
dist_array = #() -- array to store distances
for j in 1 to (getnumcpvverts $) by vskip.value do
(
f = (distance (getvert $ i) (getvert $ j))
if (f < srchrad.value) and (f != 0) then
(
append clr_array orig_clr_array[j]
append dist_array f
a = getvertcolor $ i
b = clr_array.count
c = (color 0 0 0)
for g in 1 to b do
(
c += ((clr_array[g]/b) * (1 - (dist_array[g]^vflf.value/srchrad.value^vflf.value)))
append clrstor_array c
--setvertcolor $ i (a * (wht - c) + c) -- this 'screens' the new values onto the initial vrtx value
d += 1
if mod d 20 == 0 then (progressUpdate (i*100/$.numverts)) -- don't want to update progressbar too often
progressEnd()
for k in 1 to clrstor_array.count do
(
append r_val clrstor_array[k].r
append g_val clrstor_array[k].g
append b_val clrstor_array[k].b
append rgb_val (amax r_val)
append rgb_val (amax g_val)
append rgb_val (amax b_val)
clrmax = amax rgb_val
if clrmax == 0 do clrmax = 255
mulval = 255/clrmax
for i in 1 to (getnumcpvverts $) do
(
if solonly.checked then (setvertcolor $ i (clrstor_array[i] * mulval))
else (setvertcolor $ i (orig_clr_array[i] * (wht - (clrstor_array[i]* mulval)) + (clrstor_array[i] * mulval)))
update $
)
catch
(
enablesceneredraw()
redrawviews()
und.enabled = true
enablesceneredraw()
end = timeStamp()
redrawviews()
Print ((end - start) / 1000.0)
)
on und pressed do -- this is the restore vertex colors button
(
disableSceneRedraw()
try
(
for i in 1 to (getnumcpvverts $) do
(
setVertColor $ i orig_clr_array[i]
update $
enablesceneredraw()
redrawviews()
doit.enabled = true
catch
(
enablesceneredraw()
redrawviews()
)
on trlncy open do -- some stuff that is probably a waste of time
(
try ( -- the following so existing stored data is not lost
if orig_clr_array[1] != undefined then
(
if orig_clr_array.count != $.numverts do (orig_clr_array = #()) -- if object selected does not match on open
-- this simply to see if the array exists with items
catch (orig_clr_array = #()) -- if not, then create as an empty array.
)
)
-- end
if trl != undefined then closerolloutfloater trl
trl = newRolloutFloater "Translucency" 205 452 1000 200
addRollout trlncy trl
效果圖。