How do you use a shader file once written?

Hello, I need to write custom post-processing shaders for Unity. I’m looking to do this using vertex and fragment shaders in CG and applying the effect over a camera’s view. Once I’ve written a shader file, how do I actually put it to use? Most components in Unity you can simply drag and drop where ever you’d like, but I can’t seem to do anything with shader files.

While looking for an answer, I’ve noticed in some of the imageEffects scripts that Unity has built-in that they use a shader on a material, but I’m looking to apply the shader to a camera’s view, not on an object’s material. Many of Unity’s built-in shaders don’t have a matching script, so they must be getting applied in some other manner but I haven’t figured out how. The only thing I’ve been able to find in the documentation is applying the shader to an object’s material. I’m sure there’s something simple that I’m just not seeing. Does anyone have any experience with shaders in Unity that could help me out? Thank you.

Unity nomenclature is slightly different from that you may have used in other places:

  • A Unity “shader” is assigned to a material which, in turn is applied to one or more meshes in the scene, and determine only how those meshes are rendered. So a metallic surface might use a material with a specular shader, for example, while the hair or a character might use a material with an anisotropic shader.

  • Shaders which alter the way in which a camera renders an entire scene are called “Image Effects” (essentially they are full-screen pixel shaders). Examples might be blur, depth-of-field, or bloom, for example. They too are assigned to a material, but that material is not used in the scene - it is typically used in the Graphics.Blit method of a script that implements OnRenderImage, to intercept and change the image rendered by the camera.

For a worked example of creating an Image Effect, try Postprocessing and image effects in Unity - Shader Tutorial