Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
My First Shader
Introduction
In this chapter we will compile and view a simple shader. In doing so, you will become familiar with the shader writing tools and processes, which we will apply to more complex examples in later chapters.
131
132
Essential RenderMan
The shader source code is simply text, and can be entered using any text editor, such as textedit (MacOSX), kate (Linux), or notepad (Windows). It should be saved in a text file with the name first.sl. The exact layout is not important, so you can add new lines, or spaces wherever you choose, but it is important to lay the code out so that it is as clear and readable as possible.
We will use the command shader (the PRMan shader compiler), but you should substitute for whatever is required by your renderer. When this program is run a new file is created which contains a version of the shader optimised for a particular renderer. You would therefore compile your new surface first for use by PRMan using the command shader first.sl to create the file first.slo. Each renderer uses a unique file extension for its compiled shaders, so you can compile a shader for several renderers and keep the results in the same folder. If a compiled shader is not generated, this usually means there is a mistake somewhere in your shader. This will happen, even when you are proficient at shader writing, as the compiler insists that the shader be exactly right before it can be used to create an image. In the event of an error the compiler will usually print a list of problems, along with the line number of the code which caused problems. Tackle the errors one at a time, starting with the first, as a problem on one line will often confuse the compiler, making it think there are far more problems than there arefixing the first error will often solve all of them. If you cannot see a problem on the line that the compiler is reporting an error on, check the line before, as sometimes the compiler does not notice a mistake until slightly later than it should.
My First Shader
133
134
Essential RenderMan
Starting with simple geometry allows you to understand the behavior of your shader better than a complex model would. The development process therefore becomes: edit myShader.sl shader myShader.sl render testMyShader.rib viewer testMyShader.tiff rinse and repeat . . . A typical shader development process might use a simple RIB file for the initial development. Once the basic look has been established a more complex RIB file can be used, perhaps containing the object for which the shader is being developed, so the appearance can be evaluated in situ. Only for final tweaking and production testing need the shader actually be loaded into the modeling package.
Summary
The shader development process is summarized in Figure 18.2.
Shader first.sl Go Back and Improve the shader RIB File first.rib
Renderer render
View Image