Game Development Reference
In-Depth Information
Appendix D
Shaders and Cg/HLSL
Programming
This appendix presents a brief overview of the structure of surface shaders and Cg/HLSL
programming.
Shaders in Unity can be writen in one of the following three diferent ways:
F Surface shaders will probably be your best bet. Write your shader as a surface shader
if it needs to interact properly with lighing, shadows, projectors, and so on. Surface
shaders also make it easy to write complex shaders in a compact way—it's a higher
level of abstracion. Lighing for most surface shaders can be calculated in a deferred
manner (except for some custom lighing models), which allows your shader to
eiciently interact with many real-ime lights. You write surface shaders in a couple of
lines of Cg/HLSL and a lot more code gets autogenerated from that.
F Vertex and fragment shaders will be required, if you need some very exoic efects
that the surface shaders can't handle, if your shader doesn't need to interact with
lighing, or if it's an image efect. Shader programs writen this way are the most
lexible way to create the efect you need (even surface shaders are automaically
converted to a bunch of vertex and fragment shaders), but that comes at a price—
you have to write more code and it's harder to make it interact with lighing. These
shaders are writen in Cg/HLSL as well.
F Fixed funcion shaders need to be writen for old hardware that doesn't support
programmable shaders. You will probably want to write ixed funcion shaders as an
nth fallback to your fancy fragment or surface shaders, to make sure your game sill
renders something sensible when run on old hardware or simpler mobile plaforms.
Fixed funcion shaders are enirely writen in a language called ShaderLab, which is
similar to Microsoft's .FX files or NVIDIA's CgFX.
Search WWH ::




Custom Search