Looking for a high-level explanation of some shader constructs

I have a good programming degree, and I’ve worked with shaders before, but I haven’t worked with them in Unity (or worked on Unity at all before now for that matter). I’m making my way through tutorials, examples, and such, but I was wondering if I could get someone to help me with a high-level overview of some shader constructs in Unity.

The above link steps through different steps of setting of different shader features (such as texturing, bump mapping, rim lighting, and so on). It’s extremely useful, and I’m learning quite a bit about how to work with Unity’s shader system by stepping my way through this, but I need just a pointer or two on at least what constructs are called so I can read up about what exactly it is that they do.

For example, in the second sample listed on the above page (“Texture”), it creates a “Properties” block (or something, not sure what to call it) with the line _MainTex ("Texture", 2D) = "white" {}, creates a sampler2D object also called _MainTex, and samples it in the surf function. How do these _MainTexs work together? What do the strings do, look up some predefined data in Unity’s shader system to use? Where can I find a reference of what these strings and such are called and what they do?

Thanks in advance, any help is greatly appreciated.

The thing at the top is indeed called a properties block. Its purpose is to define properties that can be set from outside your shader, either in Unity’s material inspector, or through code (with methods like Material.SetTexture or SetFloat).

For each property you define in the properties block, you specify its name in the shader (“_MainTex”), the description it’ll have in the inspector (“Texture”), its type (“2D”), and its default value (“white” {}). See http://docs.unity3d.com/Documentation/Components/SL-Properties.html for the various types of properties available.

Each property you define in the properties block must also be declared inside the CGProgram. In CG, some of the data types are named differently from what they are called inside the properties block. The CG type for a 2D texture is “sampler2D”, so if you define a property called “_MainTex” of type “2D” in the properties block, you must also declare a variable “_MainTex” of type sampler2D in your CGProgram. Range and Float properties in the properties block map to float (or half, or fixed, depending on what precision you need) in CGPrograms, and Color properties map to float4 (or half4 or fixed4).