Friday, May 16, 2008

generating framebuffers with ctrl buffer and maya 2008

Generating framebuffers in earlier versions of maya (below mentalray 3.3.51 ) was very tricky ..
However it has been made a bit easy to generate framebuffers in maya 20008

(also see previous notes to generate frame buffers using simple shader if you want quick results)

before we move ahead i would like to thank Maximilian Tarpini (ctrl.studio) for this wonderful shader...

Now how to generate framebuffers using ctrl buffers ??

First of all download and install ctrl buffers from http://www.box.net/shared/i6hd2271qk

Then we need to define the frame buffers in maya 2008

first step

First you have to create the frambuffers statements for the mr options. This can be done in the mentalray globals. Open the framebuffer section and click on the “Open Editor” button in the “User Framebuffer section”. This opens the attributeEditor for the miDefaultOptions node. Here under “Frame Buffers” you can add an framebuffer with the “Create” button (see right side).

passes_maya2008_fb_01_sm.jpg

In the appearing node, you can set the data type. For 8bit images the default is okay. The “interpolate samples” will add filtering to the samples, this means the little + sign mentioned above.

Okay very fine, you now have defined an framebuffer. If you open again the editor, you will see an new entry in the framebuffer list.

passes_maya2008_fb_02_sm.jpg

Great, the first step is done. Now we need a possibility to output the buffer to an image file. This has to be done in the camera. Select the camera an open its attribute editor. Go to the mentalray section, open it an do the same with primary output passes. Automatically the secondary output passes appears. Use the “Create” button to create a new ouptut element. Here you can turn on “Use user buffer”. In the popup menu below the checkbox, you should be able to select your previous created framebuffer. Do it. Then turn on “File mode”. Below you can enter an extension to your default file name. The file will be named like all other images, but with your new extension. e.g. sceneName_extension.001.sgi

passes_maya2008_fb_03_sm.jpg

Cool! Isnt it? So now you can render framebuffers. Of course you will only see black images. Why of course? Well, you have defined the buffers, but you didnt fill them yet. How can that be done?

While you create it always remember that the first buffer is reserved by maya for its glow shader..
so for example

you have to define 4 frame buffers say diffuse,shadow, occlusion,specular..
so while defining framebuffers in mi options and in the camera define 5 buffers so the first one automatically goes to the glow shader...
also remember to make them non renderable in the output pass option in the camera..

Now to set up ur buffer write and buffer store ... for this there is a very good example on cgtalk i'll just copy paste it here to save time ....

second step

In this eample whatever is bold is something that is added in the new shader...
again thanks kmrsic for this wonderful tutorial...
To view the images right click and click on view to see the whole image..

First off you crate your geometry and a light. In my case poly plane, poly sphere and spotlight with depth map shadow with 720 for resolution and some softnes.




real nice : )
Now, after you installd your Buffer store mental shader you can find it under Mental Ray nodes (shaders) > Material Tab and select that nice colord buffer_store icon and drag it to your work area. This is like a combiner for your passes that will be output in render time.




You can see how it looks so far in the hypershade and atribute editor. Now for this thing to actualy work or better say output anything when you press render you need anoher node connected and its name is buffer_write. You need to drag and drop hem in you render camera mental ray tab Output shader. Heres an image.




There you can see all the "free" passes you can get without using bufer store as Alpha, Normal, Depth,....so its renderd as is.



Here you need to set to important things: where to store your frame buffers and what file format to use AND how many buffers to render. So, make sure that number matches the number of your frameBuffer passes. I set it to tif in my case and buffer range to 1 as Im only using one pass.

In the latest version the buffer range is for min to max if you are generating 4 buffers set the min to 1 and max to 4...

One more thing in the latest version of ctrlbuffer is .names...
you can name ur individual frame buffers here ..
if userfb.1 is named to shadow then the rendered image will be named as ***.shadow.###.iff

In this example its shadowpass.

Now on to setting up the whats the render pass. In this scenario Im only going to do shadow pass as this one seems to confuse many. The idea can be done in to simple steps.
First you create Use Background Shader and set it up to only catch shadow by pullin all the sliders to 0. heres an image




So, this one catches all the shadows and now I connect its OutMatteOpacity to OutColor of the new Surface shader that you need to create. This way you get Shadow that is stored as alpha to transfer to rgb image (in composite its luminance is your alpha).

And drag and drop that Surface shader node to your Buffer_store buffer1 texture tab and be sure to enable store.



In the image above you can see I got to shader chains so to explain the upper one its basicly dirt shader connected to surface shader Out Color and Im using it as a shader in the primary buffer (the one thats render on the screen). You can use it or not but someone mentiond that its a good idea to put something so you can set your sampling buy it need number. Basicaly when you press render in your render view thats the image its going to be renderd on screen and used for sampling. Now with shadow maps its actualy better to put them in primary buffer but then again its up to you to do some testing and see if its fine.

Assign your Buffer store shader to all the objects wanted in that pass.





Set your render globals. Use at leas 1 as min samples for shadow pass as it wont look good below one. And thats the number 1 drawback for using shdowpass in your framebuffer and not in you primary render buffer. Sampling! Takes to much. But Then again you need it for all the rest of the passes you make. So its render and figure type of situation.



PRESS RENDER ! ; )))

And go in to the folder you set your framebuffer write.




So There it is. I hope it helps little bit and I was not to confusiong. Forgive me for all typos and spelling mistakes as Im doing this on the fly while my boss is not looking : )))

Happy rendering.

more on ctrl buffers visit
http://forums.cgsociety.org/showthread.php?f=87&t=209991&page=9&pp=15

Saturday, May 3, 2008

Puppet Shader for generating frame buffers

One of the easiest shaders available for generating frame buffers in maya is through commonly known as Puppet shader

for more details like tutorials and downloads please visit this link
http://www.puppet.tfdv.com/download/shaders_p_e.shtml
(If the above link does not work try copy pasting it in the browser window)

Frame buffers in maya 2008

Passes in mentalray 3.6 maya 2008

In mentalray there is a different definition for passes. They use it to define several parts of a very large scene to split it up into different layers, here “passes”. I’ll use the normal definition that means a special shader attribute or channel, e.g. a reflection pass, an diffuse pass etc. So how are passes defined in mr?

First you have to define an framebuffer in the options.

There is always a primary buffer and all buffers you define are additional framebuffers. Framebuffer will contain the samples, not pixels. They are converted into pixels before calling an output shader.

options "opt"
object space
contrast .1 .1 .1 1
samples -1 2
frame buffer 0 "+rgba"
frame buffer 1 "+rgba"
end options

This enables mentalray to allocate memory for the buffer and sets the type of the buffer, the plus sign means the buffer samples will be interpolated. That is not useful e.g. for a z depth buffer.

Next mentalray needs to know what it has to do with the framebuffer after rendering. All after-render-operations are calculated in an output shader. So you will define something like this:

camera "cam"
output "fb0" "tif" "somefilename.tif"
output "fb1" "tif" "someotherfilename.tif"
output "rgba" "tif" "primaryBuffer.tif"
...
end camera

Now mr knows to save the buffer as an rgba image in tif format. “output rgba” represents the primary buffer that is calculated always. The important thing are the “fb0” or “fb1”. With these shortcuts you identify the buffers allocated in the options sections “frame buffer 0...”.

Fine, now we have the allocated buffers and we know what to do with it. But they are still empty. How can we fill them. For this the shaders itself are responsible. There exist no default spec pass variable or diffuse or something like that. In the shader there has to be an statement like this one:

miColor color;

do something with the color

mi_fb_put(state, 0, &color);

This means that for this sample the color should be saved in buffer 0. This is the reason why this does not work with the maya shaders because the shaders dont contain these mi_fb_put() statements.

Fortunatly there exist some mentalray shaders out there in the www that enable you to save shader outputs into differnt buffers. e.g the puppet shaders from Pavel Ledin. He also offers the source code of his shaders. e.g. in his p_MegaTK he offers the possiblity to save several passes like the diffuse one or specular one into the buffers. Another great one is ctrl_buffers from ctrl studions, you can find them on cgtalk. great, are there any problems?

Yes, indeed. There are a few problems. Most of them are now solved with the release of maya2008 or 3dsmax2008.

  • sampling: before mentalray version 3.6 all buffers were sampled with the sampling of the primary buffer. So what? Where is the problem? For example, if you want to render a low contrast primary buffer and add contrast and detail with the occlusion pass, you may run into that problem.

passes_lowcontrast.jpgpasses_occlusion.jpg

Yes, I now these examples are really unrealistic and extreme. But they illustrate what I mean. The left one ist the low contrast primary buffer and the other one is the occlusion pass that is sampled with the same sampling like the first one 0/2. Because there is no contrast everything is calculated with sampling 0 even the occlusion pass. If you have a look at the occlusion rendering you will see aliasing artefacts at the diagonal edge of the occlusion area.

Of course you can fix it if you combine your buffers into the primary buffers and write you lowcontrast image as a seperate buffer. But it can lead to serious problems. Fortunatly mentalimages heard the complaints and implemented a new option in 3.6: “contrast all buffers” that enables a different sampling on all buffers.

  • buffer system: before maya2008, it was quite complicated to get the correct output. The main problem was that you could define additional output buffers, but there was no easy way to let the camera know which buffer should be written correctly.

This is exact the reason why all buffer shaders need an geometry shader.

What????

To use buffers correctly with maya releases before maya2008 you had to take care that the connection between the ouput options “frame buffer 0 rgba” and the camera output option “output fb0 ....” was correct. The simples way to do that is to create an geometry shader. An geometry shader is executed in the pre render phase and can manipulate almost everything in the mr scene database. An geometry shader can automatically create the frame buffer statements and the output statements to the camera. With maya2008 you are finally able to connect the output statement directly to your created frame buffer so that there is no geometry shader needed any more. solutions: use maya2008

Here is how a simple passes can be used in maya2008:

First you have to create the frambuffers statements for the mr options. This can be done in the mentalray globals. Open the framebuffer section and click on the “Open Editor” button in the “User Framebuffer section”. This opens the attributeEditor for the miDefaultOptions node. Here under “Frame Buffers” you can add an framebuffer with the “Create” button (see right side).

passes_maya2008_fb_01_sm.jpg

In the appearing node, you can set the data type. For 8bit images the default is okay. The “interpolate samples” will add filtering to the samples, this means the little + sign mentioned above.

Okay very fine, you now have defined an framebuffer. If you open again the editor, you will see an new entry in the framebuffer list.

passes_maya2008_fb_02_sm.jpg

Great, the first step is done. Now we need a possibility to output the buffer to an image file. This has to be done in the camera. Select the camera an open its attribute editor. Go to the mentalray section, open it an do the same with primary output passes. Automatically the secondary output passes appears. Use the “Create” button to create a new ouptut element. Here you can turn on “Use user buffer”. In the popup menu below the checkbox, you should be able to select your previous created framebuffer. Do it. Then turn on “File mode”. Below you can enter an extension to your default file name. The file will be named like all other images, but with your new extension. e.g. sceneName_extension.001.sgi

passes_maya2008_fb_03_sm.jpg

Cool! Isnt it? So now you can render framebuffers. Of course you will only see black images. Why of course? Well, you have defined the buffers, but you didnt fill them yet. How can that be done? You can do it with any shader that is able to fill buffers. You could use the ctrl_buffers, or p_MegaTK shader. They will simply write your infos to a buffer. Or you can use this one: simplePasses. The archive contains the mi file as well as the shader dll compiled for win32 and win64(I couldnt test the 64bit shader yet but I hope it works). But I have added the source code, so if you want you can use it to enhance it as you like it.

It is an extemly simple shader that puts your input into the framebuffers. The first input will be used as primary buffer.

passes_maya2008_fb_sp.jpg

The first shader will be written into the first buffer, the second into the second one etc... be careful not to use more shaders than previously created buffers.

And you should avoid buffer 0. It is used as glow channel by maya itself. That means every color written to the buffer 0, the first one in the simplePasses shader, will create a glow effect. You can avoid it by disabling the glow calculation in the mr globals.

The shader is compiled for mr 3.6 and will not work with any maya version below maya2008 because none of them is able to export color arrays correctly.

Source:- http://www.wiki.render3d.de/doku.php?id=renderwiki:techniques:passes:mr