Monday, January 11, 2010

Texture from shader

Credit for this idea goes to Alfred, who posted the following at blenderartists.org: http://blenderartists.org/forum/showthread.php?t=174790

Have you ever created an awesome shader in one program and tried to replicate it in another? Here's a cheap, easy method to quickly get the look of a shader in one software package into another, with cheap rendering times to boot. All you need, in your target software package, is a method to import an image as a texture, and the ability to use that texture as a spherical environment mapping. Alfred discusses how to do it in Blender -- here's how to do it in Maya. First, find a shader ball representation of the shader you like (if there are reflective or surface texture details, try to get as high res an image as possible). Pixologic offers many shader ball renders you can try out at its MatCap library: http://www.pixologic.com/zbrush/downloadcenter/library/

First find a shader ball you like, and take a screenshot of it. Crop the image so that the sides of the sphere just touch the edges of the sphere, and try to make sure the background color is similar to the color of the edge of the sphere. When cropping, err on the side of cropping too much rather than too little in order to avoid an edge on your shader ball image. In other words, it is better to cut off a little of the sphere on the top, bottom, and sides than to leave a border around the sphere.



Next, in Maya, go to the Hypershade and under the Env Textures, create an Env Ball node. In the envBall's attributes, map the Image attribute by clicking the checkerboard icon, and map it to a file texture (file1.outColor -> envBall1.image). Load the cropped image into the file texture. Finally, pipe the output of the envBall into the color channel of a Surface Shader (envBall1.outColor -> surfaceShader1.outColor). Your final Hypershade tree should look something like this.



For far away renders that don't require a lot of detail, this technique works pretty well with very little overhead for set up and render time.



Of course, you may need to have reflections and refractions in addition to what is provided by the environment sphere image. This is relatively easy to do. Create a blinn shader, and pipe the environment ball output into the blinn's color attribute (envBall1.outColor -> blinn1.color). Try to match the blinn's transparency and specular colors to the colors in the texture image. If the reflections in the image are fuzzy, make the specular highlight larger. If the glass texture is very dark, use more transparency, and if the texture is lighter in color, use less transparency. You will also need to increase the ambient color to account for the double shading (once from the texture image, and once from Maya's blinn). For this image I have a pale dark green transparecy at about 15% brightness. If using Maya software be sure to turn on raytracing. Pretty good for nearly no render overhead, and this technique can be used for any shader ball image you come across.

No comments:

Post a Comment