Bokeh in 3dsmax with particle flow and maxscript
As the new year every-CG-artist-nightmare began, here is simple holiday hint.
Let’s steel some bokeh pictures from internet, or take a photo of some bright defocused lights.
Cut them with a circle masks in AE or PS and make an equal images sequence (i did 10 pictures).
Setup the multi/sub object material in 3ds max for 10 ID’s, with additive transparency.
Put the white-to-black gradient ramp texture to the opacity slot using the second UV channel.
Put the bokeh images sequence into the diffuse slots using the first UV channel.
Let’s make the particle flow system based on some interesting complex geometry, e.g. some twisted helix splines.
Set proper number of the vertices in the Birth operator, and also set location: selected in the Position Object operator.
Use Mesh select over all splines to convert splines to mesh vertices.
Add Material Dynamic operator with prepared multi/sub object material to the PFlow event.
Let the Shape Facing operator, oriented to the Target Camera define particles shape.
And now the main part of the tutorial – add the Script operator with the following script:
on ChannelsUsed pCont do
pCont.useTime = true
pCont.useScale = true
pCont.usePosition = true
pCont.useMapping = true
on Init pCont do
on Proceed pCont do
count = pCont.NumParticles()
tarpos = $Camera01.Target.position
campos = $Camera01.position
for i in 1 to count do
pCont.particleIndex = i
pCont.setParticleMapping i 2 [abs((distance campos tarpos)-(distance campos pCont.particlePosition))/500,0,0]
— all the particles get the UV coordinates at 2-nd UV channel here.
— UV coords depends on the distance to camera’s focus “sphere”.
pCont.particleScale = abs((distance campos tarpos)-(distance pCont.particlePosition campos))/5
— here is the dependence of the particle’s scale defined
— “focused” particles are small, as they moving away from the focus – they are becoming bigger.
on Release pCont do
This script will define particle’s scale and transparency depends on camera’s focus.
Now you can animate the geometry or the camera and render the particles with scanline.
Don’t forget to cache all the particles for viewport/render using the Cache operator.
This setup renders pretty fast as opposed to mental ray’s or vray’s honest dof.
And we have fast bokeh effect with the ability to inceract with scene geometry.
P.S. While i worked with the script there were a couple of obstructions, which took several hours to break.
And after finding the proper solution, i found that exactly same solutions were already described at the second disc of CG Academy Particle Flow Scripting.
So if this theme is interesting for someone – i advice to look through. My respect to Bobo!
That is all.
Filed under: Uncategorized | 13 Comments