
This ambient occlusion term can now be used to replace theĪmbient part in a regular shader. Is no direction in the hemisphere above the surface point that is blockedīy other geometry, whereas the darker a point is, the more directions areīlocked. The white parts are not occluded at all, i.e. What you see here is only the ambient occlusion contribution without anyĪdditional shading.
Renderman tutorial code#
So you can enclose your code by an #ifdef or #ifndef: This variable will only be defined during baking,

Rendering you can use the BAKE_PASS variable to find out in which In the shader that only work either during baking or during normal This also means, you can simply turnĪny shader into a “bake shader” by adding Pref as argument andĮnclosing everything by the above macros. When the render tool is not in bake mode, theīAKE_BEGIN and BAKE_END macros will simply be substituted byĪn empty string and the BAKE_NORMAL() macro expands to the usualįaceforward(normalize(N),I). Shader computes the color for the texture map using P and the obtainedĪ shader that is prepared using the BAKE_ macros can also be usedįor normal rendering. You should make sure you saved the normals with your model and that theįormat you’re using actually stores the normals. There is another macroīAKE_NORMAL() which should be used for obtaining the correct normal.įor this to work correctly, the model must supply normal information! So The shader can actually use P just as usual. At theīeginning, the global variable P will be replaced by Pref, so The entire shader code should be enclosed by the BAKE_BEGIN andīAKE_END macros which will be provided by the render tool. Somewhere in uv space and that’s why we have to carry the original 3D P On the surface of our model where shading should take place (remember, we areĪctually rendering a flat texture map, so our regular P is bascially This variable carries the actual 3D point * Bake Ambient Occlusion */ surface bake_ao ( float samples = 128 varying point Pref = point ( 0, 0, 0 )) Įvery shader used for baking must take a parameter called Pref which Our shaderīake_ao.sl, which is simply baking an ambient occlusion map, looks Used for baking has to be made aware of this. Shader determines what you are actually baking. Now the model receives a special RenderMan shader as material. In our case, it’s simply called “Model”). Model is obtained (to do so, you have to know the name of your model. You may need a separate set of texture coordinates for baking.Īfter the Globals block the model is loaded and a reference to the Uses the standard st variable for looking up the texture. Variable if you want to bake a textured model and your shader already Holds the texture coordinates for use with baking. The next parameter isīakevarst which contains the name of the primitive variable that Specifying this parameter is not necessary. As we only have one single mesh in our scene, It can either be the name of an object or The bakemodel parameter allows to specify the model that There are two more options specific to baking that we did not use (which is the default for baking anyway, in contrast to normal rendering). The output image will be called ao_map.tifĪnd will contain an alpha channel as the display mode is set to "rgba" We don’t want OpenGL having to scale the image. Power of two resolution as we want to be able to use the map in OpenGL and

The resolution of the map is set to 512x512. The option -B or -bake to the render tool.Īll remaining options are usual rendering options that are not particular In the Globals section we first activate texture baking by setting # Bake a texture map Globals ( bake = True, resolution = ( 512, 512 ), pixelsamples = ( 2, 2 ), output = "ao_map.tif", displaymode = "rgba" ) # Load the model load ( "model.obj" ) # Obtain a reference to the model model = worldObject ( "Model" ) # Set the bake material mat = RMMaterial ( surface = RMShader ( "bake_ao.sl", samples = 1000 ) ) model. Here, I saved the model in the Wavefront Object format. The following uv layout for the above model: Instead of manually assigning the texture coordinates youĬan also let your modeling package do the job. “leaking” through to another face where it doesn’t belong to. You should also make sure that there’s a little spaceĪround each texture area to prevent the color from one texture area Wouldn’t later be possible to assign a separate color for each surface point That the final uv layout has no overlapping parts, otherwise it You can either assign the texture coordinates manually to haveįull control about the uv layout. We’re using the model in the following image (which doesn’t representĪnything particular, it’s just an object with a few concavities to showĪs we want to apply the baked texture map later on we need textureĬoordinates for the baked map. The first step is to create the model in your favorite modeling package.Ĭurrently, only polygonal models can be used for baking.
