The standard shader based on physical coloring (PBS) is introduced in Unity5 . Since this shader can realistically simulate a variety of hard surfaces by adjusting parameters and decals, it is no longer necessary to write shaders individually for a variety of textured materials, as in the Unity4 era, and to get better results. This "universal shader" seems to give a person no longer need to write their own shader illusion, but do games and do virtual reality is not the same, in addition to authenticity, but also the pursuit of fun and artistic exaggeration. So the old saying goes: No game with a custom shader, not a good game.
But it is very difficult to implement PBS yourself, if we want to inherit the PBS features of standard shader and add their own custom effects, it is best that our custom shader can be written on the basis of standard shader, That is to implement a custom PBS shader (custom PBS shader).
Because it is new, incomplete information, Google has not been able to find a way out of the box all day, the unity Official document does not explain it (in the surface shader custom lighting model part only gave no PBS example), Unity Forum has a number of posts to ask similar questions, But there are no satisfactory answers. Finally, a little clue was found in the following two connections:
http://forum.unity3d.com/threads/for-those-in-u5-beta-is-pbr-really-that-good.283867/page-3#post-1886525
http://blogs.unity3d.com/2014/10/29/physically-based-shading-in-unity-5-a-primer/(under the article MIG's question)
This clue is: "
From the release notes for Beta 12:
- Shaders:surface Shaders can use physically based shading now; The same as standard shader uses.
- Use the "standard" lighting function, and "surfaceoutputstandard" output structure.
- Do a #include "unitypbslighting.cginc" in your shader to get it.
- Default options require shader Model 3.0, so add a "#pragma target 3.0" too.
”
Then combined with the source code in the Unitypbslighting.cginc (note 1), of course, just copy some code from the Unitypbslighting.cginc (rather than modify it), finally the custom PBS shader test succeeded.
Note 1:unitypbslighting.cginc where is this file? There are three ways to get:
(1), wrote in http://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html: "File Inside Unity ({Unity Install path}/ Data/cgincludes/on Windows, /applications/unity/unity.app/contents/cgincludes/on Mac) ", it's important to note that"/applications/ Unity/unity.app/contents/cgincludes/"This path is in Unity.app's" package content ", So that's why on Mac even though Unitypbslighting.cginc has been installed with unity, it can't be found by file search.
(2) Download the "Make your Own" page via URL http://docs.unity3d.com/Manual/StandardShaderMakeYourOwn.html into the online builtin_ The latest version of shaders (also includes the historical version). Because my unity is up-to-date, the latest version of Builtin_shaders downloaded through this approach is consistent with the approach (1), but if your unity is not up-to-date, be sure to download the corresponding version of Builtin_shaders based on your Unity version number , or you can copy the code in a custom shader that may cause an error.
(3), enter file:///Applications/Unity/Unity.app/Contents/Documentation/en/Manual/in the browser address bar Standardshadermakeyourown.html go to the offline "Make Your Own" page (from the address you can see this page is actually saved in your computer), download builtin_shaders, but be aware that The builtin_shaders may not be up-to-date through this offline document download, and I'm going to be in this hole today In this way downloaded the code in the Unitypbslighting.cginc file to the custom shader error, did not find the reason for half a day, until I again through the way (1) regain unitypbslighting.cginc ...
In a comprehensive way (1) is the best.
The first ball is standard shader, the second ball is a custom shader with "normals as color Values" (without PBS), and the third ball is today's test result: Added "treat normals as color values" on the PBS basis of standard shader Effect of the hybridization shader.
Unity5, make a custom PBS shader