Quick Clay Render

40 votes
Version: 
1.1
Date Updated: 
11/13/2009

Clay Render

 

One click will render your scene as a 'clay' style image, leaving the scene, materials and all your render settings exactly as they are. Code has been updated to create the floor plane at the lowest vertex in the scene, and to make it easier to customise (different renderers, alter the material colour, environment background and light type).

Additional Info: 

When modelling, I often find myself using quick 'clay' renders to get an idea of what my models look like when lit, as it really brings out the edging and detail. But this involved saving my scene, creating a ground plane, positioning it, assigning a clay material to everything, creating the light, rendering it, then reloading the scene because I'd lost all my materials. So I figured I'd give creating a script a go.

It's not perfect, as it's the first proper script I've made, but it does the job. It will find the lowest vertex in the scene, create the ground plane beneath that, sort out the lights and materials, set the renderer to the DSR, do the render, then cleans up after itself (deletes the created nodes, restores all materials, puts the renderer back to whatever you were using).

Only downside - The actual render speed of using skylights isnt great, but that can't be helped, I just love how they look :)

And yes, this has just been written in the past hour because I got fed up of going through the process I described above. Any suggestions on how to improve it are welcome, but go easy on me, I haven't done this before!

Figure I may as well just post the code, it isn't that long:

macroScript ClayRender category: "LiamDavis"
(
-- Variables to change basic settings
rendererToUse = Default_Scanline_Renderer()
clayColour = [255,255,255]
renderBackground = [255,255,255]

clay = standardMaterial diffuse:clayColour shaderType:1
sun = Skylight castShadows: true enabled: true

in coordsys world
min_v = 99999999999
mat_array = #()
m = 1

-- define the clay material

-- Finds the lowest vertex in the scene
for obj in objects do
(
if superclassof obj == geometryClass then
(
-- Take a snapshot of the current objects mesh
checkMesh = snapshotAsMesh obj
-- Find out how many verticies it has for the coming 'for' loop and test each verticies z position to find the lowest
num_verts = checkMesh.numverts
for v=1 to num_verts do
(
vert = getVert checkMesh v
if min_v > vert.z then
(
min_v = vert.z
)
)
delete checkMesh
)
)

-- Create the floorplane at the lowest point
floorplane = plane lengthsegs:1 widthsegs:1 length:10000 width:10000 pos:[0,0,min_v]

-- Store objects current material in an array then assign the Clay material
for obj in objects do
(
append mat_array obj.material
obj.material = clay
)

-- makes sure it renders using the DSR, but leaves it as whatever the user had it as
backgroundSetBackTo = backgroundColor
backgroundColor = renderBackground
rendererSetBackTo = renderers.current
renderers.current = rendererToUse
max quick render -- render the current viewport
renderers.current = rendererSetBackTo
backgroundColor = backgroundSetBackTo

-- delete the added nodes or repeated use would multiply them
delete floorplane
delete sun

-- restore original materials to scene objects
for obj in objects do
(
obj.material = mat_array[m]
m = m+1
)
)

Video URL: 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sebastian___'s picture

I believe the LightTracer

I believe the LightTracer (also included with max) has an identical or similar look and it's much faster. And it's meant to be used with the skylight - you don't have to change a thing - it only accelerates a lot.
I did some speed compare with Vray and it was faster for this kind of clay render with small details

EDIT : Shocking I know. I think nobody knows about how fast is LighTracer for this. here is the compare

LT 12 seconds - http://img813.imageshack.us/img813/3976/lt12sec.png
MR 29 sec and lower quality http://img219.imageshack.us/img219/6316/mr29sec.png

animated gif :

Patrick Probst's picture

Bug

Hey,

First of all: Very nice script :)

I found a "bug" (?): When the active View is a Camera then "checkMesh.numverts" goes "undefined" and no rendering is possible

Wakx's picture

Идея конечно хорошая. Но

