Bokeh in 3dsmax with particle flow and maxscript

15Dec09

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.

Here is the scene

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.

About these ads


10 Responses to “Bokeh in 3dsmax with particle flow and maxscript”

  1. nice result!

  2. 2 John Rand

    Haha pretty neat trick :)

  3. 3 ABD

    شكرا لكم

  4. 5 Anton

    Thanks a lot for the script, Vitsly. It works great!

  5. very nice tutorial.
    Thanks.

  6. 7 Anonymous

    brilliant! thanks a lot for this tutorial. really beautiful cg! just a hint: i swapped the camera distance cooridnates with a falloff map dependent on cameras z-axis distance. (with the curve of the map shaped like a bell…) dunnow why, but it renders much faster, and to me, the result looks the same.

  7. I do not know whether it’s just me or if everybody else encountering issues with your blog. It appears as if some of the text within your posts are running off the screen. Can someone else please comment and let me know if this is happening to them as well? This might be a issue with my internet browser because I’ve had this happen previously.
    Kudos

  8. 9 Aman Duggal

    my render is not as it is supposed to be… images are showing with white background. tried both tga and png images….. help!!!

  9. 10 rezoloot

    Almost killed me creating the material for this, I love it though, took me a complete day to work out the material but I got it, was going to download your file and just add the maps but what would that achieve, thanks for this tut


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: