Showing posts with label environment. Show all posts
Showing posts with label environment. Show all posts

Friday, August 21, 2009

Fisheye lens distortion using MOSAIC and Aqsis

Greetings again Blender heads and RenderMan junkies :)

Well I've been hard at work with MOSAIC and recently needed a good test case for the volume shader I'm currently working on. It just so happened at that moment someone over at BlenderArtists inquired about lens distortion so I decided to do a test project and developer blog demonstrating lens distortion but also testing several area of MOSAIC. I've been asked to copy that blog to share with all the good people here also....


From the original developer blog here http://sourceforge.net/apps/wordpress/ribmosaic/

I've recently had someone at BlenderArtists ask whether MOSAIC could do lens distortions. Well since that's not a standard feature of Blender I have no built-in solution for this, however knowing this could be done I figured I'd tell him that RenderMan could do it easy and MOSAIC can set it up. As I was writing the reply I realized that I hadn't actually tried this myself and I'm currently needing an good project to test the new volume shader so... thus was born this fisheye project :) This post is not intended as a tutorial but just an overview of how I achieved this effect, I'll also include the blend if anyone wants to play with it.

Well the first thing I did of course is look around for examples of techniques, and as it so often turns out there's several different ways to do this. If looking for just mild image distortion/displacement then the simplest solution is to just use an image shader to process the image (the same as the post process filter in Blender's compositor). If looking for something more extreme such as the 360 degree fisheye effect then more radical steps are required. One approach is to use a warped plane in front of the camera and use raytracing with the surface normal refraction to fake the lens effect. Another technique, which I prefer, is to render the camera as a cube map in separate passes and then combine the maps into an empty beauty pass with an image shader. This approach can see distortions all the way around the camera, has fine tuned control over image quality and camera rotations and lens distortion and can even be animated with the same maps as long as camera translation doesn't change!

I found several example shaders but was surprised to find one written by my friend Chris Foster in the Aqsis example folder! I only made a few small changes to the shader for creative control:

  • I added a rather wide filter to the lens mask to blur its edge

  • I added the ability to flatten the distortion so the lensing effect can be pulled in and out of

  • I added the ability to rotate the forward vector in the cube lookup on x,y and z axises


The idea behind this technique is simple: use a cube map pass from the camera's position to generate cube faces, then in the beauty pass lookup into the cube faces with the image shader to project the warped perspective on the frame. The first step is to build a standard scene, I decided to use checker displacements on a ground plane and columns around the camera to emphasize the effect. I also decided to test faked soft shadows in a larger more complex space and also to include my partially rewritten volume shader to produce more daigonal light streaks for effect (the finished shader will be included in next CVS update). Next I added the fisheye image shader and created a shader fragment.

First off there's several tricks I had to play on the beauty pass:

  • Enable an empty scene layer. This is so nothing is rendererd except the image shader otherwise you'll waste time rendering object not seen.

  • Create and select a RIBset on the camera with the fisheye shader enabled. This is so the beauty uses the fisheye shader but we can force the default RIBset with no fisheye effect for other passes.


Next I created a User Autopass to use as the cube renders with a few filter options applied:

  • Blank the "Layers Scene:" filter. This is so we can specify what layers to use in this pass, otherwise it will use the beauty's empty layer.

  • Set "RIBset Bypass:" to DEFAULT. This makes sure the camera used from the beauty pass is not using the fisheye lens.


An autopass is necessary instead of just using a global env pass because better filtering can be achieved in Aqsis using textures then an env map. In this custom pass I made several custom scene RIBset's named as numbers from 0000 to 0005. Then I set this pass in the Project tab to use "RIBSETPASSES" so MOSAIC will export the numbered RIBset's as separate passes and ignore the DEFAULT RIBset. This is so I can use the same scene setup for each cube perspective. Then for each RIBset I used the "Show Autopass Settings" to setup the following:

  • For each RIBset I use one of each of the cube Camera: Perspectives (Object: nx, Object: px, Object: ny, Object: py, Object: nz, Object: pz). I use the Object instead of World perspectives so the cube faces are relative to the cameras orientation.

  • Setup each "file" display to point to ./Maps/ and use the name of each cube face, as "ny.tif", "py.tif" ect.

  • Setup the "Texture" dialog to convert each file display tif into mipmapped tex, as "ny.tif" - "ny.tex"ect. This is not strictly necessary but produces much better results with the image shader ;)


So at this point what's happening is the user autopass is exporting each RIBset using the active camera from the beauty scene with one of each cube face directions and optimizing them into one of 6 images. Now all that has to do done is pull up the fisheye shader in the shader editor and put in each of the images from the cube pass and adjust "thetaMax" to the distortion angle and render the beauty pass.

