Self-study Unity3d also has a big six months, to shader has been afraid into the pit, recently read some information, and through their own practice, to shader still have a little understanding, share under only for reference.
Since shader is a rendering of image images, it is possible to understand the knowledge of graphics and GPU programming before learning. The spring snow lowbrow of GPU programming and CG language is highly recommended, and the book is electronically available online.
There is also a book on the development of unity shaders and screen effects for Unity3d's shader, which was translated by Unity Shaders and effects Cookbook.
First look at the effect of the shader implementation:
1. Create a new sphere sphere, and then build a material ball material in project.
2. Assign the new material ball to the materials of the mesh renderer component of the Sphere object
Choose different shader, and adjust the parameters, you can see different effects.
3. Create a new shader in project, and a shader will be written by default when opened.
Shader"Custom/testshader"{//Shader "keyword start" "Custom/testshader" "Shader name, divided well used to group"Properties {//It contains attributes that are assigned in Unity_maintex ("Base (RGB)", 2D) =" White"{}//_maintex The property name "Base (RGB)" Property description, the "2D" property Type "White" "Default" will appear in the Unity panel_alpha ("Transparency", Range (0,1))=0} subshader {//child shader, can write multiple to adapt to different hardware or platformTags {"Rendertype"="Opaque"}//shader Tags "The hardware will decide when to call the shader by determining these tags"Lod $//Level of DetailCgprogram//CG Language started//affirm that the program uses surface shader processing for the following surf, using the Lambert illumination model #pragmaSurface Surf Lambertsampler2d _maintex;//variables of type sampler2d, names consistent with names in attributes, used to receive unity-passed argumentshalf _alpha; structInput {//struct, for entering dataFLOAT2 Uv_maintex;//uv_ the Uvs used to fetch the incoming map }; voidSurf (Input in, InOut surfaceoutput o) {//method of surface shaderHalf4 C = tex2d (_maintex, In.uv_maintex);//tex2d method to sample a point in a mapO.albedo = C.rgb;//assigning an RGB color to an outputO.alpha = C.A;//Transparency Assignment} ENDCG//end of CG language} FallBack"Diffuse"//rolling back}
Related information:
Candycat's Blog: http://blog.csdn.net/candycat1992/article/category/1782159
Introduction to Unity3d Shader shader programming (i)