Идея конечно хорошая.
Но он ЧУДОВИЩЬНО долго рендерит.
Гораздо быстрее переключиться в Ментал Рэй и настроить эмбиент окклужен (с заменой материалов в сцене (оверайд мат.)). Либо почти все тоже самое провернуть с Вирейм.

aaa's picture

Please help-have i not pasted

Please help-have i not pasted the right amount and then did run script? from what start of the code to end do i use? -not really great at this...right now theres errors whatever i do

aaa's picture

i pasted the full macroScript

i pasted the full

macroScript ClayRender category: "LiamDavis"
(
-- Variables to change basic settings
rendererToUse = Default_Scanline_Renderer()
clayColour = [255,255,255]
renderBackground = [255,255,255]
clay = standardMaterial diffuse:clayColour shaderType:1
sun = Skylight castShadows: true enabled: true
in coordsys world
min_v = 99999999999
mat_array = #()
m = 1
-- define the clay material
-- Finds the lowest vertex in the scene
for obj in objects do
(
if superclassof obj == geometryClass then
(
-- Take a snapshot of the current objects mesh
checkMesh = snapshotAsMesh obj
-- Find out how many verticies it has for the coming 'for' loop and test each verticies z position to find the lowest
num_verts = checkMesh.numverts
for v=1 to num_verts do
(
vert = getVert checkMesh v
if min_v > vert.z then
(
min_v = vert.z
)
)
delete checkMesh
)
)
-- Create the floorplane at the lowest point
floorplane = plane lengthsegs:1 widthsegs:1 length:10000 width:10000 pos:[0,0,min_v]
-- Store objects current material in an array then assign the Clay material
for obj in objects do
(
append mat_array obj.material
obj.material = clay
)
-- makes sure it renders using the DSR, but leaves it as whatever the user had it as
backgroundSetBackTo = backgroundColor
backgroundColor = renderBackground
rendererSetBackTo = renderers.current
renderers.current = rendererToUse
max quick render -- render the current viewport
renderers.current = rendererSetBackTo
backgroundColor = backgroundSetBackTo
-- delete the added nodes or repeated use would multiply them
delete floorplane
delete sun
-- restore original materials to scene objects
for obj in objects do
(
obj.material = mat_array[m]
m = m+1
)
)

in the new maxscript,went to run script and get an error
-SYntax error:at?,expected(
-In LIne: macroscript ClayRender category:
whats wrong?im using 2010

stuuse's picture

I changed the script to use

I changed the script to use the Mental Ray Renderer and it sped up the rendering process 10X, very quick now. How can you change the intensity of the skylight in the script?..oh and I used the concise Anubis version. Thanks to you both.

bderrick's picture

what about having the render

what about having the render overwrite the diffuse map slot but not the opacity, bump etc. I think it would be nice to have the rending look like clay while still showing some texture. Is it possible?

Liam.Davis's picture

When you execute the script

When you execute the script (either the one I posted, or better the refined version posted by Anubis) it adds the macro to your max but doesnt run it. If you go into cutomise -> customise user interface and find it (my one would be under the category 'LiamDavis', but you could change that to make it easy to find) and put it somewhere - I have it in the rendering dropdown menu along with a few other render presets and quick renderer swap buttons, but you can chuck it anywhere - quad menu, toolbar.

Then just select it from whereever you have it and it'll run. The lighting setup is really slow ro render though, so be warned - but it does make everything look bloody great!

ThatMikeGuy's picture

How do I run this script? I

How do I run this script? I tried copy/pasting and saving as an .ms file. Then I tried to Run Script from inside Max but nothing happened. What am I missing?

Thx

Anubis's picture

Hi Liam, about '$' sign, yes

Hi Liam, about '$' sign, yes its a short for selection.
And to exclude the hidden objects:

geo = for g in geometry where not g.isHidden collect g
sha = for s in shapes where not s.isHidden collect s

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.