Shadows on a ShaderMaterial?

I have had a look at ShadowOnlyMaterial and at SimpleMaterial. It seems as if the shaders there are assembled via a number of #include statements. I’m totally new to this and I’d like to understand what is being assembled there and what the end product (the whole shader source) looks like.

Is there any kind of documentation on this? Or else, can you point me to the places in the source tree from where the shader snippets are included? Then I could try to understand what happens and write a proper shadow-enabled and light-source-enabled shader for my terrain.

Thanks a lot, @sebavan