下面是使用方法和步骤:
一、创建几何体、光源。如图。
点击放大
二、选择几何体,为其指定一个纯白色材质(一定不要有颜色)。如图。
点击放大
三、选择几何体,在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
效果图。