Basic knowledge necessary before writing shader

Shader Vertex (vertex shader): After realize the operation of vertices programmatically, such as space conversion, color, texture coordinates, the vertex data to obtain the final light output to the fragment shader

Vertex shader may be used to specify a range of completely generic (e.g., coordinates, lighting, color, texture), and the operation applied on relevant data and the respective vertex.

Shader Fragment (fragment shader): before the pixel is not displayed on the screen, to perform a series of operations that may be modified or even discarded fragments. All these operations can be enabled or disabled. A texture processing operation may be performed first. Generating texture memory for each fragment a texture unit (Texel, i.e. texels, i.e. UV), and applied to this piece. Then possible to calculate the fog, and then cut test, alpha test, stencil test and depth test buffer (depth buffer for hidden surface elimination). If a piece can not be enabled by a test, it's a continuous process may be interrupted. Then, to be performed may be mixed, jitter, logical operations, and a masking operation according to a bit mask. Finally, after complete treatment fragment was drawn to the appropriate buffer, eventually becoming a pixel and reaches its final habitat.

 

Coordinate of the object gripping change: the local coordinates (origin itself for its own axial direction) -> inertial coordinate - (axial direction thereof is coincident with the origin of the world coordinate system) -> world coordinates (world coordinates coincides with the origin of the local shaft is then rotated to) -> camera coordinate (I personally prefer to call the camera coordinate, also known as the written statement of the view frustum coordinates, in fact, is the view of the camera is a four-sided pyramid or cuboid) -> dimensionality reduction operation on the three-dimensional coordinates in the camera view in ( https://www.bilibili.com/video/av37614073?from=search&seid=2402871598313506313    1:09 to find out) ->

Next on the introduction of the three tests under Shader:

Depth test:

  Depth: refers to the distance of the pixel from the camera. The farther away from the camera, the greater the depth.

    Depth buffer: stores a depth value corresponding to each pixel.

       Color buffer: storing the color values ​​corresponding to each pixel.

       Test Depth: a depth with the pixel depth buffer are compared. If it passes the depth test, you have the opportunity to rewrite the corresponding value of the depth buffer; otherwise the pixel will be discarded

  

  

   Zwrite

      Parameters On / Off On / Off depth write

   ZText 

   Greater  GEqual  Equal Less LEqual  NotEqual  Always  Never         

            Respectively

     >> = = = <<=! = Always Never

   GBuffer pixel comparison of the pixels, replacement condition is satisfied. Otherwise reject, object rendering pixels to the screen is not directly need to be calculated, in line with the conditions the test is passed, eventually to the screen.

Alpha test:

  Alpha Test, Chinese is the transparency test. Briefly this point is the color value V & F shader function of the output of the last fragment (i.e., the output of a speaking half4 frag) of the alpha value is compared with a fixed value. AlphaTest statements are in the starting position of Pass {}.

  grammar:
  The first: AlphaTest Off: no test, rendering the whole
  The second: Alpha alpha target value comparison operators
  Wherein the target is an alpha value ranging from 0 to 1, the parameters can also be used, such as AlphaTest [varName].
 
  Comparison operators: (hereinafter referred to as target value alpha x)
  Always full rendering (x arbitrary value)
  Never does not render the whole
  Greater alpha value greater than the point of rendering x
  GEuqal point alpha value greater than rendered equal to x
  Less alpha value less than the point x rendering
  LEqual    点的alpha值小于等于x时渲染
  Equal  点的alpha值等于x时渲染
  NotEqual  点的alpha值不等于x时渲染
 
  例:
  AlphaTest never  0      全不渲染(这个0可以是任意值,但必须填)
  AlphaTest always 0      全渲染(这个0可以是任意值,但必须填)
  AlphaTest off               全渲染
  AlphaTest Greater 0.4  当alpha大于0.4渲染,   缺点是边缘过于锋利并且显示不完整,alpha小于0.4的部分被忽略掉了
  Alpha Blend                 边缘柔和,但是中心也太柔和,没有实体的感觉
  AlphaTest Greater 0.4 / AlphaTest LEqual 0.4 两个部分,大于0.4不混合,小于0.4混合。效果是既有实体感觉,边缘也柔和。

 

模板测试:

  模版测试较为复杂,它不像Alpha测试一样,单单通过简单的大于小于等运算符来比较,但是和Alpha测试一样,都是测试像素点,符合要求的就渲染,不符合要求的就不渲染。了解模版测试,需要理解较多术语:

  1.GBuffer:几何缓冲,相当于一个容器

  2.RefenceValue:模版值,Guffer中的像素点就是与这个值按位与后进行比较

  3.stencilOperation:比较后进行的操作

  4.ReadMask|WriteMask:读遮罩|写遮罩

  理解了以上的术语,那么模版测试的公式就差不多可以理解了:其公式为:

  referenceValue&readMask comparisonFunction stencilBufferValue&readMask

 

转:https://blog.csdn.net/coolbeliever/article/details/81979089

 

Guess you like

Origin www.cnblogs.com/chenggg/p/11204708.html