Write in front
Thanks to all the friends who came in to see. Yes, I'm currently going to write a book about unity shader.
The purpose of the book is to have the following several:
Summarize my experience with unity Shader and give others a reference. I am very aware of the difficulties of learning shader, and I have seen many questions raised by people in the group. I think learning shader is still a regular thing to follow, but the problem is Chinese information is difficult to find, and we do not want to see English ... What good is this for me? Forced me to comb the knowledge, to grasp the details of the problem more clearly.
A second reason you know.
Questions about the positioning of the book:
For unity Shader Beginners, but to:
- Have a certain programming experience, or I said: In the script to write a function xxx, you ask me, what is the script? I:.......
- I hope you remember the basic mathematics of junior High school. At least you can count the numbers clearly. I understand that many people have already given the matrix these slightly more complicated math to the college teachers, so I will introduce them in a separate chapter.
- I hope you have a certain degree of patience. Why do you always feel that you do not understand, learn not to shader, you can reflect on yourself is not too impatient, want to see today tomorrow will. Give it up, it's impossible.
One of my goals in writing this book is to help beginners build a foundation that is unreliable without any superstructure.
I'm not writing a special effects encyclopedia, so if you want to see all kinds of cool and awesome effects, I'm sorry, there's hardly anything in this book. This has a lot to do with one book, and I'm sure a beginner can't be a "shader". I hope that anyone who has read this book can really understand what shader is, and not say, "Oh, shader, that's the right thing in unity that Create->shader get." About the special effects of the problem, if I have full experience and qualifications in the future, may actually write a book, hahaha
Writing a book is a very difficult thing, I hope I can do it well.
Overall structure
I have divided this book into five chapters:
Basic article: This is a very important chapter, mainly for beginners to popularize basic theoretical knowledge, as well as the necessary mathematical basis. I understand that many people do not understand some of the material on the Internet, I try to speak as popular as possible.
Shader Elementary: Start with the simplest shader, and explain the basic lighting models, textures, and transparency effects in shader. At the same time, it will introduce some shader debug techniques, shader common error messages.
Shader Intermediate: This is the advanced chapter, will explain more complex lighting, high-level texture, and how to use shader to achieve a series of advanced content such as animation;
Shader Advanced: It covers some of the advanced uses of shader, such as the use of buffers, the implementation of screen effects, non-photorealistic rendering, and also introduces some optimization techniques;
Extension: Will cover some of the mechanisms behind Unity Surface shader, and will also briefly analyze some of the new features in the Unity 5.0+ release. Finally, I hope to introduce you to the experience and resources of learning shader.
Currently the catalogue has been initially finalized and the catalogue is recorded here, but I will keep updating it.
If you have any comments and suggestions on the contents and content of the book, you can leave a comment below. If you don't have a CSDN account, you can also send me an email to tell me: lelefeng1992 # gmail DOT com. I will make certain changes to the catalogue and content based on your comments.
Catalogue (updated to 11th chapter)
* Preface
* What does the book say?
* What you need to know before you read this book
* Who is suitable to read this book
* Who is not fit to read this book for the time being
* Convention
* Reader Feedback
* Source of the book
The 1th part of the basic article
1th Chapter Welcome to the world of shader
- 1.1 Programmer's Three great romance: why learn Shader
- 1.2 This is not a programmer's fight.
- 1.3 The world is so big
2nd Chapter Rendering Line
- 2.1 Reviews
- 2.1.1 What is an assembly line
- 2.1.2 What is a rendering pipeline
- 2.2 CPU and GPU communication
- 2.2.1 Loading data into video memory
- 2.2.2 Setting Rendering status
- 2.2.3 Calling Draw Call
- 2.3 GPU Pipelining
- 2.3.1 Overview
- 2.3.2 Vertex Shader
- 2.3.3 Cropping
- 2.3.4 Screen Mapping
- 2.3.5 Triangle Settings
- 2.3.6 Triangle Traversal
- 2.3.7 Chip Shader
- 2.3.8 per-slice operation
- 2.3.9 Summary
- 2.4 Some places that are easy to confuse
- 2.4.1 What is Opengl/directx
- 2.4.2 What is HLSL, GLSL, CG
- 2.4.3 What is draw call
- 2.4.4 what is a fixed rendering pipeline (Fixed-function Pipeline)
- 2.5 So, do you understand what a shader is?
- Extended Reading
3rd Unity Shader Foundation
- 3.1 Unity Shader Overview
- 3.1.1 Pair of good brothers: material (Material) and Unity Shader
- 3.1.2 The material in unity
- 3.1.3 Unity in the shader
- 3.2 Unity Shader Foundation: Shaderlab
- 3.3 Unity Shader's structure
- 3.3.1 gave our Shader a name: Shader.
- 3.3.2 Material and Unity Shader Bridge: Properties
- 3.3.3 Heavyweight member: Subshader
- 3.3.4 left a way: Fallback
- 3.3.5 Shaderlab Do you have any other semantics?
- 3.4 Unity Shader Form
- 3.4.1 Unity's darling: Surface Shader
- 3.4.2 's Smartest kid: Vertex/fragment Shader
- 3.4.3 abandoned corner: Fixed Function Shader
- 3.4.4 So, what kind of unity shader form to choose
- 3.5 Book using the Unity shader form
- 3.6 FAQ
- 3.6.1 Unity Shader! = Real Shader
- 3.6.2 the relationship between Unity shader and CG/HLSL
- 3.6.3 can I use GLSL to write?
- Extended Reading
4th. The mathematical basis required for learning shader
- 4.1 Background: Farm games
- 4.2 Cartesian coordinate system
- 4.2.12-d Cartesian coordinate system
- 4.2.23-d Cartesian coordinate system
- 4.2.3 left-hand coordinate system and right-hand coordinate
- 4.2.4 Unity uses the coordinate system
- 4.2.5 Exercises
- 4.3 Points and vectors
- 4.3. The difference between 1 points and vectors
- 4.3.2 Vector Operations
- 4.3.2.1 vector and scalar multiplication/division
- Addition and subtraction of 4.3.2.2 vectors
- The modulus of 4.3.2.3 vector
- 4.3.2.4 Unit vector
- dot Product of 4.3.2.5 vectors
- Cross product of 4.3.2.6 vectors
- 4.3.3 Exercises
- 4.4 Matrix
- Definition of the 4.4.1 matrix
- 4.4.2 and vectors linked together
- 4.4.3 Matrix Operations
- Multiplication of 4.4.3.1 matrices and scalars
- Multiplication of 4.4.3.2 matrices and matrices
- 4.4.4 Special matrices
- 4.4.4.1 block Matrix
- 4.4.4.2 Unit Matrix
- 4.4.4.3 Transpose Matrix
- 4.4.4.4 Inverse matrix
- 4.4.4.5 orthogonal matrix
- 4.4.5 row matrix or column matrix
- 4.4.6 Exercises
- 4.5 Geometric meanings of matrices: transformations
- 4.5.1 Homogeneous coordinates
- 4.5.2 Decomposition Base transformation matrix
- 4.5.3 translation Matrix
- 4.5.4 Scaling Matrix
- 4.5.5 rotation matrix
- 4.5.6 Combination Transformation
- 4.5.7 Exercises
- 4.6 Coordinate space
- 4.6.1 Why use so many different coordinate spaces
- Transformation of 4.6.2 coordinate space
- The coordinate space transformation process of 4.6.3 vertex
- 4.6.4 model Space
- 4.6.5 World Space
- 4.6.6 observation Space
- 4.6.7 clipping Space
- 4.6.7.1 Perspective projection
- 4.6.7.2 orthogonal projection
- 4.6.7.3 case
- 4.6.8 Screen Space
- 4.6.9 Summary
- 4.7 Normal Transformations
- 4.8 Built-in variables in Unity shader (Math article)
- 4.9 FAQ
- 4.9.1 using a 3 x 3 or 4 x 4 transformation matrix
- Vector and matrix types in 4.9.2 CG
- 4.9.3 screen coordinates in unity: Computescreenpos/vpos/wpos
- Answers to the exercises
- Extended Reading
2nd part of the Junior chapter
The 5th chapter begins unity Shader Learning Journey
- 5.1 The software and environment used in the book
- 5.2 One of the simplest vertex/fragment Shader
- 5.2.1 vertex/fragment Shader Basic Structure
- 5.2.2 where the model data comes from
- 5.2.3 How to communicate between vertex shader and slice shader
- 5.2.4 How to use properties
- 5.3 Powerful Helping hand: Uni The built-in files and variables provided by Ty
- 5.3.1 built-in include files
- 5.3.2 built-in variables
- 5.4 Unity provides CG/HLSL semantics
- 5.4.1 What is semantics
- 5.4.2 Unity-supported semantics
- 5.4.3 How to define a complex variable type
- 5.5 Programmer's annoyance: Deeeeebug
- 5.5.1 using false color images
- 5.5.2 using artifact: Visual Studio
- 5.6 Caution: Differences in render platform
- 5.6.1 coordinate differences for rendered textures
- 5.6.2 shader Syntax differences
- 5.6.3 Shader Semantic differences
- 5.6. 4 other platform Differences
- 5.7 shader neat Way
- 5.7.1 float, half or fixed
- 5.7.2 canonical Syntax
li>5.7.3 Avoid unnecessary calculations
- 5.7.4 caution with branching and looping statements
- 5.7.5 do not divide by 0
- extended Read
-
6th basic Lighting in Unity
- 6.1 How we see the World
- 6.1.1 light source
- 6.1.2 absorption and scattering
6.1.3 coloring
- 6.1.4 BRDF illumination model
- 6.2 standard illumination Model
- 6.2.1 Ambient light
- 6.2 .2 Self-illumination
- 6.2.3 Diffuse reflection
- 6.2.4 Specular reflection
- 6.2.5 pixel-by-node or per-vertex
- 6.2.6 Summary
- 6.3 ambient light and spontaneous light
- 6.4 Diffuse Light model
- 6.4.1 Practice: Per-vertex illumination
- 6.4.2 Practice: per pixel illumination
- 6.4.3 Improvement tips: Semi-lambert model
- 6.5 Specular light model
- 6.5.1 Practice: Per-vertex illumination
- 6.5.2 Practice: per pixel illumination
- 6.5.3 Blinn-phong modulo Type
- 6.6 Summon the Dragon: Use unity built-in functions
- 6.6.1 using built-in functions to rewrite unity Shader
-
7th basic Texture
- 7.1 Single-sheet texture
- 7.1.1 Practice
- 7.1.2 explanation
- 7.1.3 Texture Properties
- 7.2 Bump map
- 7.2.1 Height texture
- 7.2.2 Normal texture
- 7.2.3 Practice
- 7 .2.4 Interpreting the normal texture type in
- 7.2.5 Unity
- 7.3 Gradient Texture
- 7.3.1 Practice
- 7.3. 2 explanation
- 7.4 Matte texture
- 7.4.1 Practice
- 7.4.2 Explanation
- 7.4.3 other matte textures
8th Chapter Transparency Effect
- 8.1 Why rendering order is important
- 8.2 Unity Shader Render Order
- 8.3 Transparency Testing
- 8.3.1 Practice
- 8.3.2 Explanation
- 8.4 Transparency Blending
- 8.4.1 Practice
- 8.4.2 Explanation
- 8.5 Turning on the translucent effect of deep writes
- 8.5.1 Practice
- 8.5.2 explanation
- 8.6 Shaderlab's Hybrid command
- 8.6.1 Mixed equations and parameters
- 8.6.2 Blending Operations
- 8.6.3 Common types of blends
The 3rd part of the intermediate chapter
Part 4th Shader Advanced Chapter
The 11th chapter is the rendering method based on image processing
- 11.1 Gamma correction
- 11.2 Anti-aliasing
- 11.3 Brightness, saturation, and contrast
- 11.4 Implementing Photoshop-like blending modes
- 11.5 Implementing the gradient overlay effect
- 11.6 to achieve a vignette effect
12th. Using depth and normal buffers
- 12.1 How to get buffers
- 12.2 Practice: Depth of field effect
- 12.3 Practice: Edge Detection
13th Non-photorealistic rendering
- 13.1 Cartoon Rendering
- 13.2 Contour Rendering
- 13.3 hand-painted style rendering
14th. Using noise in shader
- 14.1 What is Noise (Noise)
- 14.2 Perlin Noise
- 14.3 Worley Noise
- 14.4 Practice
The 15th chapter of mobile Platform optimization
- 15.1 The difference between a mobile platform and a desktop
- 15.2 identify factors that affect performance
- 15.2.1 CPU
- Treatment of 15.2.2 Vertex
- Treatment of 15.2.3 Fragment
- 15.2.4 Bandwidth
- 15.2.5 Unity's performance analysis tool: Profiler
- 15.3 Optimizing geometry
- 15.4 using LOD Technology
- 15.5 Using occlusion culling technology
- 15.6 Controlling Drawing Order
- 15.7 always alert for transparent objects
- 15.8 reduce real-time illumination
- 15.8.1 using Lightmaps
- 15.8.2 using God Rays
- 15.9 Reduced Draw Calls
- 15.9.1 Static Batch Processing
- 15.9.2 Dynamic Batch Processing
- 15.9.3 How to choose
- 15.10 Reducing texture size
- 15.11 Using Zoom
The 5th part of the extended chapter
16th Chapter Surface Shader Quest
- 16.1 Basic assembly line
- 16.2 Unity behind what was done
The 17th chapter is based on physical rendering--physically Based Shading
- 17.1 theory
- 17.2 Unity's Standard Shader
18th. What did Unity 5.0 update
- 18.1 scenes "brighter"
- 18.2 Surface shader Easier "error"
- 18.3 ownership: Control of non-uniform scale grid
- 18.4 Fixed function gradually exits the stage
Is there anything more in the 19th chapter?
- 19.1 If you want to learn more about shader,
- 19.2 or that sentence: the world is so big
Reference documents
- Index
2015.06.28 Update
These days in the part of the math, I have long expected that mathematics is the most difficult to say, especially the matrix. I like a lot of people, the matrix this guy is simply "disgust", see it just want to escape. Helpless, shader inside to often deal with it, then, bravely face it!
I understand why we are so "annoying" matrices. If we can visualize the vector as a visual way to understand, then, the matrix, which is placed in a small box of things, it is difficult to paint the way to draw it out. And our brains are very lazy (well, I can only speak for my brain), no picture you say a xxx! I don't bother remembering!
In fact, I have always had a kind of awe-inspiring attitude towards mathematics. There are many mathematicians in the world who are also philosophers, psychologists, and feel that mathematics is very important to understand the world, and the life of those mathematicians is very interesting and admirable. It is great for those who can contribute their life to mathematics, how great are those who create matrices, spaces and vectors, and how do they think of describing this phenomenon in such a way? It's a really amazing thing. And, you will find, how this can be expressed in this sense, obviously there is no relationship between it! This coincidence really makes people sigh the greatness of mathematics.
Well, no longer crooked ... Back to the real world ... In the process of writing, I will try to use the popular, humorous, graphic way to talk about this chapter, how the effect, I am also very disturbed, will not reflect that can not understand? Now it's unclear ...
One interesting thing is that I made a model of my own hand when I was talking about the coordinate system and the handedness of the left and right hands:
Ha, this yellow hand is really my hand, and then I processed it with Photoshop. Looks like it's going to work? Who dares to say my hand fat I with who urgent!
These days have been drawing, reading, writing, writing formula (God, although it is very convenient to write formulas with markdown, but one day to write so many formulas are really ...). ), computation, hope the final result is good. Come on!
2015.07.10 Update
After writing for two weeks, the draft of the mathematics chapter was basically finished. Today, the 2nd, 3, 4 chapters of the catalogue, interested can look at, welcome to make various comments and suggestions.
Math is the most I want to write a good (of course, other chapters I will also write well ...) )。 Mathematics is difficult to learn, part of it is because of its abstraction, no way, if we want to take some of the rules from life, it is necessary to involve a variety of mathematical symbols, it is necessary to use the abstract. I used a lot of graphs and cases to try to make the process more readable and to explain some common doubts by using some sort of conversational approach.
At present, the first article of the book-Basic form. Each chapter in the basic article has a section called answer questions, intended to summarize some common doubts, if the reader in addition to the points I wrote above there are other puzzles, you can give me a message. I will add this to this section as appropriate.
In addition, in the Math chapter I added the part of the exercises. In fact, I have hesitated, I think maybe everyone will jump over, it is not written in vain ... The reason is to set the part of this exercise, on the one hand really hope that the reader can really take a written calculation through these exercises, really, math you do not really do not know how to learn forever. On the other hand, we want to put forward some confusing points through the practice exercises, so that the readers can calculate their own understanding. Because if you want to write these confusing points in the book, the idea will be more chaotic. Hope to play a better effect it ...
The following will really start the unity shader part. Come on!
2015.07.29 Update
Spend most of the holiday to take a look at information, study, write a book. More than half a month to write the basic text of the draft, do not know whether it is fast or slow? I am confident that I write very detailed, for example, the 5th chapter introduces the semantics, the 6th chapter introduces the basic illumination model in detail, the 7th chapter writes to the bump mapping time also spends the very big space to introduce the realization principle and the detail, including the height diagram, the 8th Chapter transparency effect first introduced the rendering queue, I thought this very important, You should let the reader know how important the rendering queue is to transparency before learning how to achieve transparency. I think the current arrangement for beginners is friendly enough, of course, when writing the following content may also be in the previous content changes, for example, now want to add a in the 4th math in Unity Script matrix operation, but this book is shader, do not know add in not fit, But it is an error-prone place.
Every time I talk about the new content, I try to use the illustration to explain, each picture is in the OmniGraffle earnestly, hoped that the person who sees later can get to my meaning. Writing too much writing blog is incoherent ...
QQ Group recently, private messages and messages often have some problems, I am here to answer a unified. answer a few questions :
When will the book be published?
Everyone also saw my update speed, currently written in the 8th chapter (the first chapter is not written), the preliminary set is 19 chapters, that is to say One-third, I now spend about one months, but the book did spend a lot of time, after writing the basic article may slow down a bit of speed. Overall, I estimate that it will take about three or four months to finish writing, so the publication of the words the fastest end, or early next year. Some people say it's too late, believe me, I want it to be published faster than anyone else, but I'm not a shadow. Good envy Naruto.
Can you add some more difficult techniques?
Some children's shoes look at the first few chapters of the catalogue and feel that the content is relatively simple. How to say, this book is oriented to beginners, so it will certainly be from easy to difficult, but I am confident that even the simple content I wrote very detailed, a lot of small points are written, many places are other information in the area, but also very confusing point. If you have not learned shader, even now can be proficient in writing some I think this book is also useful.
More importantly, I do not want to write it into an encyclopedia, one of my own experience is not enough, I do not write to the Daquan, and secondly I think a book of books must be written not fine, write not thin, in the end, and said do not understand how to do? Three come I think write shader is a teacher lead the door to practice rely on personal life, once you understand its work flow and basic ideas, the rest is the accumulation of experience, you read, write much natural on the bad, this is not a basic book can let you do.
Of course, I do write some complicated techniques, and this is the work of high-level articles and extensions. If you think there are some common and complicated techniques that you want to see in this book, you can tell me.
Is it a color book or a black and white book?
I certainly hope that it is a color book, a book about the effect of the picture is black and white that is too regrettable. But the editor told me that color printing would raise a lot of costs and that sales would go down. I can understand, but there is no final verdict, and I will try to fight for it when I finish writing. But I am also very curious, you think such a hundreds of-page full-color book, how much do you think the price is more appropriate?
2015.09.04 Update
I finished the draft of the intermediate article on and off. The more you write the feeling content of the more laborious arrangement, some content does not know to put them into which chapter more suitable, put early some content not to worry about the reader can not understand, put the late and feel content is insufficient alone Cheng Zhang. The high-level article presumably will do the same. The catalogue is still under constant adjustment ...
Write the 9th Chapter light is in addition to the most painful chapter of mathematics, want to speak clearly very difficult ah, anyway, the current content I tried, hope can have a good effect. Because of the content and miscellaneous, so this chapter unknowingly wrote 40,000 words, is currently the most words of the chapter. Even so, some of the content is still "obsessed", such as modafinil lighting, edge lighting, etc., do not know whether to join in the future.
In other words, when writing a book found a good free texture site--http://opengameart.org/, when writing a book some textures are found here, also recommended to everyone here. Of course, there are some textures of their own painting. Before the game did a 2D water surface, this time to add its implementation to the book.
Two more drafts of the whole are complete. Some of the content want to steal a little lazy, use dot Blog wrote ... September is expected to catch up on the paper, the progress will be slower. Expected to be completed in November or December, I hope you can wait patiently. I'm going to refuel.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"My book" Unity Shader's book-Catalogue (2015.09.04 Update)