However since the cube faces can be reused in a simple rotational animation with minimal render time I decided to take things further and do a 20 second animation. Also since the cube faces are static I decided to try really high quality occlusion maps, shadow map with faked soft shadows, DOF and volume atmosphere shading. This is because the addition time needed to calculate these passes on the first frame are more then made up for by the really fast render times of the animation in the imager pass (it only has to grab the cube faces and calculate lookup direction and lensing). I also thought it would be interesting to synchronize settings across the pipeline from Blender to MOSAIC by adding animated composting effects and by using the same camera controls to drive multiple shader parameters in MOSAIC. In particular I'm animating the "lens" control on the camera and hooking that to the thetaMax shader control but also grabbing the same lens data and modifying it in a python token to control the lens distortion parameter and finally using the frame count in another python token to feed y axis rotation in the cube lookup. As a finishing touch I've animated a spectral lens distortion effect in Blender's compositor, this could fairly easily be done in the image shader but this gave me a chance to try sychronizing animation in Blender's compositor with RenderMan :) Anyway Here's the video, project file and a few frames of the animation from my gallery...

Here's the youTube video...


Here's a direct download of the mp4...
http://www.dreamscapearts.com/Public/fisheye.mp4

Here's a frame at 100 degree lens at 0 degrees rotation...


Here's a frame at 200 degree lens at 90 degrees rotation...


Here's a frame at 360 degree lens at 180 degrees rotation...


Here's a frame at 360 degree lens at 180 degrees rotation...


And if anybody want's to play with the blend here it is too.
NOTE: I embedded a modified version of MOSAIC that includes the Object:py-nz camera perspecitves that is not in CVS yet so you'll need to run MOSAIC from the text editor!!
http://www.dreamscapearts.com/Public/fisheye.blend

That's it, thanks for reading :)
Eric Back (WHiTeRaBBiT)

Saturday, July 12, 2008

MOSAIC feature ramblings - part 5

Part 5 - The Project Setup tab and render passes:


The "Project Setup" tab presents a series of controls for setting aspects of the current project. The term "project" is unique to MOSAIC since Blender has no project settings or internal datablocks (the lowest structures in Blender are scenes).

Since scenes are render passes to MOSAIC a project tab is necessary to have a global place for scenes to be managed as passes. This is also a convenient place to put settings global to all exported RIBs.

Before I begin outlining the controls for this tab I need to talk a little about render passes and RIBsets.

Render Passes:
We've learned from earlier posts that render passes are Blender scenes to MOSAIC. We've also hinted that these scenes can be managed by MOSAIC, so let's expound on that.

There are essentially 3 types of render passes to MOSAIC:

  • Generated map autopasses recognized by their names and extensions.

  • Generated user autopasses recognized by their extensions.

  • Manually linked scenes as passes (no special naming).

Generated map passes are automatically made by MOSAIC and are for things like shadow maps, occlusion maps, etc. They are created and edited by various controls in MOSAIC's interface and are named using the name of the object they are made for with an added special extension. So for example if you use the "Enable Shadow Mapping" dialog in the "Lights Setup" tab for a lamp called "mylamp", MOSAIC would generate a scene called "mylamp.sm" and add its entry to the render pass list.

MOSAIC recognizes five scene extensions for map autopasses:

  • ".sm" - shadow map scene

  • ".cm" - caustic map scene

  • ".om" - occlusion map scene

  • ".em" - environment map scene

  • ".wm" - world environment map scene

Generated user autopasses are created by a tool in the "MOSAIC Utilities" tab and allow the user to create a pass that's maintained by MOSAIC, but can be crafted for custom use (such as building an occlusion cache pass, etc). These passes are identified by MOSAIC because they have the ".ap" extension.

Manual passes are nothing but normal scenes linked to the render pass list and contain no filtering or automation. They are very flexible because MOSAIC does not mess with them (so anything is possible), but do not always update properly when the beauty scene is updated (such as adding objects to the beauty scene).

I've mentioned several times that autopasses are "maintained" by MOSAIC. By "maintained" I mean that the contents of these scenes are automatically updated according to filter settings before they are exported. This "filter" concept is the corner stone of autopasses. How this works is every scene can have a series of settings applied to them that tell MOSAIC how to filter the scene, these filters contain things like which scene this pass is to be updated from, which object will be the active camera, only link objects in certain groups, block all lights, block all objects, use a particular RIBset, etc. Before MOSAIC exports a scene it will look to see if it's an autopass (by its extension) and if so then filter its contents according to its filter settings before it's exported (unless you disable the "Export Render Passes" toggle in the actions tab). Both map and user autopasses use the same filter mechanism but map autopasses have several filter settings automatically filled in.

Even though this all sounds very complicated in practice all you really need to do for most projects is hit the button for the type of map you want (depending on where you are in MOSAIC) and it'll all be done for you ;)


RIBsets:
RIBsets are a simple mechanism to have multiple "sets" of RenderMan settings per MOSAIC tab (ergo "RIB" "set"). Scene, Camera, Geometry, Light, and Material tabs can all use RIBsets. RIBset controls are located at the top of each tab and have buttons for creating, deleting and selecting RIBsets. Any changes to any controls in the tab are applied to the current RIBset, all controls are updated by the selection of other RIBsets. All RIBsets have a "DEFAULT" selection that cannot be deleted, if a default RIBset is deleted all controls in it are reset to their default states. RIBsets have several purposes:

  • To allow the user to have multiple setups (such as multiple shader selections on one Blender material).

  • To allow multiple scenes with shared objects to use different settings (such as having shadow map passes with no surface shaders on shared materials).

  • To have potentially hundreds of settings in a single scene.

Occlusion


The last point is very important for occlusion mapping. Occlusion mapping involves having hundreds of spot lights in a hemisphere pointed at the center of the scene, each spot light needs to have its own render pass. Since we don't want hundreds of render passes entries we need a better way to do this. The best way to handle the setup for that many coordinated lights is by parenting a mesh to a light and using Blender's "DupliVert" feature thereby creating a light at every vertex of the mesh.

MOSAIC has a feature so that if a light is made an active camera and if that light is part of a dupli system then you can set the "Dupli Index" number in the "Scene Setup" tab to set which dupli light perspective to use for the camera. By itself this isn't very helpful but combined with RIBsets you can create hundreds of RIBsets for the "Scene Setup" tab for every index into the dupli system. Next if you set the render pass to use "RIBSETPASSES" then MOSAIC will export every RIBset (except DEFAULT) in the scene as a separate pass. Using this mechanism it's possible to create hundreds of passes in a single compact scene with just one render pass entry.

Again even though this sounds complicated all you have to do in reality is click "Enable Occlusion Mapping" in the "Scene Setup" tab and MOSAIC will build all of this for you ;)


Now let's outline the controls in this tab.

Project Folder:
This is the name of the folder to export the project into (this folder if created in the "Export Directory" set in "MOSAIC Settings"). Remember to change this for each project if you want multiple projects running (such as rendering one while you edit another).

Search Paths:
All options in this category allow you to control which paths are used in the RIBs, see your renderer's documentation for a more detailed description of searchpaths.

Note : If you blank a path it will reset to its default, if you type in "NONE" then it will not be exported.

Texture Export Options:
This utility allows you to set how a each texture is handled by MOSAIC. Their options are:

  • Completely ignore - Do not export or optimize this texture.

  • Export only - Simply export this texture, but do not optimize it.

  • Export and Optimize - Both export and optimize it for the renderer.

  • Export into Environment Map - Export map but optimize it as a lat/long env map.

Create Render Pass:
This button will generate a blank render pass. This control and everything below it are were render passes are managed in MOSAIC. When a render pass is added you will get a row of controls for managing that pass. Passes are exported and rendered from top down with the beauty pass normally being the last in the list. Render passes can be added manually or automatically created and ordered by autopass utilities throughout MOSAIC. When passes are automatically created they are stacked in this order:

  • occlusion map passes

  • shadow map passes

  • caustic map passes

  • environment map passes

  • world map passes

  • user autopasses

  • beauty passes

They are stacked in this order so that shadows are calculated before environments which are before final passes. Also note that MOSAIC can support multiple beauty passes. When a pass is created you will see a row of these controls for each pass:

  • "Use" - This lets you enable or disable the export of this pass.

  • "Select Scene" - This lets you select which Blender scene is used for this pass.

  • "Select RIBset" - This lets you select which RIBset to set for this scene for export. Use this to select a custom created scene setups or use RIBSETPASSESS to render every RIBset in scene as a separate pass (DEFAULT RIBset is ignored).

  • "Sta" - Set this to the starting animation frame for this pass (if 0 then uses scenes "Sta" control in Blender).

  • "End" - Set this to the ending animation frame for this pass (if 0 then uses scenes "End" control in Blender).

  • "Up/Dn" - Move this pass up or down the pass list to change its export and render order.

  • "Del" - Delete this pass entry (does not delete the scene however).


That's it for the project tab, next blog will be focused on the "Scene Setup" tab and will probably be broken into two blog posts (since it's such a large topic).

Thanks for reading, WHiTeRaBBiT